Skip to content

Commit

Permalink
Lexer improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
eilvelia committed Dec 27, 2024
1 parent 9346fb3 commit 9da765b
Show file tree
Hide file tree
Showing 8 changed files with 7,659 additions and 5,406 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ default: build

.PHONY: generate-re2c
generate-re2c:
re2ocaml -W --no-generation-date -i src/lexer.ml.re -o src/lexer.ml
re2ocaml -W -Wno-nondeterministic-tags --no-generation-date --conditions -i src/lexer.ml.re -o src/lexer.ml
sed -i "s/'\\\\f'/'\\\\x0C'/g" src/lexer.ml
sed -i "s/'\\\\a'/'\\\\x07'/g" src/lexer.ml
sed -i "s/'\\\\v'/'\\\\x0B'/g" src/lexer.ml
Expand Down
2 changes: 1 addition & 1 deletion src/err.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
exception Custom_parsing_error of string * Loc.t
exception Custom_lexing_error of string
exception Custom_lexing_error of string * Loc.t

type error_loc = Loc.t

Expand Down
12 changes: 6 additions & 6 deletions src/kdl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ module L = Lens

let document_revised =
MenhirLib.Convert.Simplified.traditional2revised Parser.document
let parse yyrecord : (t, error) result =
try Ok (document_revised @@ Lexer.main_tokenizer yyrecord) with
| Custom_lexing_error msg ->
Error (msg, Lexer.get_location yyrecord)
let parse state : (t, error) result =
try Ok (document_revised @@ Lexer.main_tokenizer state) with
| Custom_lexing_error (msg, loc) ->
Error (msg, loc)
| Custom_parsing_error (msg, loc) ->
Error (msg, loc)
| Parser.Error ->
(* note: this doesn't seem to print correct locations with lookahead tokens *)
Error ("Syntax error", Lexer.get_location yyrecord)
Error ("Syntax error", Lexer.get_location state)

let from_string ?fname input =
parse (Lexer.make_tokenizer_yyrecord ?fname input)
parse (Lexer.make_tokenizer_state ?fname input)

let from_string_exn ?fname input =
match from_string ?fname input with
Expand Down
Loading

0 comments on commit 9da765b

Please sign in to comment.