xamvolagis
xamvolagis

Reputation: 15

ocamllex regex syntax error

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?

Upvotes: 0

Views: 207

Answers (1)

Jeffrey Scofield
Jeffrey Scofield

Reputation: 66823

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: '

Upvotes: 3

Related Questions