Created
January 27, 2017 14:34
-
-
Save zoffixznet/055d00d0e2d76ec7445a16f33403d6fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use NQPHLL; | |
grammar Perl7::Grammar is HLL::Grammar { | |
token TOP { | |
:my $*CUR_BLOCK := QAST::Block.new(QAST::Stmts.new()); | |
<statementlist> | |
[ $ || <.panic('Perl 7 syntax error')> ] | |
} | |
token ws { <!ww> \h* || \h+ } | |
rule statementlist { [ <statement> "\n"+ ]* } | |
proto token statement {*} | |
token statement:sym<EXPR> { <EXPR> } | |
token statement:sym<💬> { | |
<.ws> <sym> <.ws> <EXPR> | |
} | |
token statement:sym<fuc> { | |
'fuc' \h+ <fucbody> | |
} | |
rule fucbody { | |
:my $*CUR_BLOCK := QAST::Block.new(QAST::Stmts.new()); | |
<ident> \n | |
<statementlist> | |
'ton' | |
} | |
proto token sign {*} | |
token sign:sym<−> { '−' } | |
token sign:sym<+> { '+'? } | |
proto token value {*} | |
token value:sym<string> { <?["']> <quote_EXPR: ':q'> } | |
token value:sym<integer> { <sign> $<num>=\d+ } | |
token value:sym<float> { <sign> $<num>=[\d+ '.' \d+] } | |
token term:sym<value> { <value> } | |
token term:sym<ident> { | |
:my $*MAYBE_DECL := 0; | |
<ident> | |
[ <?before \h* '=' [\w|\h+] { $*MAYBE_DECL := 1 }> || <?> ] | |
} | |
token term:sym<call> { | |
<!keyword> | |
<ident> '[' ']' | |
} | |
token keyword { | |
[ fuc | ton ] | |
<!ww> | |
} | |
my %multiplicative := nqp::hash('prec', 'u=', 'assoc', 'left' ); | |
my %additive := nqp::hash('prec', 't=', 'assoc', 'left' ); | |
my %assignment := nqp::hash('prec', 'j=', 'assoc', 'right'); | |
token infix:sym<×> { <sym> <O(|%multiplicative, :op<mul_n>)> } | |
token infix:sym<÷> { <sym> <O(|%multiplicative, :op<div_n>)> } | |
token infix:sym<+> { <sym> <O(|%additive, :op<add_n>)> } | |
token infix:sym<−> { <sym> <O(|%additive, :op<sub_n>)> } | |
token infix:sym<=> { <sym> <O(|%assignment, :op<bind> )> } | |
} | |
say(Perl7::Grammar.parse: "fuc greet\n 💬 'hi'\nton"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment