This module contains predicates for working with DCGs defined over
sequences of character codes. Some of the predicates can only
be used to generate sequences, not parse them.
- writedcg(+P:phrase) is nondet
- Run the phrase P, which must be a standard list-of-codes DCG,
and print the output.
- phrase_string(+P:phrase, -S:string) is nondet
- phrase_string(+P:phrase, +S:string) is nondet
- Use list-of-codes DCG phrase P to parse or generate a string S.
- phrase_atom(+P:phrase, -A:atom) is nondet
- phrase_atom(+P:phrase, +A:atom) is nondet
- Use list-of-codes DCG phrase P to parse or generate a atom A.
- ctype(Type)// is nondet
- Matches a code C that satisfies
code_type(C,Type)
. See char_type/2
for listing of types.
- null// is det
- Empty string.
- cr// is det
- Carriage return "\n".
- sp// is det
- Space " ".
- fs// is det
- Full stop (period) ".".
- fssp// is det
- Full stop (period) followed by space.
- tb// is det
- Tab "\t".
- comma// is det
- Comma ",".
- commasp// is det
- Comma and space ", ".
- at(+X:atom)// is det
- Generate code list for textual representation of atom X.
- wr(+X:term)// is det
- Generate the list of codes for term X, as produced by write/1.
- str(+X:term)// is det
- Generate the list of codes for string X, as produced by writeq/1.
- fmt(+F:atom, +Args:list)// is det
- Generate list of codes using format/3.
- padint(+N:integer, +Range, +X:integer)// is det
- padint(+N:integer, +Range, -X:integer)// is nondet
- Write integer X padded with zeros ("0") to width N.
- brace(+P:phrase)// is nondet
- Generate "{" before and "}" after the phrase P.
- paren(+P:phrase)// is nondet
- Generate "(" before and ")" after the phrase P.
- sqbr(+P:phrase)// is nondet
- Generate "[" before and "]" after the phrase P.
- q(+P:phrase)// is nondet
- Generate list of codes from phrase P, surrounds it with single quotes,
and escapes (by doubling up) any internal quotes so that the
generated string is a valid quoted string. Must be list of codes DCG.
- qq(+P:phrase)// is nondet
- Generate list of codes from phrase P, surrounds it with double quotes,
and escapes (by doubling up) any double quotes so that the
generated string is a valid double quoted string.
- escape(+Q:C, +P:phrase)// is nondet
- Runs phrase P to generate a list of elements of type C and
then escapes any occurrences of Q by doubling them up, e.g.,
escape(39,"some 'text' here")
doubles up the single quotes
yielding "some ''text'' here"
.
- escape_with(+E:C, +Q:C, +P:phrase)// is nondet
- Runs phrase P to generate a list of elements of type C and
then escapes any occurrences of Q by prefixing them with E, e.g.,
escape_with(92,39,"some 'text' here")
escapes the single quotes
with backslashes, yielding "some \'text\' here"
.
- esc(+Esc:esc, +Codes:list(code))// is det
- esc(+Esc:esc, -Codes:list(code))// is nondet
- Parser for a sequence of characters involving escape sequences.
These are recognised by the predicate Esc, whose type is
esc == pred(list(codes),list(codes))//.
The DCG goal esc(H,T)
matches an escaped sequence in the string
and unifies H-T with a difference list representing it's internal
or semantic form. Esc must not place any constraints on the
difference list tail T.
Starts with the longest possible match and retrieves shorter
matches on backtracking.