Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/rocq_elpi_vernacular_syntax.mlg
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ let lib_ref id =
++ str " (you may need to require some .v file with \
`Register ... as " ++ str id ++ str ".`).")

let lookahead_lib_colon kwstate strm =
match Gramlib.LStream.peek_nth kwstate 0 strm with
| Tok.IDENT "lib" ->
(match Gramlib.LStream.peek_nth kwstate 1 strm with
| Tok.KEYWORD ":" -> ()
| _ -> raise Gramlib.Stream.Failure)
| _ -> raise Gramlib.Stream.Failure
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use the lookahead combinators?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No special reason, I copied some code from SSR


[%%if coq = "8.18" || coq = "8.19" || coq = "8.20"]
let lookahead_lib_colon = Pcoq.Entry.(of_parser "lookahead_lib_colon" { parser_fun = lookahead_lib_colon })
[%%else]
let lookahead_lib_colon = Procq.Entry.(of_parser "lookahead_lib_colon" { parser_fun = lookahead_lib_colon })
[%%endif]
}
GRAMMAR EXTEND Gram
GLOBAL: term;
Expand All @@ -102,11 +115,11 @@ GRAMMAR EXTEND Gram
GLOBAL: term;

term: LEVEL "0"
[ [ "lib"; ":"; id = qualified_name -> {
[ [ lookahead_lib_colon;IDENT "lib"; ":"; id = qualified_name -> {
let ref = lib_ref id in
let path = Nametab.path_of_global ref in
CAst.make ~loc Constrexpr.(CRef (Libnames.qualid_of_path ~loc:(fst id) path,None)) }
| "lib"; ":"; "@"; id = qualified_name -> {
| lookahead_lib_colon;IDENT "lib"; ":"; "@"; id = qualified_name -> {
let ref = lib_ref id in
let path = Nametab.path_of_global ref in
let f = Libnames.qualid_of_path ~loc:(fst id) path in
Expand Down
6 changes: 6 additions & 0 deletions tests/test_lib.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Module lib.
Definition foo := I.
End lib.
Check lib.foo. (* works fine *)
Require Import elpi.elpi.
Check lib.foo.
Loading