Skip to main content

Module parser

Module parser 

Source
Expand description

Operator-precedence parser for ISO Prolog programs and queries.

Ported from patch-prolog’s parser.rs, split into focused submodules:

  • operators: the operator-name table DATA (token → atom name).
  • [term]: term / primary parsing and the precedence-climbing levels.
  • [clause]: clause parsing and :- ... directive handling.
  • [query]: program / query entry points and goal-list parsing.

Changes from v1: fnv::FnvHashMapstd::collections::HashMap, serde derives dropped, and Term/Clause/StringInterner/VarId/AtomId sourced from plg_shared.

Modules§

operators
Operator table DATA — token → operator-name mappings grouped by ISO precedence level, kept separate from the precedence-climbing logic in [super::term].

Structs§

CallSite
A source occurrence of an atom-functor term (name or name(...)), captured in parse_primary. This is a broad over-approximation of “call sites”: it records every such term regardless of position — goals, but also atoms as constants (X = foo), atoms inside data (p(foo, bar)), functors in operator specs (dynamic(foo/1) records dynamic, foo, and /), and [] as []/0. It never matches text in comments (those aren’t parsed). The LSP narrows this to real calls by intersecting with the lint’s undefined (name, arity) set, which keeps the false-positive surface small in practice.
CgClause
A clause as codegen consumes it: a plain head term plus body goals whose source spans survive lowering. (Provenance for the head is not needed — existence errors point at the call site, not the definition.)
Parser
Parser for Edinburgh Prolog syntax. Parses tokens into Terms and Clauses, with variable scoping per clause.
ProgramDirectives
Directives extracted from a program (:- dynamic(f/1). etc).