在我的声明中,lexer.mll
我声明EOS
如下:
let line_feed = '\n' (* %x200A *)
let carriage_return = '\r' (* %x200D *)
let line_terminator = line_feed | carriage_return | carriage_return line_feed
(* KO: %x2028 | %x2029 *)
let LINE_END = line_terminator
let tab_character = '\x09' (* CHARACTER TABULATION *)
let eom_character = '\x19' (* END OF MEDIUM *)
let space_character = '\x20' (* SPACE *)
let underscore = '\x5F' (* LOW LINE or SPACING UNDERSCORE *)
let WSC = tab_character | eom_character | space_character
let line_continuation = WSC* underscore WSC* line_terminator
let WS = (WSC | line_continuation)+
let EOL = WS? LINE_END
let EOS = EOL*
rule token = parse
| WS { token lexbuf }
| LINE_END { newline lexbuf; token lexbuf }
| EOS { EOS }
在我的parser.mly
,我有这样的事情:
%token EOS
...
%%
nonterminal :
statement EOS
statement { semantic-action }
我如下编辑我test_KO.txt
的Emacs
,它在解析时引发错误:
a_statement
b_statement
但是,如果我在后面添加一个space
,a_statement
它会通过解析:
a_statement(space)
b_statement
我想原因是line_terminator
无法识别,test_KO.txt
但不在同一行;如果它们之间有一个,则可以识别。a_statemnt
b_statement
line_terminator
space
您认为添加x2028和x2029会line_terminator
解决问题吗?由于ocamllex
可能不支持很好的 unicode,所以测试它会很复杂......
否则,有没有其他解决方案?