Skip to content

Commit

Permalink
improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
getzze authored and masatake committed Nov 23, 2020
1 parent 873505f commit 41d9d1f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 82 deletions.
7 changes: 6 additions & 1 deletion Units/parser-julia.r/julia_test.d/expected.tags
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
4 changes: 3 additions & 1 deletion Units/parser-julia.r/julia_test.d/input.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
114 changes: 34 additions & 80 deletions parsers/julia.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,69 +344,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:
Expand Down Expand Up @@ -455,67 +470,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)
{
Expand Down

0 comments on commit 41d9d1f

Please sign in to comment.