~ubuntu-branches/ubuntu/vivid/menhir/vivid

« back to all changes in this revision

Viewing changes to demos/calc-two/lexer.mll

  • Committer: Package Import Robot
  • Author(s): Mehdi Dogguy
  • Date: 2014-04-27 14:49:45 UTC
  • mfrom: (1.2.9)
  • Revision ID: package-import@ubuntu.com-20140427144945-vlmb6p3kget3s65q
Tags: 20140422.dfsg-1
New upstream relese.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
}
21
21
 
 
22
(* This rule looks for a single line, terminated with '\n' or eof.
 
23
   It returns a pair of an optional string (the line that was found)
 
24
   and a Boolean flag (false if eof was reached). *)
 
25
 
22
26
rule line = parse
23
27
| ([^'\n']* '\n') as line
24
 
    { line }
 
28
    (* Normal case: one line, no eof. *)
 
29
    { Some line, true }
25
30
| eof
26
 
    { exit 0 }
 
31
    (* Normal case: no data, eof. *)
 
32
    { None, false }
 
33
| ([^'\n']+ as line) eof
 
34
    (* Special case: some data but missing '\n', then eof.
 
35
       Consider this as the last line, and add the missing '\n'. *)
 
36
    { Some (line ^ "\n"), false }
 
37
 
 
38
(* This rule analyzes a single line and turns it into a stream of
 
39
   tokens. *)
27
40
 
28
41
and token = parse
29
42
| [' ' '\t']
44
57
    { LPAREN }
45
58
| ')'
46
59
    { RPAREN }
47
 
| eof
48
 
    { exit 0 }
49
60
| _
50
61
    { raise (Error (Printf.sprintf "At offset %d: unexpected character.\n" (Lexing.lexeme_start lexbuf))) }
51
62