@@ -46,6 +46,7 @@ rechildren(x::Scan, t::DataType, v::Vector) = Scan{valtype(v),t}(x.match)
4646rechildren (x:: Token , t:: DataType , v:: Vector ) = Token {valtype(v),t} (x. token)
4747rechildren (x:: Tokens , t:: DataType , v:: Vector ) =
4848 Tokens {valtype(v),t,typeof(x.tokens)} (x. tokens)
49+ rechildren (x:: EndOfInput , t:: DataType , v:: Vector ) = EndOfInput {valtype(v),t} ()
4950rechildren (x:: Epsilon , t:: DataType , v:: Vector ) = Epsilon {valtype(v),t} ()
5051rechildren (x:: Fail , t:: DataType , v:: Vector ) = Fail {valtype(v),t} ()
5152rechildren (x:: Seq , t:: DataType , v:: Vector ) = Seq {valtype(v),t} (v)
@@ -97,7 +98,7 @@ better_match_than(::Clause, new::Match, old::Match) = new.last > old.last
9798
9899
99100can_match_epsilon (x:: Union{Satisfy,Scan,Token,Tokens,Fail} , :: Vector{Bool} ) = false
100- can_match_epsilon (x:: Epsilon , :: Vector{Bool} ) = true
101+ can_match_epsilon (x:: Union{ Epsilon,EndOfInput} , :: Vector{Bool} ) = true
101102can_match_epsilon (x:: Seq , ch:: Vector{Bool} ) = all (ch)
102103can_match_epsilon (x:: First , ch:: Vector{Bool} ) =
103104 isempty (ch) ? false :
@@ -236,16 +237,21 @@ end
236237# Epsilon matches
237238#
238239
239- match_epsilon! (x:: Clause , id:: Int , pos:: Int , st:: ParserState ) =
240+ match_epsilon! (x:: Clause , id:: Int , pos:: Int , st:: ParserState ):: MatchResult =
240241 new_match! (Match (id, pos, prevind (st. input, pos), 0 , submatch_empty (st)), st)
241242
242- function match_epsilon! (x:: FollowedBy , id:: Int , pos:: Int , st:: ParserState )
243+ function match_epsilon! (x:: EndOfInput , id:: Int , pos:: Int , st:: ParserState ):: MatchResult
244+ pos <= lastindex (st. input) ? 0 :
245+ new_match! (Match (id, pos, prevind (st. input, pos), 0 , submatch_empty (st)), st)
246+ end
247+
248+ function match_epsilon! (x:: FollowedBy , id:: Int , pos:: Int , st:: ParserState ):: MatchResult
243249 mid = lookup_best_match_id! (pos, x. follow, st)
244250 mid == 0 ? 0 :
245251 new_match! (Match (id, pos, prevind (st. input, pos), 1 , submatch_record! (st, mid)), st)
246252end
247253
248- function match_epsilon! (x:: NotFollowedBy , id:: Int , pos:: Int , st:: ParserState )
254+ function match_epsilon! (x:: NotFollowedBy , id:: Int , pos:: Int , st:: ParserState ):: MatchResult
249255 # This might technically cause infinite recursion, byt a cycle of
250256 # NotFollowedBy clauses is disallowed by the error thrown by
251257 # can_match_epsilon(::NotFollowedBy, ...)
0 commit comments