aboutsummaryrefslogtreecommitdiff
path: root/lib/lexer.mll
diff options
context:
space:
mode:
Diffstat (limited to 'lib/lexer.mll')
-rw-r--r--lib/lexer.mll18
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")) }