Skip to content

Commit

Permalink
adding tests, also making find_tokens not use string algebra but repl…
Browse files Browse the repository at this point in the history
…ace with nextind/prevind
  • Loading branch information
tlienart committed Oct 30, 2018
1 parent 334a8ad commit 1a8e8df
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/parser/find_tokens.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ function find_tokens(str::AbstractString, tokens_dict::Dict,
stack = subs(str, head_idx, endchar_idx)
if λ(stack)
# offset==True --> looked at 1 extra char (lookahead)
head_idx = endchar_idx - offset
head_idx = prevind(str, endchar_idx, offset)
push!(tokens, Token(case, chop(stack, tail=offset)))
# token identified, no need to check other cases.
break
end
else # rule-based match, greedy catch until fail
stack, shift = head, 1
nextchar_idx = head_idx + shift
nextchar_idx = nextind(str, head_idx)
while λ(shift, str[nextchar_idx])
stack = subs(str, head_idx, nextchar_idx)
shift += 1
nextchar_idx += 1
nextchar_idx = nextind(str, nextchar_idx)
end
endchar_idx = nextchar_idx - 1
endchar_idx = prevind(str, nextchar_idx)
if endchar_idx > head_idx
push!(tokens, Token(case, stack))
head_idx = endchar_idx
Expand Down

0 comments on commit 1a8e8df

Please sign in to comment.