Commits

Sébastien Ferré  committed 6335434

Initial revision

  • Participants
  • Parent commits f4b89d8

Comments (0)

Files changed (2)

+{
+open Token
+} 
+
+let skip_char = [' ' '\t']
+let ident_char = ['A'-'Z' 'a'-'z' '0'-'9' '_']
+let digit = ['0'-'9']
+
+rule token = parse
+| skip_char { token lexbuf }
+| "\\\n" { token lexbuf }
+| '\n' { EOL }
+| '`' { BackQuote }
+| '~' { Tilda }
+| '!' { Exclam }
+| '@' { At }
+| '#' { Sharp }
+| '$' { Dollar }
+| '%' { Percent }
+| '^' { Hat }
+| '&' { Et }
+| '*' { Star }
+| '(' { LeftPar }
+| ')' { RightPar }
+| '-' { Minus }
+| '+' { Plus }
+| '=' { Equal }
+| '{' { LeftAcc }
+| '}' { RightAcc }
+| '[' { LeftBra }
+| ']' { RightBra }
+| '|' { Pipe }
+| '\\' { BackSlash }
+| '/' { Slash }
+| '?' { Interro }
+| '<' { LT }
+| '>' { GT }
+| ',' { Comma }
+| '.''.' { DotDot }
+| '.' { Dot }
+| ':' { Colon }
+| ';' { SemiColon }
+| '"' { DoubleQuote }
+| '\'' { Quote }
+| ['a'-'z' 'A'-'Z' '_'] ident_char *
+    { Ident(Lexing.lexeme lexbuf) }
+| ['+' '-']? digit+
+    { Int(int_of_string(Lexing.lexeme lexbuf)) }
+| ['+' '-']? digit+ '.' digit* (['e' 'E'] ['+' '-']? digit+)?
+    { Float(float_of_string(Lexing.lexeme lexbuf)) }
+| '`' _ '`'
+    { Char((Lexing.lexeme lexbuf).[1]) }
+| '"' [^ '\\' '"']* ('\\' _ [^ '\\' '"']*)* '"'
+  { let s = Lexing.lexeme lexbuf in String(String.sub s 1 (String.length s - 2)) }
+| '\'' [^ '\\' '\'']* ('\\' _ [^ '\\' '\'']*)* '\''
+  { let s = Lexing.lexeme lexbuf in Term(String.sub s 1 (String.length s - 2)) }
+| eof { raise Eof }
+exception Eof
+
+type t =
+    BackQuote | Tilda | Exclam | At | Sharp | Dollar | Percent | Hat | Et | Star
+  | LeftPar | RightPar | Minus | Plus | Equal | LeftAcc | RightAcc | LeftBra | RightBra
+  | Pipe | BackSlash | Slash | Interro | LT | GT | Comma | DotDot | Dot | Colon | SemiColon
+  | DoubleQuote | Quote
+  | Ident of string | Int of int | Float of float | Char of char | String of string | Term of string | EOL