manpagez: man pages & more
info bigloo
Home | html | info | man
[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

11.3 The semantics actions

The semantics actions are regular Scheme expressions. These expressions appear in an environment where some “extra procedures” are defined. These procedures are:

bigloo rgc procedure: the-port

Returns the input port currently in used.

bigloo rgc procedure: the-length

Get the length of the biggest matching string.

bigloo rgc procedure: the-string

Get a copy of the last matching string. The function the-string returns a fresh copy of the matching each time it is called. In consequence,

(let ((l1 (the-string)) (l2 (the-string)))
   (eq? l1 l2))
   ⇒ #f
bigloo rgc procedure: the-substring start end

Get a copy of a substring of the last matching string. If the length is negative, it is subtracted to the whole match length. Here is an example of a rule extracting a part of a match:

(regular-grammar ()
   ((: #\" (* (out #\")) #\")
    (the-substring 1 (-fx (the-length) 1))))

Which can also be written:

(regular-grammar ()
   ((: #\" (* (out #\")) #\")
    (the-substring 1 -1)))
bigloo rgc procedure: the-character
bigloo rgc procedure: the-byte

Returns the first character of a match (respectively, the first byte).

bigloo rgc procedure: the-byte-ref n

Returns the n-th bytes of the matching string.

bigloo rgc procedure: the-symbol
bigloo rgc procedure: the-downcase-symbol
bigloo rgc procedure: the-upcase-symbol
bigloo rgc procedure: the-subsymbol start length

Convert the last matching string into a symbol. The function the-subsymbol obeys the same rules as the-substring.

bigloo rgc procedure: the-keyword
bigloo rgc procedure: the-downcase-keyword
bigloo rgc procedure: the-upcase-keyword

Convert the last matching string into a keyword.

bigloo rgc procedure: the-fixnum

The conversion of the last matching string to fixnum.

bigloo rgc procedure: the-flonum

The conversion of the last matching string to flonum.

bigloo rgc procedure: the-failure

Returns the first char that the grammar can’t match or the end of file object.

bigloo rgc procedure: ignore

Ignore the parsing, keep reading. It’s better to use (ignore) rather than an expression like (read/rp grammar port) in semantics actions since the (ignore) call will be done in a tail recursive way. For instance,

(let ((g (regular-grammar ()
             (let* ((car (ignore))
                    (cdr (ignore)))
                (cons car cdr)))
            ((+ (out "()"))
      (p (open-input-string "(foo(bar(gee)))")))
   (read/rp g p))
   ⇒ ("foo" ("bar" ("gee")))
bigloo rgc procedure: rgc-context [context]

If no context is provide, this procedure reset the reader context state. That is the reader is in no context. With one argument, context set the reader in the context context. For instance,

(let ((g (regular-grammar ()
            ((context foo "foo") (print 'foo-bis))
            ("foo" (rgc-context 'foo) (print 'foo) (ignore))
            (else 'done)))
      (p (open-input-string "foofoo")))
   (read/rp g p))
   -| foo

Note that RGC context are preserved across different uses of read/rp.

bigloo rgc procedure: the-context

Returns the value of the current Rgc context.

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on October 23, 2011 using texi2html 5.0.

© 2000-2018
Individual documents may contain additional copyright information.