package coq-core

  1. Overview
  2. Docs
The Coq Proof Assistant -- Core Binaries and Tools

Install

Dune Dependency

Authors

Maintainers

Sources

coq-8.17.0.tar.gz
sha512=2f77bcb5211018b5d46320fd39fd34450eeb654aca44551b28bb50a2364398c4b34587630b6558db867ecfb63b246fd3e29dc2375f99967ff62bc002db9c3250

doc/coq-core.parsing/CLexer/index.html

Module CLexerSource

Sourcetype starts_quotation =
  1. | NoQuotation
  2. | Quotation

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 ':'

Sourceval add_keyword : ?quotation:starts_quotation -> string -> unit

This should be functional but it is not due to the interface

Sourceval is_keyword : string -> bool
Sourceval keywords : unit -> CString.Set.t
Sourcetype keyword_state
Sourceval set_keyword_state : keyword_state -> unit
Sourceval get_keyword_state : unit -> keyword_state
Sourceval check_ident : string -> unit
Sourceval is_ident : string -> bool
Sourceval check_keyword : string -> unit
Sourceval terminal : string -> string Tok.p

When string is not an ident, returns a keyword.

Sourceval terminal_number : string -> NumTok.Unsigned.t Tok.p

Precondition: the input is a number (c.f. NumTok.t)

Sourceval after : Loc.t -> Loc.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:

Sourcemodule Lexer : Gramlib.Plexing.S with type te = Tok.t and type 'c pattern = 'c Tok.p
Sourcemodule Error : sig ... end

Create a lexer. true enables alternate handling for computing diffs. It 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 "(*" 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
Sourcemodule LexerDiff : Gramlib.Plexing.S with type te = Tok.t and type 'c pattern = 'c Tok.p
OCaml

Innovation. Community. Security.