[ << ] | [ < ] | [ 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-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 len
Get a copy of a substring of the last matching string. If the len 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-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 asthe-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-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 "()")) (the-string)))) (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 foo-bis
Note that RGC context are preserved across different uses of
read/rp
.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on March 31, 2014 using texi2html 5.0.