e0/lib/lexer.mll
2022-03-08 03:20:19 -06:00

22 lines
494 B
OCaml

{ open Parser }
rule f = parse
| '\n' { Lexing.new_line lexbuf; f lexbuf }
| [' ' '\t'] { f lexbuf }
| "extern" { KWD_EXTERN }
| "fn" { KWD_FN }
| "return" { KWD_RETURN }
| "(" { PUNCT_LPAREN }
| ")" { PUNCT_RPAREN }
| "->" { PUNCT_RARROW }
| ":" { PUNCT_COLON }
| ";" { PUNCT_SEMI }
| "{" { PUNCT_LBRACE }
| "}" { PUNCT_RBRACE }
| "-" ['0'-'9']+ as i { LIT_NEG_INT (- (int_of_string i)) }
| ['0'-'9']+ as i { LIT_INT (int_of_string i) }
| ['a'-'z' 'A'-'Z']* as i { IDENT i }
| eof { EOF }