1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
[comment {-*- text -*- doctools manpage}]
[manpage_begin pt_parser_api i 1]
[include include/module.inc]
[titledesc {Parser API}]
[description]
[include include/ref_intro.inc]
This document describes the API shared by the grammar interpreter
provided by the package [package pt::peg::interp] and the parsers
generated by the [cmd pt] application for the result formats
[const critcl], [const snit], and [const oo] regarding access
to the actual parsing functionality.
[para]
Its intended audience are people who wish to create a parser for some
language of theirs and then use that parser within a Tcl-based package
or application.
[para]
It resides in the User Layer of Parser Tools.
[para][image arch_user_pkg][para]
[section {Class API}]
[list_begin definitions]
[call [cmd className] [opt [arg objectName]]]
The class command constructs parser instances, i.e. objects. The
result of the command is the fully-qualified name of the instance
command.
[para]
If no [arg objectName] is specified the class will generate and use an
automatic name. If the [arg objectName] was specified, but is not
fully qualified the command will be created in the curent namespace.
[list_end]
[section {Instance API}]
All parser instances provide at least the methods shown below:
[list_begin definitions]
[include include/std_parser_object_api.inc]
[list_end]
[section Usage]
A generated parser is used like this
[example {
package require the-parser-package ;# Generated by result-formats 'critcl', 'snit' or 'oo' of 'pt'.
set parser [the-parser-class]
set ast [$parser parse $channel]
... process the abstract syntax tree ...
}]
When using a grammar interpreter for parsing some differences creep in
[example {
package require the-grammar-package ;# Generated by result-format 'container' of 'pt'.
set grammar [the-grammar-class]
package require pt::peg::interp
set parser [pt::peg::interp]
$parser use $grammar
set ast [$parser parse $channel]
$parser destroy
... process the abstract syntax tree ...
}]
[include include/serial/ast.inc]
[include include/serial/pexpression.inc]
[include include/feedback.inc]
[manpage_end]
|