ocamllex 正则表达式语法错误

ocamllex regex syntax error

我有一些基本的 ocamllex 代码,是我的教授写的,看起来还不错:

{ 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
   }

然而,运行 ocamllex wordcount.mll 产生 File "wordcount.mll", line 4, character 3: syntax error.

这里说明第四行正则表达式第一个[处有错误。这是怎么回事?

您的文字中似乎有弯引号(也称为 "smart quotes" -- 呃)。您需要常规的旧单引号。

curly quote: ’
old fashioned single quote: '