Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Syntax Tweaks

  • Loading branch information...
commit 041b2cf9e1300075f13424e523a03c59e85b0d1c 1 parent f325f72
Brian Gernhardt authored
Showing with 31 additions and 19 deletions.
  1. +19 −9 cish/src/cish/Actions.pm
  2. +12 −10 cish/src/cish/Grammar.pm
28 cish/src/cish/Actions.pm
View
@@ -1,26 +1,36 @@
class cish::Actions is HLL::Actions;
-method TOP($/) {
- make PAST::Block.new( $<statementlist>.ast , :hll<cish>, :node($/) );
+sub past_block($/, @statements) {
+ my $past := PAST::Block.new( $past, :blocktype<immediate>, :node($/) );
+ for @statements { $past.push( $_.ast ); }
+ return $past;
}
-method statementlist($/) {
- my $past := PAST::Stmts.new( :node($/) );
- for $<statement> { $past.push( $_.ast ); }
- make $past;
+method TOP($/) {
+ my $past := past_block($/, $<statement>);
+ $past.hll('cish');
+ make $past;
}
method statement($/) {
- make $<statement_control> ?? $<statement_control>.ast !! $<EXPR>.ast;
+ make $<simple>.ast;
+}
+
+method simple($/) {
+ if $<builtin> {
+ make $<builtin>.ast
+ } else {
+ make $<EXPR>.ast
+ }
}
-method statement_control:sym<say>($/) {
+method builtin:sym<say>($/) {
my $past := PAST::Op.new( :name<say>, :pasttype<call>, :node($/) );
for $<EXPR> { $past.push( $_.ast ); }
make $past;
}
-method statement_control:sym<print>($/) {
+method builtin:sym<print>($/) {
my $past := PAST::Op.new( :name<print>, :pasttype<call>, :node($/) );
for $<EXPR> { $past.push( $_.ast ); }
make $past;
22 cish/src/cish/Grammar.pm
View
@@ -7,30 +7,32 @@ This is the grammar for cish in Perl 6 rules.
grammar cish::Grammar is HLL::Grammar;
token TOP {
- <statementlist>
+ <statement>*
[ $ || <.panic: "Syntax error"> ]
}
## Lexer items
-# This <ws> rule treats # as "comment to eol".
+# This <ws> rule treats /* this as a comment */
token ws {
<!ww>
- [ '#' \N* \n? | \s+ ]*
+ [ '/*' .*? '*/' | \s+ ]*
}
## Statements
-rule statementlist { [ <statement> | <?> ] ** ';' }
-
rule statement {
- | <statement_control>
- | <EXPR>
+ <simple> ';'
+}
+
+rule simple {
+ | <builtin>
+ | <EXPR>
}
-proto token statement_control { <...> }
-rule statement_control:sym<say> { <sym> [ <EXPR> ] ** ',' }
-rule statement_control:sym<print> { <sym> [ <EXPR> ] ** ',' }
+proto token builtin { <...> }
+rule builtin:sym<say> { <sym> [ <EXPR> ] ** ',' }
+rule builtin:sym<print> { <sym> [ <EXPR> ] ** ',' }
## Terms
Please sign in to comment.
Something went wrong with that request. Please try again.