ocamllex regex syntax error

2019-08-29 05:41发布

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条回答
三岁会撩人
2楼-- · 2019-08-29 06:04

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: '
查看更多
登录 后发表回答