Parse scalar expressions with source spans
This commit is contained in:
9 files changed
+363
-12
No files matched your search
@@ -0,0 +1,17 @@
|
||||
let one_line text =
|
||||
match String.index_opt text '\n' with
|
||||
| Some index -> String.sub text 0 index
|
||||
| None -> text
|
||||
|
||||
let unexpected text lexbuf =
|
||||
let start = Lexing.lexeme_start_p lexbuf in
|
||||
let stop = Lexing.lexeme_end_p lexbuf in
|
||||
let token =
|
||||
if start.Lexing.pos_cnum >= String.length text then "end of file"
|
||||
else "`" ^ one_line (Lexing.lexeme lexbuf) ^ "`"
|
||||
in
|
||||
Diagnostic.error (Location.span_of_lexing start stop) "syntax error: unexpected %s" token
|
||||
|
||||
let expression text =
|
||||
let lexbuf = Lexing.from_string text in
|
||||
try Parser.expr Lexer.token lexbuf with Parsing.Parse_error -> unexpected text lexbuf
|
||||
Reference in new issue
Block a user