This library provides facilities comparable maplist/3, ignore/1 and foreach/2 for DCGs.
STATUS: This library is experimental. The interface and
implementation may change based on feedback. Please send feedback to the
mailinglist or the issue page of the swipl-devel.git
repository.
//
?- phrase(sequence(digit, Digits), `123a`, L). Digits = "123", L = [97] ; Digits = [49, 50], L = [51, 97] ; ...
//
Element?, (Sep,Element)*
See also sequence//5.
//
Start, Element?, (Sep,Element)*, End
The example below matches a Prolog list of integers:
?- phrase(sequence(("[",blanks), number, (",",blanks), (blanks,"]"), L), `[1, 2, 3 ] a`, Tail). L = [1, 2, 3], Tail = [32, 97].
//
[]
for Default succeeds without any additional actions if Match
fails. For example:
?- phrase(optional(number(X), {X=0}), `23`, Tail). X = 23, Tail = []. ?- phrase(optional(number(X), {X=0}), `aap`, Tail). X = 0, Tail = `aap`.
//
//
?- phrase(foreach(between(1,5,X), number(X), ", "), L). L = "1, 2, 3, 4, 5".