Your BNF contains only CR, but you parse the code to terminate using LF. Is that intended? BNF supports LF (Unix), CR (Mac), and CRLF (Win) EOLs:
Rule_|_Def.__|_Meaning___
CR | %x0D | carriage return
LF | %x0A | linefeed
CRLF | CR LF | Internet standard newline