Did you know ... Search Documentation:
Pack prolog_library_collection -- prolog/dcg.pl
PublicShow source
 add_indent(+Indent:positive_integer)//
 alpha*(-Codes:list(code), -Tail:list(code))//
 alpha+(-Codes:list(code), -Tail:list(code))//
 alphanum(?Code:code)//
 alphanum*(-Codes:list(code), -Tail:list(code))//
 alphanum+(-Codes:list(code), -Tail:list(code))//
 dcg_atom(:Dcg_1, ?Atom:atom)//
This meta-DCG rule handles the translation between the word and the character level of parsing/generating.

Typically, grammar A specifies how words can be formed out of characters. A character is a code, and a word is a list of codes. Grammar B specifies how sentences can be built out of words. Now the word is an atom, and the sentences in a list of atoms.

This means that at some point, words in grammar A, i.e. lists of codes, need to be translated to words in grammar B, i.e. atoms.

This is where dcg_atom//2 comes in. We illustrate this with a schematic example:

sentence([W1,...,Wn]) -->
  word2(W1),
  ...,
  word2(Wn).

word2(W) -->
  dcg_atom(word1, W).

word1([C1, ..., Cn]) -->
  char(C1),
  ...,
  char(Cn).
throws
- instantiation_error
- type_error
 dcg_atom_from_codes(:Dcg_1, ?Atom:atom)//
 dcg_between(+Low:nonneg, +High:nonneg)//
 dcg_between(+Low:nonneg, +High:nonneg, ?Code:nonneg)//
 dcg_boolean(+Boolean:boolean)// is det
dcg_boolean(-Boolean:boolean)// is det
 dcg_call(:Dcg_0)//
 dcg_call(:Dcg_1, ?Arg1)//
 dcg_call(:Dcg_2, ?Arg1, ?Arg2)//
 dcg_call(:Dcg_3, ?Arg1, ?Arg2, ?Arg3)//
 dcg_call(:Dcg_4, ?Arg1, ?Arg2, ?Arg3, ?Arg4)//
 dcg_call(:Dcg_5, ?Arg1, ?Arg2, ?Arg3, ?Arg4, ?Arg5)//
See also
- call/[1-8]
 dcg_peek(+Length:nonneg)//
 dcg_pp_boolean(+Boolean:boolean)// is det
 dcg_string(:Dcg_1, ?String)//
 dcg_string_from_codes(:Dcg_1, ?String:string)//
 dcg_with_output_to(:Dcg_0) is nondet
 dcg_with_output_to(+Sink, :Dcg_0) is nondet
 default(:Dcg_0, ?Default_0)//
 digit*(-Codes:list(code))//
 digit*(-Codes:list(code), -Tail:list(code))//
 digit+(-Codes:list(code))//
 digit+(-Codes:list(code), -Tail:list(code))//
 digit_weight(?Weight:between(0,9))//
 digit_weight*(-Weights:list(between(0,9)))// is det
 digit_weight+(-Weights:list(between(0,9)))// is det
 ellipsis(+Original:text, +MaxLength:beteen(2,inf))// is det
Arguments:
MaxLength- The maximum length of the generated ellipsed string.
 indent(+Indent:nonneg)// is det
 must_see(:Dcg_0)//
 must_see_code(+Code, :Skip_0)//
 nl// is det
 nonblank//
Wrapper around nonblank//1 from library(dcg/basics).
 nonblanks//
 parsing// is semidet
Succeeds if currently parsing a list of codes (rather than generating a list of codes).
 remainder_as_atom(-Atom:atom)// is det
 remainder_as_string(-Remainder:string)// is det
 string_phrase(:Dcg_0, ?String) is nondet
 string_phrase(:Dcg_0, +String1, ?String2) is nondet
 tab(+N:nonneg)// is det
 term(+Term)// is det
 thousands(+N:integer)// is det
 ws// is det
 ...//
 ...(-Codes:list(code))//
Wrapper around string//1.
 alpha//
 alpha(?Code:code)//

Undocumented predicates

The following predicates are exported, but not or incorrectly documented.

 ...(Arg1, Arg2)
 atom_phrase(Arg1, Arg2)
 atom_phrase(Arg1, Arg2, Arg3)
 dcg_between(Arg1, Arg2, Arg3, Arg4, Arg5)
 dcg_call(Arg1, Arg2, Arg3, Arg4)
 dcg_call(Arg1, Arg2, Arg3, Arg4, Arg5)
 dcg_call(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)
 dcg_call(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7)
 dcg_call(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8)
 dcg_char(Arg1, Arg2, Arg3)
 dcg_with_output_to(Arg1, Arg2)
 digit*(Arg1, Arg2, Arg3, Arg4)
 digit+(Arg1, Arg2, Arg3, Arg4)
 string_phrase(Arg1, Arg2, Arg3)
 white(Arg1, Arg2)
 whites(Arg1, Arg2)
 blank(Arg1, Arg2)
 blanks(Arg1, Arg2)
 nonblank(Arg1, Arg2, Arg3)
 nonblanks(Arg1, Arg2, Arg3)
 blanks_to_nl(Arg1, Arg2)
 string(Arg1, Arg2, Arg3)
 string_without(Arg1, Arg2, Arg3, Arg4)
 alpha_to_lower(Arg1, Arg2, Arg3)
 digits(Arg1, Arg2, Arg3)
 digit(Arg1, Arg2, Arg3)
 integer(Arg1, Arg2, Arg3)
 float(Arg1, Arg2, Arg3)
 number(Arg1, Arg2, Arg3)
 xdigits(Arg1, Arg2, Arg3)
 xdigit(Arg1, Arg2, Arg3)
 xinteger(Arg1, Arg2, Arg3)
 prolog_var_name(Arg1, Arg2, Arg3)
 eos(Arg1, Arg2)
 remainder(Arg1, Arg2, Arg3)
 atom(Arg1, Arg2, Arg3)