@@ -14,14 +14,38 @@ L<JSON::Simple module|https://github.com/moritz/json>, which can
14
14
deserialize any valid JSON file, and yet the deserializing code is
15
15
written in less than 100 lines of simple, extensible code.
16
16
17
+ = head1 Named Regexes
18
+
19
+ The main ingredients of grammars are named L < regexes|/language/regexes > .
20
+ These have a special syntax, similar to subroutine definitions:
21
+
22
+ = for code :allow<B>
23
+ my B < regex number { > \d+ [ \. \d+ ]? B < } >
24
+
25
+ In this case, we have to specify that the regex is lexically scoped
26
+ using the C < my > keyword, because named regexes are normally used within
27
+ grammars.
28
+
29
+ Being named gives us the advantage of being able to easily reuse the
30
+ regex elsewhere:
31
+
32
+ = begin code :allow<B>
33
+ say "32.51" ~~ B < &number > ;
34
+ say "15 + 4.5" ~~ /B << <number> >> \s* '+' \s*B << <number> >> /
35
+ = end code
36
+
37
+ TODO signatures
38
+
39
+ TODO tokens & rules
40
+
17
41
= head1 class Grammar
18
42
19
43
class Grammar is Cursor { }
20
44
21
45
C < Grammar > is the superclass that classes automatically get when they
22
46
are declared with the C < grammar > keyword instead of C < class > . Grammars
23
47
should only be used to parse text; if you wish to extract complex data,
24
- an L < action class|/language/grammars#Action classes > is recommended to
48
+ an L < action class|/language/grammars#Action_Classes > is recommended to
25
49
be used in conjunction with the grammar.
26
50
27
51
= begin code :allow<B L>
@@ -117,7 +141,7 @@ of the supplied string.
117
141
Parses the contents of the file C < $filename > with the L < parse > method,
118
142
passing along any named options in C < %opts > .
119
143
120
- = head1 Action classes
144
+ = head1 Action Classes
121
145
122
146
TODO
123
147
0 commit comments