Skip to content

Commit

Permalink
issues 46/47
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacLN committed Aug 29, 2017
1 parent 5ccf383 commit cf37491
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/components/controlflow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ Parse an `if` block.
function parse_if(ps::ParseState, nested = false)
# Parsing
kw = INSTANCE(ps)
if ps.ws.kind == NewLineWS || ps.ws.kind == SemiColonWS
return EXPR{ERROR}(EXPR[], 0, 0:-1, "missing conditional in `if`")
end
@catcherror ps cond = @default ps @closer ps block @closer ps ws parse_expression(ps)

ifblock = EXPR{Block}(EXPR[], 0, 1:0, "")
Expand Down
27 changes: 27 additions & 0 deletions src/components/loops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,47 @@ end

function parse_ranges(ps::ParseState)
arg = @closer ps range @closer ps ws parse_expression(ps)

if !is_range(arg)
ps.errored = true
return EXPR{ERROR}(EXPR[], 0, 0:-1, "invalid iteration specification")
end
if ps.nt.kind == Tokens.COMMA
arg = EXPR{Block}(EXPR[arg], "")
while ps.nt.kind == Tokens.COMMA
next(ps)
push!(arg, INSTANCE(ps))

@catcherror ps nextarg = @closer ps comma @closer ps ws parse_expression(ps)
if !is_range(nextarg)
ps.errored = true
return EXPR{ERROR}(EXPR[], 0, 0:-1, "invalid iteration specification")
end
push!(arg, nextarg)
end
end
return arg
end


function is_range(x) false end
function is_range(x::EXPR{BinarySyntaxOpCall})
if x.args[2] isa EXPR{OPERATOR{AssignmentOp,Tokens.EQ,false}}
return true
else
return false
end
end

function is_range(x::EXPR{BinaryOpCall})
if x.args[2] isa EXPR{OPERATOR{ComparisonOp,Tokens.IN,false}} || x.args[2] isa EXPR{OPERATOR{ComparisonOp,Tokens.ELEMENT_OF,false}}
return true
else
return false
end
end



function parse_kw(ps::ParseState, ::Type{Val{Tokens.WHILE}})
# Parsing
Expand Down

0 comments on commit cf37491

Please # to comment.