Skip to content

Commit

Permalink
Fix parser (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
gares authored Oct 11, 2023
1 parent abd355a commit 8df1ac4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,15 @@ jobs:

- name: Extra setup on Linux
if: runner.os == 'Linux'
run: opam exec -- echo "workspace=${{ github.workspace }}" >> $GITHUB_ENV
run: |
opam exec -- echo "workspace=${{ github.workspace }}" >> $GITHUB_ENV
sudo apt-get install wdiff
- name: Extra setup on macOS
if: runner.os == 'macOS'
run: |
brew install gnu-time
brew install wdiff
opam exec -- echo "workspace=${{ github.workspace }}" >> $GITHUB_ENV
- name: Extra setup on Windows
Expand All @@ -82,9 +85,11 @@ jobs:
opam exec -- sed -i ' ' tests/sources/*.elpi
& "$Env:CYGWIN_ROOT/setup-x86_64.exe" -q -P time
& "$Env:CYGWIN_ROOT/setup-x86_64.exe" -q -P which
& "$Env:CYGWIN_ROOT/setup-x86_64.exe" -q -P wdiff
opam exec -- which which
opam exec -- time which
opam exec -- which time
opam exec -- which wdiff
# Build ######################################################################
#
Expand Down
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# v1.17.4 (October 2023)

Requires Menhir 20211230 and OCaml 4.08 or above.
Camlp5 8.0 or above is optional.

Parser:
- Fix location handling (used to ignore the char count of the initial loc)

# v1.17.3 (September 2023)

Requires Menhir 20211230 and OCaml 4.08 or above.
Expand Down
14 changes: 10 additions & 4 deletions src/parser/parse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,16 @@ let to_lexing_loc { Util.Loc.source_name; line; line_starts_at; source_start; _
pos_bol = line_starts_at;
pos_cnum = source_start; }

let lexing_set_position lexbuf loc =
let loc = to_lexing_loc loc in
let open Lexing in
lexbuf.lex_curr_p <- { loc with pos_fname = lexbuf.lex_curr_p.pos_fname };
lexbuf.lex_abs_pos <- loc.pos_cnum;
lexbuf.lex_start_p <- loc;
lexbuf.lex_curr_p <- loc

let goal_from ~loc lexbuf =
let lexbuf = { lexbuf with Lexing.lex_start_p = to_lexing_loc loc } in
let lexbuf = { lexbuf with Lexing.lex_curr_p = to_lexing_loc loc } in
lexing_set_position lexbuf loc;
snd @@ parse Grammar.goal "" lexbuf

let goal ~loc ~text =
Expand All @@ -103,8 +110,7 @@ let goal ~loc ~text =

let program_from ~loc lexbuf =
Hashtbl.clear already_parsed;
let lexbuf = { lexbuf with Lexing.lex_start_p = to_lexing_loc loc } in
let lexbuf = { lexbuf with Lexing.lex_curr_p = to_lexing_loc loc } in
lexing_set_position lexbuf loc;
snd @@ parse Grammar.program "" lexbuf

let program ~file =
Expand Down

0 comments on commit 8df1ac4

Please sign in to comment.