diff options
author | Marc Coquand <marc@mccd.space> | 2023-12-26 10:08:23 -0600 |
---|---|---|
committer | Marc Coquand <marc@mccd.space> | 2023-12-26 10:08:23 -0600 |
commit | d96e1839eb800bf26bcc38272072d98af69f5d83 (patch) | |
tree | 1570f7f47ba4e39acf4caebfce6eaf4a6575bc97 /lib/lexer.mll | |
parent | 2bb4215b957d912058d490c16ee64320e3724037 (diff) | |
download | fixgen-d96e1839eb800bf26bcc38272072d98af69f5d83.tar.gz fixgen-d96e1839eb800bf26bcc38272072d98af69f5d83.tar.bz2 fixgen-d96e1839eb800bf26bcc38272072d98af69f5d83.zip |
Support const keyword
Diffstat (limited to 'lib/lexer.mll')
-rw-r--r-- | lib/lexer.mll | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/lexer.mll b/lib/lexer.mll index e0c5453..6e9b975 100644 --- a/lib/lexer.mll +++ b/lib/lexer.mll @@ -23,6 +23,7 @@ rule read = | "_int" { INTSYMBOL } | "(" { LBRACE } | ")" { RBRACE } + | '"' { read_string (Buffer.create 20) lexbuf } | int { INT (Lexing.lexeme lexbuf |> int_of_string) } | white { read lexbuf } | ":" { COLON } @@ -32,3 +33,20 @@ rule read = | "." { DOT } | eof { EOF } | _ as c { failwith (Printf.sprintf "unexpected character: %C" c) } + +and read_string buf = + parse + | '"' { STRING (Buffer.contents buf) } + | '\\' '/' { Buffer.add_char buf '/'; read_string buf lexbuf } + | '\\' '\\' { Buffer.add_char buf '\\'; read_string buf lexbuf } + | '\\' 'b' { Buffer.add_char buf '\b'; read_string buf lexbuf } + | '\\' 'f' { Buffer.add_char buf '\012'; read_string buf lexbuf } + | '\\' 'n' { Buffer.add_char buf '\n'; read_string buf lexbuf } + | '\\' 'r' { Buffer.add_char buf '\r'; read_string buf lexbuf } + | '\\' 't' { Buffer.add_char buf '\t'; read_string buf lexbuf } + | [^ '"' '\\']+ + { Buffer.add_string buf (Lexing.lexeme lexbuf); + read_string buf lexbuf + } + | _ { raise (SyntaxError ("Illegal string character: " ^ Lexing.lexeme lexbuf)) } + | eof { raise (SyntaxError ("String is not terminated")) } |