deeplog.grounding.prolog.parser
Plain-Prolog source text: parsed into program clauses, and rendered from symbols.
The head / body / functor splitting is generic and knows only plain Prolog; an
operator such as :: is read as the ordinary binary term it is.
Functions
|
Read the Prolog term |
|
Parse |
|
Parse one clause line |
|
Parse a single plain-Prolog clause line. |
|
Split source text into |
|
Parse a plain-Prolog program; clauses may share a line. |
|
Return the elements of the list |
|
Convert a Symbol to a valid Prolog term string using strict prefix notation. |
Module Contents
- parse_term(text: str) Symbol[source]
Read the Prolog term
text.A term is read around the first of
:-,?-,::,;and,outside brackets;,and;group to the right. Otherwise, text holding one of Prolog’s operators of priority 700 outside brackets is read around it:is, unification= \=, identity== \==, the standard order of terms@< @> @=< @>=and arithmetic comparison=:= =\= < > =< >=, soX + 1 =:= Y * 2is=:=(+(X, 1), *(Y, 2)). Text holding two of them is not. Otherwise, text made of operands joined by the arithmetic operators+ - * / // mod rem div ^ /\ \/ xor << >>is read with Prolog’s priorities and associativity:Z is (N1 + N2) mod 10isis(Z, mod(+(N1, N2), 10)). Any other text is read byparse_symbol(), with each argument read as a Prolog term.
- parse_atoms( ) Iterable[Symbol][source]
Parse
atoms_strsplit onsplit_strwithatom_parserper atom.atom_parserdefaults toparse_term(); an extension passes its own (e.g. one that peels ap ::label prefix) to reuse this splitting.
- parse_rule( ) RuleType[source]
Parse one clause line
h1 ; ... <functor> b1 , ...ending in..The head/body/functor splitting is generic;
atom_parserdecides how each atom is read, so extensions reuse this for their own surface syntax. Every_is a variable of its own, as in Prolog: it is named_1,_2, … with names the clause does not already use.
- iter_clauses(code: str) Iterable[str][source]
Split source text into
.-terminated clause strings.A period ends a clause only at bracket depth zero and when followed by whitespace or the end of the text, so floats (
0.8::a) and periods inside argument positions never split. Clauses may share a line or span several lines (newlines inside a clause are folded to spaces).#comment lines are skipped. A trailing fragment without its terminator is yielded as-is so the rule parser reports it instead of dropping it silently.
- str_to_rules(
- code: str,
Parse a plain-Prolog program; clauses may share a line.