Next: guile-tools lint, Previous: guile-tools h2doc, Up: Miscellaneous Tools
Usage: lexer-repl [--emacs] [--offset N] input spec
lexer-repl provides a read-eval-print loop specialized for lexical
analysis of the INPUT file using a grammar specified in the SPEC
file. The SPEC file is regular Guile scheme code that also defines a
grammar, and calls `set-LEXER-SPEC!' with it.
The INPUT file should be in a format that can be analyzed using the
spec (otherwise you may see many errors!). Option "--emacs" means
don't show a prompt but instead echo the input in a way suitable for
feeding to Emacs' `read' function. Option "--offset N" means to
ignore the first N characters.
Usage from a Scheme program:
(lexer-repl under-emacs? lexer inp)
If UNDER-EMACS? is non-#f, lexer-repl does not display a prompt,
but instead displays, after input, a "pseudo-prompt" followed by
the input, designed to be comment-like (transparent) to the `read'
function in emacs. LEXER is a lexical analyzer conforming to that
returned by `make-lexer' in module (lang lex). INP is an input
port conforming to that returned by `make-line-buffering-input-port'
in module (ice-9 lineio). This port is used to read the INPUT file,
and should not be confused w/ current-input-port, from which commands
are read.
Commands:
(next) --- Display the next lexeme to stdout followed by newline.
Lexemes have the form: (LENGTH NAME MATCHED-INPUT)
where NAME is a symbol, MATCHED-INPUT is a string and
LENGTH is the count of characters in the string. The
spec file may arrange to omit MATCHED-INPUT by using
a "procedure action". For example, given the rules:
("<<" double-less-than)
("--" ,(lambda ignored 'double-dash))
(">>" ,(lambda ignored '(double-greater)))
and given input ">>--<<", lexer-repl displays:
(2 double-greater)
(2 . double-dash)
(2 double-less-than "<<")
on three subsequent invocations of the `(next)' command.
(quit) --- Quit the repl.
TODO:
- Add "--stop N" option.
- Add commands to examine/reset stats.