package coq-core
Install
Dune Dependency
Authors
Maintainers
Sources
md5=64b49dbc3205477bd7517642c0b9cbb6
sha512=02fb5b4fb575af79e092492cbec6dc0d15a1d74a07f827f657a72d4e6066532630e5a6d15be4acdb73314bd40b9a321f9ea0584e0ccfe51fd3a56353bd30db9b
doc/coq-core.parsing/CLexer/index.html
Module CLexer
Source
When one registers a keyword she can declare it starts a quotation. In particular using QUOTATION("name:") in a grammar rule declares "name:" as a keyword and the token QUOTATION is matched whenever the keyword is followed by an identifier or a parenthesized text. Eg
constr:x string:....
ltac:(....) ltac:....
The delimiter is made of 1 or more occurrences of the same parenthesis, eg ((.....)) or [[[....]]]
. The idea being that if the text happens to contain the closing delimiter, one can make the delimiter longer and avoid confusion (no escaping). Eg
string:[ .. ']' ..
]
Nesting the delimiter is allowed, eg ((..((...))..)) is OK.
Keywords don't need to end in ':'
When string is not an ident, returns a keyword.
Precondition: the input is a number (c.f. NumTok.t
)
after loc
Will advance a lexing location as the lexer does; this can be used to implement parsing resumption from a given position:
let loc = Pcoq.Parsable.loc pa |> after in
let str = Gramlib.Stream.of_string text in
(* Stream.count being correct is critical for Coq's lexer *)
Gramlib.Stream.njunk loc.ep str;
let pa = Pcoq.Parsable.make ~loc str in
(* ready to resume parsing *)
The lexer of Coq:
module Lexer :
Gramlib.Plexing.S
with type keyword_state = keyword_state
and type te = Tok.t
and type 'c pattern = 'c Tok.p
LexerDiff ensures that, ignoring white space, the concatenated tokens equal the input string. Specifically:
- for strings, return the enclosing quotes as tokens and treat the quoted value as if it was unquoted, possibly becoming multiple tokens.
- for comments, return the "(\*" (\ to be kind to syntax highlighters) as a token and treat the contents of the comment as if it was not in a comment, possibly becoming multiple tokens.
- return any unrecognized Ascii or UTF-8 character as a string.
module LexerDiff :
Gramlib.Plexing.S
with type keyword_state = keyword_state
and type te = Tok.t
and type 'c pattern = 'c Tok.p