Next: , Up: parsing   [Index]

10.1 Stream ideom api

There is a little framework in guile-log imported with (logic guile-log) that enables the setup of syntactic sugar for streams. The api is

SCM: (define-guile-log-parser-tool (lam (X ...)) def oo xx cc)

lam will be the name of the new lambda object that can be used to produce a matcher. X ... will be the name of the syntax parameters and also define the standard positions for them in call and return. def is the corresponding define. To do an actual match in guile-log with parser function call one need to use oo and when one issues a whole new expression we use xx. To return values from the matcher we use cc. The use of oo is twofold. First G.L (oo (v ...) (f a ..)), does a call in nontail possition. G.L (oo (f a ..)), does a call in tail position.

xx is used to capture the return of a subexpression like in the example below. It cannot be used to call parser funcitons.

10.1.1 Example

The parsing framwork is using

(define-guile-log-parser-tool (<p-lambda> (X XL N M)) <p-define> .. xx <p-cc>)

An example to use xx is,

(<p-define> (f c1)
  (xx (c2) (<or> (.. (g c1)) (.. (h c1))))
  (<p-cc> `(g-or-h ,c2)))

in practice one keeps the numbers of needed uses of all of the above framework by using functional combinators of matchers. But it is practical to just use this framework to e.g. define a c-parser.