haskell - Alex right_ctx end-of-line ($) chokes on end of file -


in alex have rule looks this

^@ident\:$   {tlabel (init s)} 

so, single line starts identifier followed colon , end of line.

this works fine unless line last in file , there not \n @ end. when happens $ not match , scan fails. need match either end of line (\n) or end of file?

the easiest solution make sure input ends in \n appending 1 @ end of input.

alternatively, can behavior want using predicate instead of $.

^@ident\:/{ eoloreof }   { ... } 

a predicate can examine input stream surrounding token , decide if should match or not. in case, have examine stream after token check \n or eof.

the exact definition depend on wrapper you're using (the definition of type alexinput varies between wrappers), here's 1 got work using "basic" wrapper.

eoloreof :: user -> alexinput -> int -> alexinput -> bool eoloreof _ _ _ (_, after) =   case after of     []       -> true  -- end-of-file     ('\n':_) -> true  -- end-of-line     _        -> false 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -