ocamllex regex syntax error

荒凉一梦 提交于 2019-12-12 00:54:32

问题


I have some basic ocamllex code, which was written by my professor, and seems to be fine:

{ type token = EOF | Word of string }
  rule token = parse
| eof { EOF }
| [’a’-’z’ ’A’-’Z’]+ as word { Word(word) }
| _ { token lexbuf }
    {
     (*module StringMap = BatMap.Make(String) in *)
     let lexbuf = Lexing.from_channel stdin in
     let wordlist =
       let rec next l = match token lexbuf with
         EOF -> l
       | Word(s) -> next (s :: l)
       in next []
     in
     List.iter print_endline wordlist
   }

However, running ocamllex wordcount.mll produces File "wordcount.mll", line 4, character 3: syntax error.

This indicates that there is an error at the first [ in the regex in the fourth line here. What is going on?


回答1:


You seem to have curly quotes (also called "smart quotes" -- ugh) in your text. You need regular old single quotes.

curly quote: ’
old fashioned single quote: '


来源:https://stackoverflow.com/questions/33048725/ocamllex-regex-syntax-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!