From 1a8c3d9f3efe7257825b0c76bed7ef9a0c80d3a8 Mon Sep 17 00:00:00 2001 From: getzze Date: Thu, 19 Nov 2020 22:33:07 +0000 Subject: [PATCH] improve coverage --- .../parser-julia.r/julia_test.d/expected.tags | 7 +- Units/parser-julia.r/julia_test.d/input.jl | 4 +- parsers/julia.c | 114 ++++++------------ 3 files changed, 43 insertions(+), 82 deletions(-) diff --git a/Units/parser-julia.r/julia_test.d/expected.tags b/Units/parser-julia.r/julia_test.d/expected.tags index 4d3cb00854..6e2acbf2c5 100644 --- a/Units/parser-julia.r/julia_test.d/expected.tags +++ b/Units/parser-julia.r/julia_test.d/expected.tags @@ -1,7 +1,11 @@ +!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/ +!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/ +!_TAG_OUTPUT_MODE u-ctags /u-ctags or e-ctags/ ATest input.jl /^abstract type ATest end$/;" t Base.ifelse input.jl /^function Base.ifelse(a::Int)$/;" f +Makie input.jl /^using Plots, Makie$/;" x Normal input.jl /^import Distributions: Normal$/;" x -Plots input.jl /^using Plots$/;" x +Plots input.jl /^using Plots, Makie$/;" x Random.randn input.jl /^using Random.randn$/;" x Revise input.jl /^using Revise$/;" x STest input.jl /^mutable struct STest <: ATest; a::Int end$/;" s @@ -17,4 +21,5 @@ eq input.jl /^eq(c=4; b=(1,2,3), c=:a=>5) = a == b$/;" f lone_function input.jl /^function lone_function end$/;" f run_test input.jl /^function run_test(a::T) where T<:Int; a::Int end$/;" f test_fun input.jl /^function test_fun(a::Int, b::T) where #$/;" f +test_macro input.jl /^macro test_macro() end$/;" m α input.jl /^ α::Real$/;" g struct:Test1 diff --git a/Units/parser-julia.r/julia_test.d/input.jl b/Units/parser-julia.r/julia_test.d/input.jl index 0fdd2c46fa..9bd714caa9 100644 --- a/Units/parser-julia.r/julia_test.d/input.jl +++ b/Units/parser-julia.r/julia_test.d/input.jl @@ -2,11 +2,13 @@ using Revise import Distributions: Normal using Random.randn -using Plots +using Plots, Makie const a::Int = 'c' # struct Struct_wrong3 end +macro test_macro() end + """ test_fun(a::Int) For test only diff --git a/parsers/julia.c b/parsers/julia.c index 4e375dd0c4..a964fd0d40 100644 --- a/parsers/julia.c +++ b/parsers/julia.c @@ -338,69 +338,84 @@ static void scanIdentifier (lexerState *lexer, bool clear) } while(lexer->cur_c != EOF && isIdentifierCharacter(lexer->cur_c)); } -/* Double-quoted strings, we only care about the \" escape. These - * last past the end of the line, so be careful not to store too much - * of them (see MAX_STRING_LENGTH). */ -static void scanString (lexerState *lexer) +/* Scan a quote-like expression. + * Allow for triple-character variand and interpolation with `$`. + * These last past the end of the line, so be careful + * not to store too much of them (see MAX_STRING_LENGTH). */ +static void scanStringOrCommand (lexerState *lexer, int c) { - //vStringClear(lexer->token_str); bool istriple = false; - /* Pass the first doublequote */ + /* Pass the first "quote"-character */ advanceAndStoreChar(lexer); - /* Check for triple doublequotes */ - if (lexer->cur_c == '"' && lexer->next_c == '"') + /* Check for triple "quote"-character */ + if (lexer->cur_c == c && lexer->next_c == c) { istriple = true; advanceAndStoreChar(lexer); advanceAndStoreChar(lexer); - /* Cancel up to 2 doublequotes after opening the triple */ - if (lexer->cur_c == '"') + /* Cancel up to 2 "quote"-characters after opening the triple */ + if (lexer->cur_c == c) { advanceAndStoreChar(lexer); - if (lexer->cur_c == '"') + if (lexer->cur_c == c) { advanceAndStoreChar(lexer); } } } - while (lexer->cur_c != EOF && lexer->cur_c != '"') + while (lexer->cur_c != EOF && lexer->cur_c != c) { - /* Check for interpolation before checking for end of string */ + /* Check for interpolation before checking for end of "quote" */ if (lexer->cur_c == '$' && lexer->next_c == '(') { advanceAndStoreChar(lexer); scanParenBlock(lexer); /* continue to avoid advance character again. Correct bug - * with doublequote just after closing parenthesis */ + * with "quote"-character just after closing parenthesis */ continue; } if (lexer->cur_c == '\\' && - (lexer->next_c == '"' || lexer->next_c == '\\')) + (lexer->next_c == c || lexer->next_c == '\\')) { advanceAndStoreChar(lexer); } advanceAndStoreChar(lexer); - /* Cancel up to 2 doublequotes if triple string */ - if (istriple && lexer->cur_c == '"') + /* Cancel up to 2 "quote"-characters if triple string */ + if (istriple && lexer->cur_c == c) { advanceAndStoreChar(lexer); - if (lexer->cur_c == '"') + if (lexer->cur_c == c) { advanceAndStoreChar(lexer); } } } - /* Pass the last doublequote */ + /* Pass the last "quote"-character */ advanceAndStoreChar(lexer); } +/* Scan commands surrounded by backticks, + * possibly triple backticks */ +static void scanCommand (lexerState *lexer) +{ + scanStringOrCommand(lexer, '`'); +} + +/* Double-quoted strings, + * possibly triple doublequotes */ +static void scanString (lexerState *lexer) +{ + scanStringOrCommand(lexer, '"'); +} + + /* This deals with character literals: 'n', '\n', '\uFFFF'; * and matrix transpose: A'. * We'll use this approximate regexp for the literals: @@ -449,67 +464,6 @@ static bool scanCharacterOrTranspose (lexerState *lexer) return true; } -/* Scan commands surrounded by backticks, - * possibly triple backticks */ -static void scanCommand (lexerState *lexer) -{ - /* assume the first character is a backtick */ - bool istriple = false; - - /* Pass the first backtick */ - advanceAndStoreChar(lexer); - - /* Check for triple backtick */ - if (lexer->cur_c == '`' && lexer->next_c == '`') - { - istriple = true; - advanceAndStoreChar(lexer); - advanceAndStoreChar(lexer); - - /* Cancel up to 2 backtick after opening the triple */ - if (lexer->cur_c == '`') - { - advanceAndStoreChar(lexer); - if (lexer->cur_c == '`') - { - advanceAndStoreChar(lexer); - } - } - } - - while (lexer->cur_c != EOF && lexer->cur_c != '`') - { - /* Check for interpolation before checking for end of string */ - if (lexer->cur_c == '$' && lexer->next_c == '(') - { - advanceAndStoreChar(lexer); - scanParenBlock(lexer); - /* continue, in order to avoid advancing another character. - * Correct problem with backtick just after closing parenthesis */ - continue; - } - - if (lexer->cur_c == '\\' && - (lexer->next_c == '`' || lexer->next_c == '\\')) - { - advanceAndStoreChar(lexer); - } - advanceAndStoreChar(lexer); - - /* Cancel up to 2 backticks if triple */ - if (istriple && lexer->cur_c == '`') - { - advanceAndStoreChar(lexer); - if (lexer->cur_c == '`') - { - advanceAndStoreChar(lexer); - } - } - } - /* Pass the last backtick */ - advanceAndStoreChar(lexer); -} - /* Parse a block with opening and closing character */ static void scanBlock (lexerState *lexer, int open, int close, bool convert_newline) {