@@ -11,12 +11,17 @@ heading
11
11
fmt.Println("Hello from Go")
12
12
= end code
13
13
14
+ = begin DESCRIPTION
15
+ Some description
16
+ = item one item
17
+ = end DESCRIPTION
18
+
14
19
= for defn :numbered
15
20
We
16
21
Need
17
22
Numbers
18
23
19
- = end pod
24
+ = end pod
20
25
21
26
say $ = pod [0 ]. config<numbered >;
22
27
@@ -43,7 +48,7 @@ multi sub fib (\n where * > 1) {
43
48
say fib 10 ;
44
49
# OUTPUT: 55
45
50
46
- # | C< Shape> role
51
+ # | B<A C<<uh U< Shape> umm>> role>
47
52
role Shape {
48
53
method area { ... }
49
54
@@ -129,6 +134,82 @@ key2 = value2
129
134
key3=value3
130
135
END
131
136
137
+ grammar Nested {
138
+ token TOP { <block > <section >* { if $/ { say $/ } } }
139
+ token block {
140
+ <? before <.[ \)\] \} ] >>
141
+ }
142
+
143
+ token you_are_here {
144
+ <?{ nqp ::getlexdyn(' $?FILES' ) ~~ /\. setting$ / }> ||
145
+ \w + 'some text' \d +
146
+ { self . typed_panic(' X::Syntax::Reserved' ,
147
+ reserved => ' use of {YOU_ARE_HERE} outside of a setting' ,
148
+ instead => ' (use whitespace if not a setting, or rename file with .setting extension?)' );
149
+ }
150
+ }
151
+
152
+ rule statement_control :sym <if > {
153
+ $ < sym > =[if| with]<.kok > { }
154
+ <xblock (~ $ < sym > [0 ] ~~ /with / ?? $ PBLOCK_REQUIRED_TOPIC !! $ PBLOCK_NO_TOPIC )>
155
+ [
156
+ [
157
+ | 'else' \h * 'if' <.typed_panic : 'X::Syntax::Malformed::Elsif' >
158
+ | 'elif' { $/ . typed_panic(' X::Syntax::Malformed::Elsif' , what => " elif" ) }
159
+ | $ < sym > ='elsif' <xblock >
160
+ | $ < sym > ='orwith' <xblock ($ PBLOCK_REQUIRED_TOPIC )>
161
+ ]
162
+ ]*
163
+ { }
164
+ [
165
+ 'else'
166
+ <else = .pblock (~ $ < sym > [-1 ] ~~ /with / ?? $ PBLOCK_REQUIRED_TOPIC !! $ PBLOCK_NO_TOPIC )>
167
+ ]?
168
+ }
169
+
170
+ token special_variable :sym <$ \\> {
171
+ '$\\' <? before \s | ',' | '=' | <.terminator > >
172
+ <.obsvar (' $\\ ' )>
173
+ }
174
+
175
+ token type_declarator :sym <enum > {
176
+ :my % * MYSTERY ;
177
+ [ <?[ <(« ] > <term > <.ws > || <.panic : 'An enum must supply an expression using <>, «», or ()' > ]
178
+ <.explain_mystery > <.cry_sorrows >
179
+ <?{
180
+ elsif ! ($ text ~~ /^ (\w | \:)+ $ /) {
181
+ $/ . obs($ bad , " $ sigil \($ text ) for hard ref or $ sigil \::($ text ) for symbolic ref" );
182
+ }
183
+ }>
184
+ }
185
+
186
+ token rad_number {
187
+ :my $ rad_digits := token rad_digits { <rad_digit >+ [ _ <rad_digit >+ ]* } ;
188
+ <O (| % methodcall )>
189
+ <O = .revO ($ < infixish > )>
190
+ <code = [ A..Z ] >
191
+ }
192
+
193
+ token pod_balanced_braces {
194
+ <?{ nqp :: chars ($ < start > ) == $ * POD_ANGLE_COUNT || $ * POD_ANGLE_COUNT < 0 } >
195
+ }
196
+
197
+ token routine_declarator :sym <macro > {
198
+ :my $ * LINE_NO := HLL::Compiler . lineof(self. orig(), self. from(), :cache (1));
199
+ <!!{ nqp ::rebless ($/ , self . slang_grammar(' MAIN' )); 1 }>
200
+ <sym > <.end_keyword > <macro_def ()>
201
+ }
202
+
203
+ token routine_declarator :sym <macro > {
204
+ :my $ * LINE_NO := HLL::Compiler . lineof(self. orig(), self. from(), :cache (1));
205
+ <sym > <.end_keyword > <macro_def ()>
206
+ }
207
+
208
+ token integer {
209
+ <!! before ['.' <? before \s | ',' | '=' | ':' <! before <coloncircumfix <OPER = prefix > > > | <.terminator > | $ > <.typed_sorry : 'X::Syntax::Number::IllegalDecimal' >]? >
210
+ [ <? before '_' '_' + \d > <.sorry : "Only isolated underscores are allowed inside numbers" > ]?
211
+ }
212
+ }
132
213
133
214
say $ match <block ><pair >[0 ]<value >;
134
215
# OUTPUT: 「value1」
@@ -237,6 +318,8 @@ rx/:i
237
318
238
319
<? before <.[\)\]\}] >>
239
320
321
+ \/
322
+
240
323
$ < string > = ( [ $ < part > = [abc] ]* % ' -' )
241
324
$ < variable > = \w+ ' =' $ < value > = \w+
242
325
a <( b ) > c
@@ -316,6 +399,9 @@ say Q:b[Testing];
316
399
" some $ variable :some('adverb').method() testing" ;
317
400
" some func() testing" ;
318
401
" some func:some<adverb>() testing" ;
402
+ " some & func() testing" ;
403
+ " some & func($ test ) testing" ;
404
+ " some & func :some<adverb>() testing" ;
319
405
say " Something foo(2) $ a. succ (2 + 3, $ some_variable ) $ a. some-method () @ more $ _. Str (2 ) $ _ : { $ _ * 2 } " ;
320
406
321
407
#`[[
@@ -384,7 +470,6 @@ for <a b c> {
384
470
# |[[
385
471
multiline pod declaration]
386
472
]]
387
-
388
473
grammar Calculator {
389
474
token TOP { <calc - op > }
390
475
0 commit comments