Skip to content

Commit

Permalink
Merged rm-base-extensions into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacLN committed May 4, 2017
2 parents 9827afc + a5b46f2 commit 395662b
Show file tree
Hide file tree
Showing 24 changed files with 269 additions and 301 deletions.
8 changes: 4 additions & 4 deletions src/CSTParser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module CSTParser
global debug = true

using Tokenize
import Base: next, start, done, length, first, last, endof, +, isempty, getindex, setindex!
import Base: next, start, done, length, first, last, endof, getindex, setindex!
import Tokenize.Tokens
import Tokenize.Tokens: Token, iskeyword, isliteral, isoperator
import Tokenize.Lexers: Lexer, peekchar, iswhitespace
Expand Down Expand Up @@ -138,11 +138,11 @@ function parse_compound(ps::ParseState, ret)
elseif isajuxtaposition(ps, ret)
op = OPERATOR{TimesOp, Tokens.STAR, false}(0)
@catcherror ps startbyte ret = parse_operator(ps, ret, op)
elseif ps.nt.kind == Tokens.LPAREN && isempty(ps.ws)
elseif ps.nt.kind == Tokens.LPAREN && isemptyws(ps.ws)
@catcherror ps startbyte ret = @closer ps paren parse_call(ps, ret)
elseif ps.nt.kind == Tokens.LBRACE && isempty(ps.ws)
elseif ps.nt.kind == Tokens.LBRACE && isemptyws(ps.ws)
@catcherror ps startbyte ret = parse_curly(ps, ret)
elseif ps.nt.kind == Tokens.LSQUARE && isempty(ps.ws) && !(ret isa OPERATOR)
elseif ps.nt.kind == Tokens.LSQUARE && isemptyws(ps.ws) && !(ret isa OPERATOR)
@catcherror ps startbyte ret = @nocloser ps block parse_ref(ps, ret)
elseif ps.nt.kind == Tokens.COMMA
@catcherror ps startbyte ret = parse_tuple(ps, ret)
Expand Down
62 changes: 31 additions & 31 deletions src/components/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,97 +173,97 @@ _start_typed_vcat(x::EXPR) = Iterator{:typed_vcat}(1, length(x.args) + length(x.

function next(x::EXPR, s::Iterator{:vect})
if isodd(s.i)
return x.punctuation[div(s.i + 1, 2)], +s
return x.punctuation[div(s.i + 1, 2)], next_iter(s)
elseif s.i == s.n
return last(x.punctuation), +s
return last(x.punctuation), next_iter(s)
else
return x.args[div(s.i, 2)], +s
return x.args[div(s.i, 2)], next_iter(s)
end
end

function next(x::EXPR, s::Iterator{:vcat})
np = length(x.punctuation) - 2
if np > 0
if s.i == s.n
return last(x.punctuation), +s
return last(x.punctuation), next_iter(s)
elseif s.i == s.n - 1
return last(x.args), +s
return last(x.args), next_iter(s)
elseif iseven(s.i)
return x.args[div(s.i, 2)], +s
return x.args[div(s.i, 2)], next_iter(s)
else
return x.punctuation[div(s.i + 1, 2)], +s
return x.punctuation[div(s.i + 1, 2)], next_iter(s)
end
else
if s.i == 1
return first(x.punctuation), +s
return first(x.punctuation), next_iter(s)
elseif s.i == s.n
return last(x.punctuation), +s
return last(x.punctuation), next_iter(s)
else
return x.args[s.i - 1], +s
return x.args[s.i - 1], next_iter(s)
end
end
end

function next(x::EXPR, s::Iterator{:hcat})
if s.i == 1
return first(x.punctuation), +s
return first(x.punctuation), next_iter(s)
elseif s.i == s.n
return last(x.punctuation), +s
return last(x.punctuation), next_iter(s)
else
return x.args[s.i - 1], +s
return x.args[s.i - 1], next_iter(s)
end
end

next(x::EXPR, s::Iterator{:row}) = x.args[s.i], +s
next(x::EXPR, s::Iterator{:row}) = x.args[s.i], next_iter(s)

function next(x::EXPR, s::Iterator{:typed_vcat})
if length(x.args) > 0 && last(x.args) isa EXPR && last(x.args).head == PARAMETERS
if s.i == s.n
return last(x.punctuation), +s
return last(x.punctuation), next_iter(s)
elseif s.i == s.n - 1
return last(x.args), +s
return last(x.args), next_iter(s)
elseif s.i == 1
return x.args[1], +s
return x.args[1], next_iter(s)
elseif s.i == 2
return first(x.punctuation), +s
return first(x.punctuation), next_iter(s)
elseif isodd(s.i)
return x.args[div(s.i + 1, 2)], +s
return x.args[div(s.i + 1, 2)], next_iter(s)
else
return x.punctuation[div(s.i, 2)], +s
return x.punctuation[div(s.i, 2)], next_iter(s)
end
else
if s.i == 1
return x.args[1], +s
return x.args[1], next_iter(s)
elseif s.i == 2
return first(x.punctuation), +s
return first(x.punctuation), next_iter(s)
elseif s.i == s.n
return last(x.punctuation), +s
return last(x.punctuation), next_iter(s)
else
return x.args[s.i - 1], +s
return x.args[s.i - 1], next_iter(s)
end
end
end

function next(x::EXPR, s::Iterator{:typed_hcat})
if s.i == 1
return x.args[1], +s
return x.args[1], next_iter(s)
elseif s.i == 2
return first(x.punctuation), +s
return first(x.punctuation), next_iter(s)
elseif s.i == s.n
return last(x.punctuation), +s
return last(x.punctuation), next_iter(s)
else
return x.args[s.i - 1], +s
return x.args[s.i - 1], next_iter(s)
end
end

_start_ref(x::EXPR) = Iterator{:ref}(1, length(x.args) + length(x.punctuation))

function next(x::EXPR, s::Iterator{:ref})
if s.i == s.n
return last(x.punctuation), +s
return last(x.punctuation), next_iter(s)
elseif isodd(s.i)
return x.args[div(s.i + 1, 2)], +s
return x.args[div(s.i + 1, 2)], next_iter(s)
else
return x.punctuation[div(s.i, 2)], +s
return x.punctuation[div(s.i, 2)], next_iter(s)
end
end
10 changes: 5 additions & 5 deletions src/components/curly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ _start_curly(x::EXPR) = Iterator{:curly}(1, length(x.args) + length(x.punctuatio

function next(x::EXPR, s::Iterator{:curly})
if s.i == 1
return x.args[1], +s
return x.args[1], next_iter(s)
elseif s.i == 2
return x.punctuation[1], +s
return x.punctuation[1], next_iter(s)
elseif s.i == s.n
return last(x.punctuation), +s
return last(x.punctuation), next_iter(s)
elseif isodd(s.i)
return x.args[div(s.i + 1, 2)], +s
return x.args[div(s.i + 1, 2)], next_iter(s)
else
return x.punctuation[div(s.i, 2)], +s
return x.punctuation[div(s.i, 2)], next_iter(s)
end
end
10 changes: 5 additions & 5 deletions src/components/do.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ end

function next(x::EXPR, s::Iterator{:do})
if s.i == 1
return x.args[1], +s
return x.args[1], next_iter(s)
elseif s.i == 2
return x.head, +s
return x.head, next_iter(s)
elseif s.i == 3
return x.args[2], +s
return x.args[2], next_iter(s)
elseif s.i == 4
return x.args[3], +s
return x.args[3], next_iter(s)
else
return x.punctuation[1], +s
return x.punctuation[1], next_iter(s)
end
end
30 changes: 15 additions & 15 deletions src/components/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,53 +177,53 @@ _start_parameters(x::EXPR) = Iterator{:parameters}(1, length(x.args) + length(x.

function next(x::EXPR, s::Iterator{:function})
if s.i == 1
return x.head, +s
return x.head, next_iter(s)
elseif s.i == s.n
return x.punctuation[1], +s
return x.punctuation[1], next_iter(s)
else
return x.args[s.i - 1], +s
return x.args[s.i - 1], next_iter(s)
end
end

function next(x::EXPR, s::Iterator{:call})
if length(x.args) > 0 && last(x.args) isa EXPR && last(x.args).head == PARAMETERS && s.i == (s.n - 1)
return last(x.args), +s
return last(x.args), next_iter(s)
end
if s.i == s.n
return last(x.punctuation), +s
return last(x.punctuation), next_iter(s)
elseif isodd(s.i)
return x.args[div(s.i + 1, 2)], +s
return x.args[div(s.i + 1, 2)], next_iter(s)
else
return x.punctuation[div(s.i, 2)], +s
return x.punctuation[div(s.i, 2)], next_iter(s)
end
end

function next(x::EXPR, s::Iterator{:parameters})
if isodd(s.i)
return x.args[div(s.i + 1, 2)], +s
return x.args[div(s.i + 1, 2)], next_iter(s)
elseif iseven(s.i)
return x.punctuation[div(s.i, 2)], +s
return x.punctuation[div(s.i, 2)], next_iter(s)
end
end

_start_ccall(x::EXPR) = Iterator{:ccall}(1, 1 + length(x.args) + length(x.punctuation))

function next(x::EXPR, s::Iterator{:ccall})
# if length(x.args)>0 && last(x.args) isa EXPR && last(x.args).head == PARAMETERS && s.i == (s.n-1)
# return last(x.args), +s
# return last(x.args), next_iter(s)
# end
if s.i == 1
return x.head, +s
return x.head, next_iter(s)
elseif s.i == s.n
return last(x.punctuation), +s
return last(x.punctuation), next_iter(s)
elseif iseven(s.i)
return x.punctuation[div(s.i, 2)], +s
return x.punctuation[div(s.i, 2)], next_iter(s)
else
return x.args[div(s.i - 1, 2)], +s
return x.args[div(s.i - 1, 2)], next_iter(s)
end
end

next(x::EXPR, s::Iterator{:stdcall}) = x.head, +s
next(x::EXPR, s::Iterator{:stdcall}) = x.head, next_iter(s)


# Linting
Expand Down
28 changes: 14 additions & 14 deletions src/components/generators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ end

function next(x::EXPR, s::Iterator{:generator})
if isodd(s.i)
return x.args[div(s.i + 1, 2)], +s
return x.args[div(s.i + 1, 2)], next_iter(s)
else
return x.punctuation[div(s.i, 2)], +s
return x.punctuation[div(s.i, 2)], next_iter(s)
end
end

Expand All @@ -67,13 +67,13 @@ end

function next(x::EXPR, s::Iterator{:filter})
if s.i == s.n
return first(x.args), +s
return first(x.args), next_iter(s)
elseif s.i == s.n - 1
return first(x.punctuation), +s
return first(x.punctuation), next_iter(s)
elseif isodd(s.i)
return x.args[div(s.i + 1, 2) + 1], +s
return x.args[div(s.i + 1, 2) + 1], next_iter(s)
else
return x.punctuation[div(s.i, 2) + 1], +s
return x.punctuation[div(s.i, 2) + 1], next_iter(s)
end
end

Expand All @@ -83,11 +83,11 @@ end

function next(x::EXPR, s::Iterator{:comprehension})
if s.i == 1
return x.punctuation[1], +s
return x.punctuation[1], next_iter(s)
elseif s.i == 2
return x.args[1], +s
return x.args[1], next_iter(s)
elseif s.i == 3
return x.punctuation[2], +s
return x.punctuation[2], next_iter(s)
end
end

Expand All @@ -97,14 +97,14 @@ end

function next(x::EXPR, s::Iterator{:typed_comprehension})
if s.i == 1
return x.args[1], +s
return x.args[1], next_iter(s)
elseif s.i == 2
return x.punctuation[1], +s
return x.punctuation[1], next_iter(s)
elseif s.i == 3
return x.args[2], +s
return x.args[2], next_iter(s)
elseif s.i == 4
return x.punctuation[2], +s
return x.punctuation[2], next_iter(s)
end
end

next(x::EXPR, s::Iterator{:flatten}) = x.args[1], +s
next(x::EXPR, s::Iterator{:flatten}) = x.args[1], next_iter(s)
30 changes: 15 additions & 15 deletions src/components/genericblocks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,52 +48,52 @@ end

function next(x::EXPR, s::Iterator{:invisiblebrackets})
if s.i == 1
return first(x.punctuation), +s
return first(x.punctuation), next_iter(s)
elseif s.i == 2
return x.args[1], +s
return x.args[1], next_iter(s)
elseif s.i == 3
return last(x.punctuation), +s
return last(x.punctuation), next_iter(s)
end
end

function next(x::EXPR, s::Iterator{:block})
if !isempty(x.punctuation) && first(x.punctuation) isa PUNCTUATION{Tokens.COMMA}
if isodd(s.i)
return x.args[div(s.i + 1, 2)], +s
return x.args[div(s.i + 1, 2)], next_iter(s)
else
return x.punctuation[div(s.i, 2)], +s
return x.punctuation[div(s.i, 2)], next_iter(s)
end
elseif length(x.punctuation) == 2
if s.i == 1
return x.punctuation[1], +s
return x.punctuation[1], next_iter(s)
elseif s.i == s.n
return x.punctuation[2], +s
return x.punctuation[2], next_iter(s)
else
return x.args[s.i - 1], +s
return x.args[s.i - 1], next_iter(s)
end
end

return x.args[s.i], +s
return x.args[s.i], next_iter(s)
end

function next(x::EXPR, s::Iterator{:begin})
if s.i == 1
return x.head, +s
return x.head, next_iter(s)
elseif s.i == 2
return x.args[1], +s
return x.args[1], next_iter(s)
elseif s.i == 3
return x.punctuation[1], +s
return x.punctuation[1], next_iter(s)
end
end

function next(x::EXPR, s::Iterator{:toplevelblock})
if isempty(x.punctuation)
return x.args[s.i], +s
return x.args[s.i], next_iter(s)
else
if isodd(s.i)
return x.args[div(s.i + 1, 2)], +s
return x.args[div(s.i + 1, 2)], next_iter(s)
else
return x.punctuation[div(s.i, 2)], +s
return x.punctuation[div(s.i, 2)], next_iter(s)
end
end
end
Expand Down
Loading

0 comments on commit 395662b

Please # to comment.