From 5d227bcd0055d02e1d49a3dcd27e80a756923d5b Mon Sep 17 00:00:00 2001 From: Malte Voos Date: Sun, 23 Jun 2024 23:31:59 +0200 Subject: split code into smaller libraries and make a better repl --- src/parser/Lexer.mll | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/parser/Lexer.mll (limited to 'src/parser/Lexer.mll') diff --git a/src/parser/Lexer.mll b/src/parser/Lexer.mll new file mode 100644 index 0000000..708bb64 --- /dev/null +++ b/src/parser/Lexer.mll @@ -0,0 +1,37 @@ +{ +open Grammar + +exception IllegalCharacter of char +} + +let whitespace = [' ' '\t' '\r' '\n']+ +let letter = ['a'-'z' 'A'-'Z'] +let ident = letter+ + +rule token = + parse + | whitespace { token lexbuf } + | "(" { LPR } + | ")" { RPR } + | "[" { LBR } + | "]" { RBR } + | "->" { ARROW } + | "*" { ASTERISK } + | "\\" { BACKSLASH } + | "::" { DOUBLE_COLON } + | ":" { COLON } + | "," { COMMA } + | "." { DOT } + | "=>" { FATARROW } + | "_" { UNDERSCORE } + | "at" { AT } + | "fst" { FST } + | "snd" { SND } + | "type" { TYPE } + | "bool" { BOOL } + | "true" { TRUE } + | "false" { FALSE } + | "bool-elim" { BOOL_ELIM } + | ident { IDENT (Lexing.lexeme lexbuf) } + | eof { EOF } + | (_ as illegal_char) { raise (IllegalCharacter illegal_char) } -- cgit 1.4.1