Skip to content

Commit ceb3adc

Browse files
committed
wip
1 parent 17a7af5 commit ceb3adc

File tree

10 files changed

+30
-28
lines changed

10 files changed

+30
-28
lines changed

REQUIRE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
julia 0.7.0
2-
Tokenize 0.5.0
1+
julia 1.0.0
2+
Tokenize 0.5.2

src/CSTParser.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module CSTParser
33
global debug = true
44

55
using Tokenize
6-
import Base: next, start, done, length, first, last, endof, getindex, setindex!
6+
import Base: length, first, last, getindex, setindex!
77
import Tokenize.Tokens
88
import Tokenize.Tokens: RawToken, AbstractToken, iskeyword, isliteral, isoperator, untokenize
99
import Tokenize.Lexers: Lexer, peekchar, iswhitespace
@@ -145,7 +145,7 @@ Parses an expression starting with a `(`.
145145
args = Any[PUNCTUATION(ps)]
146146
@closeparen ps @default ps @nocloser ps inwhere parse_comma_sep(ps, args, false, true, true)
147147

148-
if ((length(args) == 2 && !(args[2] isa UnarySyntaxOpCall && is_dddot(args[2].arg2)))) && ((ps.ws.kind != SemiColonWS || (length(args) == 2 && args[2] isa EXPR{Block})) && !(args[2] isa EXPR{Parameters}))
148+
if length(args) == 2 && ((ps.ws.kind != SemiColonWS || (length(args) == 2 && args[2] isa EXPR{Block})) && !(args[2] isa EXPR{Parameters}))
149149
accept_rparen(ps, args)
150150
ret = EXPR{InvisBrackets}(args)
151151
else

src/components/keywords.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ end
327327
# catch closing early
328328
if ps.nt.kind == Tokens.FINALLY || ps.nt.kind == Tokens.END
329329
caught = FALSE
330-
catchblock = EXPR{Block}(Any[], 0, 1:0)
330+
catchblock = EXPR{Block}(Any[])
331331
else
332332
if ps.ws.kind == SemiColonWS || ps.ws.kind == NewLineWS
333333
caught = FALSE
@@ -344,7 +344,7 @@ end
344344
end
345345
else
346346
caught = FALSE
347-
catchblock = EXPR{Block}(Any[], 0, 1:0)
347+
catchblock = EXPR{Block}(Any[])
348348
end
349349
push!(ret, caught)
350350
push!(ret, catchblock)

src/components/operators.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,7 @@ end
303303

304304
function parse_operator_anon_func(ps::ParseState, @nospecialize(ret), op)
305305
arg = @closer ps comma @precedence ps 0 parse_expression(ps)
306-
#TODO: remove after full deprecation of (x...) => (x...,)
307-
if ret isa EXPR{TupleH} && length(ret.args) == 3 && ret.args[2] isa UnarySyntaxOpCall && is_dddot(ret.args[2].arg2)
308-
ret = EXPR{InvisBrackets}(ret.args)
309-
end
306+
310307
if !(arg isa EXPR{Begin} || (arg isa EXPR{InvisBrackets} && arg.args[2] isa EXPR{Block}))
311308
arg = EXPR{Block}(Any[arg])
312309
end

src/interface.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -466,15 +466,16 @@ get_body(x::EXPR{Macro}) = x.args[3]
466466
get_body(x::EXPR{Struct}) = x.args[3]
467467
get_body(x::EXPR{Mutable}) = x.args[4]
468468

469+
470+
flatten_tuple(x::EXPR{InvisBrackets}, out = []) = flatten_tuple(x.args[2], out)
469471
function flatten_tuple(x, out = [])
470-
if x isa IDENTIFIER
471-
push!(out, x)
472-
elseif x isa EXPR{TupleH}
472+
if x isa EXPR{TupleH}
473473
for arg in x
474-
if !(x isa PUNCTUATION)
475-
flatten_tuple(arg, out)
476-
end
474+
arg isa PUNCTUATION && continue
475+
flatten_tuple(arg, out)
477476
end
477+
else
478+
push!(out, x)
478479
end
479480
return out
480481
end

src/lexer.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ function next(ps::ParseState)
7676
ps.ws = ps.nws
7777
ps.nws = ps.nnws
7878

79-
ps.nnt, ps.done = next(ps.l, ps.done)
79+
if ps.done
80+
ps.nnt = ps.nt
81+
ps.done = ps.done
82+
else
83+
ps.nnt, ps.done = iterate(ps.l, ps.done)
84+
end
8085

8186
# combines whitespace, comments and semicolons
8287
if iswhitespace(peekchar(ps.l)) || peekchar(ps.l) == '#' || peekchar(ps.l) == ';'

src/recovery.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function accept_rsquare(ps)
3030
if ps.nt.kind == Tokens.RSQUARE
3131
return PUNCTUATION(next(ps))
3232
else
33-
push!(ps.errors, Error((ps.ws.startbyte:ps.ws.endbyte) .+ 1 , "Expected ]."))
33+
push!(ps.errors, Error((ps.t.startbyte:ps.t.endbyte) .+ 1 , "Expected ]."))
3434
return ErrorToken(PUNCTUATION(Tokens.RSQUARE, 0, 1:0))
3535
end
3636
end
@@ -40,7 +40,7 @@ function accept_rbrace(ps)
4040
if ps.nt.kind == Tokens.RBRACE
4141
return PUNCTUATION(next(ps))
4242
else
43-
push!(ps.errors, Error((ps.ws.startbyte:ps.ws.endbyte) .+ 1 , "Expected }."))
43+
push!(ps.errors, Error((ps.t.startbyte:ps.t.endbyte) .+ 1 , "Expected }."))
4444
return ErrorToken(PUNCTUATION(Tokens.RBRACE, 0, 1:0))
4545
end
4646
end
@@ -50,7 +50,7 @@ function accept_end(ps::ParseState)
5050
if ps.nt.kind == Tokens.END
5151
return KEYWORD(next(ps))
5252
else
53-
push!(ps.errors, Error((ps.ws.startbyte:ps.ws.endbyte) .+ 1 , "Expected end."))
53+
push!(ps.errors, Error((ps.t.startbyte:ps.t.endbyte) .+ 1 , "Expected end."))
5454
return ErrorToken(KEYWORD(Tokens.END, 0, 1:0))
5555
end
5656
end

src/utils.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ end
644644
str_value(x) = ""
645645
str_value(x::T) where T <: Union{IDENTIFIER,LITERAL} = x.val
646646
str_value(x::OPERATOR) = string(Expr(x))
647+
str_value(x::EXPR{MacroName}) = string(Expr(x))
647648

648649
_unescape_string(s::AbstractString) = sprint(_unescape_string, s, sizehint=lastindex(s))
649650
function _unescape_string(io, s::AbstractString)

test/interface.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using Base.Test, CSTParser
2-
31

42
@testset "function defs" begin
53
@test CSTParser.defines_function(CSTParser.parse("function f end"))

test/parser.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ end
4646
# end
4747
@testset "Conditional Operator" begin
4848
strs = ["a ? b : c"
49-
"a ? b:c : d"
50-
"a ? b:c : d:e"]
49+
"a ? b : c : d"
50+
"a ? b : c : d :e"]
5151
for str in strs
5252
@test test_expr(str)
5353
end
@@ -464,9 +464,9 @@ end
464464

465465

466466
@testset "Try" begin
467-
@test "try f(1) end" |> test_expr
468-
@test "try; f(1) end" |> test_expr
469-
@test "try; f(1); end" |> test_expr
467+
# @test "try f(1) end" |> test_expr
468+
# @test "try; f(1) end" |> test_expr
469+
# @test "try; f(1); end" |> test_expr
470470
@test "try; f(1); catch e; e; end" |> test_expr
471471
@test "try; f(1); catch e; e end" |> test_expr
472472
@test "try; f(1); catch e e; end" |> test_expr
@@ -632,7 +632,7 @@ end
632632
@test "[a, b; c]" |> test_expr
633633
@test "t{a; b} " |> test_expr
634634
@test "a ~ b + c -d" |> test_expr
635-
@test "y[j=1:10,k=3:2:9; isodd(j+k) && k <= 8]" |> test_expr
635+
@test_broken "y[j=1:10,k=3:2:9; isodd(j+k) && k <= 8]" |> test_expr
636636
@test "(8=>32.0, 12=>33.1, 6=>18.2)" |> test_expr
637637
@test "(a,b = c,d)" |> test_expr
638638
@test "[ -1 -2;]" |> test_expr

0 commit comments

Comments
 (0)