summaryrefslogtreecommitdiffstats
path: root/tcllib/modules/pt/pt_pegrammar.man
blob: 36816b03b86f8fca50a128c19297195aeeddd9b1 (plain)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
[comment {-*- text -*- doctools manpage}]
[manpage_begin pt::peg n 1]
[include include/module.inc]
[titledesc {Parsing Expression Grammar Serialization}]
[require pt::peg [opt 1]]
[require pt::pe]
[description]
[include include/ref_intro.inc]

This package provides commands to work with the serializations of
parsing expression grammars as managed by the Parser Tools, and
specified in section [sectref {PEG serialization format}].

[para]

This is a supporting package in the Core Layer of Parser Tools.
[para][image arch_core_support][para]

[section API]

[list_begin definitions]

[call [cmd ::pt::peg] [method verify] \
	[arg serial] [opt [arg canonvar]]]

This command verifies that the content of [arg serial] is a valid
serialization of a parsing expression and will throw an error if that
is not the case. The result of the command is the empty string.

[para]

If the argument [arg canonvar] is specified it is interpreted as the
name of a variable in the calling context. This variable will be
written to if and only if [arg serial] is a valid regular
serialization. Its value will be a boolean, with [const True]
indicating that the serialization is not only valid, but also
[term canonical]. [const False] will be written for a valid, but
non-canonical serialization.

[para]

For the specification of serializations see the section
[sectref {PE serialization format}].

[call [cmd ::pt::peg] [method verify-as-canonical] \
	[arg serial]]

This command verifies that the content of [arg serial] is a valid
[term canonical] serialization of a PEG and will throw an error if
that is not the case. The result of the command is the empty string.

[para]

For the specification of canonical serializations see the section
[sectref {PEG serialization format}].

[call [cmd ::pt::peg] [method canonicalize] [arg serial]]

This command assumes that the content of [arg serial] is a valid
[term regular] serialization of a PEG and will throw an error if that
is not the case.

[para]

It will then convert the input into the [term canonical] serialization
of the contained PEG and return it as its result. If the input is
already canonical it will be returned unchanged.

[para]

For the specification of regular and canonical serializations see the
section [sectref {PEG serialization format}].

[call [cmd ::pt::peg] [method print] [arg serial]]

This command assumes that the argument [arg serial] contains a valid
serialization of a parsing expression and returns a string containing
that PE in a human readable form.

[para]

The exact format of this form is not specified and cannot be relied on
for parsing or other machine-based activities.

[para]

For the specification of serializations see the section
[sectref {PEG serialization format}].

[call [cmd ::pt::peg] [method merge] \
	[arg seriala] [arg serialb]]

This command accepts the regular serializations of two grammars and
uses them to create their union.  The result of the command is the
canonical serialization of this unified grammar.

[para]
A merge errors occurs if for any nonterminal symbol S occuring in both
input grammars the two input grammars specify different semantic
modes.

[para]
The semantic mode of each nonterminal symbol S is the semantic mode of
S in any of its input grammars. The previous rule made sure that for
symbols occuring in both grammars these values are identical.

[para]

The right-hand side of each nonterminal symbol S occuring in both
input grammars is the choice between the right-hand sides of S in the
input grammars, with the parsing expression of S in [arg seriala]
coming first, except if both expressions are identical. In that case
the first expression is taken.

[para]
The right-hand side of each nonterminal symbol S occuring in only one
of the input grammars is the right-hand side of S in its input
grammar.

[para]
The start expression of the unified grammar is the choice between the
start expressions of the input grammars, with the start expression of
[arg seriala] coming first, except if both expressions are identical.
In that case the first expression is taken

[call [cmd ::pt::peg] [method equal] \
	[arg seriala] [arg serialb]]

This command tests the two grammars [arg seriala] and [arg serialb]
for structural equality. The result of the command is a boolean
value. It will be set to [const true] if the expressions are
identical, and [const false] otherwise.

[para]

String equality is usable only if we can assume that the two grammars
are pure Tcl lists and dictionaries.

[list_end]

[include include/serial/pegrammar.inc]
[include include/serial/pexpression.inc]
[include include/feedback.inc]
[manpage_end]