@@ -65,21 +65,8 @@ grammar Rubyish::Grammar is HLL::Grammar {
65
65
|| <.panic (' Syntax error' )>
66
66
}
67
67
68
- token continuation { \\ \n }
69
68
rule separator { ';' | \n <! after continuation> }
70
- token template-chunk { [<tmpl - unesc >| <tmpl - hdr >] ~ [<tmpl - esc >| $ ] <template - nibble >* }
71
- proto token template-nibble {* }
72
- token template-nibble :sym <interp > { <interp > }
73
- token template-nibble :sym <stray-tag > { [<.tmpl - unesc >| <.tmpl - hdr >] <.panic (" Stray tag, e.g. '%>' or '<?rbi?>'" )> }
74
- token template-nibble :sym <literal > { [<! before [<tmpl - esc >| '#{' | $ ]> . ]+ }
75
-
76
- token tmpl-hdr {'<?rbi?>' \h * \n ? { $ * IN_TEMPLATE := 1 } }
77
- token tmpl-esc {\h * '<%'
78
- [<?{ $ * IN_TEMPLATE }> || <.panic (' Template directive precedes "<?rbi?>"' )>]
79
- }
80
- token tmpl-unesc { '%>' \h * \n ?
81
- [<?{ $ * IN_TEMPLATE }> || <.panic (' Template directive precedes "<?rbi?>"' )>]
82
- }
69
+ token continuation { \\ \n }
83
70
84
71
rule stmtlist {
85
72
[ <stmt = .stmtish >? ] *%% [<.separator >| <stmt = .template - chunk >]
@@ -282,12 +269,6 @@ grammar Rubyish::Grammar is HLL::Grammar {
282
269
] <!ww >
283
270
}
284
271
285
- proto token comment {* }
286
- token comment :sym <line > { '#' [<?{ ! $ * IN_TEMPLATE }> \N * || [<! before <tmpl - unesc >>\N ]* ] }
287
- token comment :sym <podish > {[^^ '=begin' \n ] [ .*? [^^ '=end' [\n | $ ]] || <.panic (' missing ^^=end at eof' )>] }
288
- token ws { <!ww > [\h | <.continuation > | <.comment > | <?{ $ * IN_PARENS }> \n ]* }
289
- token hs { <!ww > [\h | <.continuation > ]* }
290
-
291
272
INIT {
292
273
# Operator precedence levels
293
274
# see http://www.tutorialspoint.com/ruby/ruby_operators.htm
@@ -440,6 +421,29 @@ grammar Rubyish::Grammar is HLL::Grammar {
440
421
]
441
422
}
442
423
424
+ # Comments and whitespace
425
+ proto token comment {* }
426
+ token comment :sym <line > { '#' [<?{ ! $ * IN_TEMPLATE }> \N * || [<! before <tmpl - unesc >>\N ]* ] }
427
+ token comment :sym <podish > {[^^ '=begin' \n ] [ .*? [^^ '=end' [\n | $ ]] || <.panic (' missing ^^=end at eof' )>] }
428
+ token ws { <!ww > [\h | <.continuation > | <.comment > | <?{ $ * IN_PARENS }> \n ]* }
429
+ token hs { <!ww > [\h | <.continuation > ]* }
430
+
431
+ # Templates
432
+ token template-chunk { [<tmpl - unesc >| <tmpl - hdr >] ~ [<tmpl - esc >| $ ] <template - nibble >* }
433
+ proto token template-nibble {* }
434
+ token template-nibble :sym <interp > { <interp > }
435
+ token template-nibble :sym <stray-tag > { [<.tmpl - unesc >| <.tmpl - hdr >] <.panic (" Stray tag, e.g. '%>' or '<?rbi?>'" )> }
436
+ token template-nibble :sym <literal > { [<! before [<tmpl - esc >| '#{' | $ ]> . ]+ }
437
+
438
+ token tmpl-hdr {'<?rbi?>' \h * \n ? { $ * IN_TEMPLATE := 1 } }
439
+ token tmpl-esc {\h * '<%'
440
+ [<?{ $ * IN_TEMPLATE }> || <.panic (' Template directive precedes "<?rbi?>"' )>]
441
+ }
442
+ token tmpl-unesc { '%>' \h * \n ?
443
+ [<?{ $ * IN_TEMPLATE }> || <.panic (' Template directive precedes "<?rbi?>"' )>]
444
+ }
445
+
446
+ # Builtin functions
443
447
method builtin-init () {
444
448
nqp ::hash(
445
449
' abort' , ' die' ,
@@ -470,22 +474,6 @@ class Rubyish::Actions is HLL::Actions {
470
474
make $ stmts ;
471
475
}
472
476
473
- method template-chunk ($/ ) {
474
- my $ text := QAST ::Stmts. new ( : node($/ ) );
475
- $ text . push ( QAST ::Op. new ( : op<print >, $ _ . ast ) )
476
- for $ < template-nibble > ;
477
-
478
- make $ text ;
479
- }
480
-
481
- method template-nibble :sym <interp >($/ ) {
482
- make $ < interp > . ast
483
- }
484
-
485
- method template-nibble :sym <literal >($/ ) {
486
- make QAST ::SVal. new ( : value(~ $/ ) );
487
- }
488
-
489
477
method stmtish ($/ ) {
490
478
make $ < modifier >
491
479
?? QAST ::Op. new ( $ < EXPR > . ast, $ < stmt > . ast,
@@ -634,7 +622,7 @@ class Rubyish::Actions is HLL::Actions {
634
622
my $ sigil := ~ $ < sigil > // ' ' ;
635
623
my $ name := $ sigil ~ $ < ident > ;
636
624
637
- my $ ns := ' ' ;
625
+ my $ ns ;
638
626
if $ < pkg > {
639
627
$ ns := ~ $ < pkg > ;
640
628
}
@@ -991,6 +979,22 @@ class Rubyish::Actions is HLL::Actions {
991
979
992
980
method term :sym <lambda >($/ ) { make $ < closure > . ast }
993
981
982
+ method template-chunk ($/ ) {
983
+ my $ text := QAST ::Stmts. new ( : node($/ ) );
984
+ $ text . push ( QAST ::Op. new ( : op<print >, $ _ . ast ) )
985
+ for $ < template-nibble > ;
986
+
987
+ make $ text ;
988
+ }
989
+
990
+ method template-nibble :sym <interp >($/ ) {
991
+ make $ < interp > . ast
992
+ }
993
+
994
+ method template-nibble :sym <literal >($/ ) {
995
+ make QAST ::SVal. new ( : value(~ $/ ) );
996
+ }
997
+
994
998
}
995
999
996
1000
class Rubyish::Compiler is HLL::Compiler {
0 commit comments