grammar NQP::Grammar is HLL::Grammar { my $sc_id := 0; method TOP() { # Language braid. my $*LANG := self; self.define_slang('MAIN', self, self.actions); self.define_slang('Regex', NQP::Regex, NQP::RegexActions); # Old language braids, going away. my %*LANG; %*LANG := NQP::Regex; %*LANG := NQP::RegexActions; %*LANG
:= NQP::Grammar; %*LANG := NQP::Actions; # Package declarator to meta-package mapping. Note that there is # one universal KnowHOW from the 6model core, and an attribute # meta-object to go with it. self.set_how('knowhow', nqp::knowhow()); self.set_how('knowhow-attr', nqp::knowhowattr()); # Serialization context builder - keeps track of objects that # cross the compile-time/run-time boundary that are associated # with this compilation unit. my $file := nqp::getlexdyn('$?FILES'); my $source_id := nqp::sha1(self.target()) ~ (%*COMPILING<%?OPTIONS> // '') ~ '-' ~ ~($sc_id++); my $*W := nqp::isnull($file) ?? NQP::World.new(:handle($source_id)) !! NQP::World.new(:handle($source_id), :description($file)); my $*SCOPE := ''; my $*MULTINESS := ''; my $*PKGDECL := ''; my $*INVOCANT_OK := 0; my $*RETURN_USED := 0; my $*CONTROL_USED := 0; my $*IN_REGEX_ASSERTION := 0; my %*HANDLERS; self.comp_unit; } ## Lexer stuff token identifier { <.ident> [ <[\-']> <.ident> ]* } token name { ['::']* } token deflongname { ? } token ENDSTMT { [ <.unv>? $$ <.ws> ]? } token ws { || || [ \v+ | <.comment> | ^^ <.pod_comment> | \h+ ]* } token unv { # :dba('horizontal whitespace') [ | ^^ <.pod_comment> | \h* <.comment> | \h+ ] } proto token comment {*} token comment:sym<#> { '#' {} \N* } token pod_comment { ^^ \h* '=' [ | 'begin' \h+ 'END' >> [ .*? \n \h* '=' 'end' \h+ 'END' » \N* || .* ] | 'begin' \h+ [ || .*? \n \h* '=' 'end' \h+ $ » \N* || <.panic: '=begin without matching =end'> ] | 'begin' » \h* [ $$ || '#' || <.panic: 'Unrecognized token after =begin'> ] [ || .*? \n \h* '=' 'end' » \N* || <.panic: '=begin without matching =end'> ] | {} .*? \n }/=cut), please use =begin/=end instead"> ]? | \n ]> | {} [ \s || <.panic: 'Illegal pod directive'> ] \N* ] } ## Top-level rules token comp_unit { :my $*IN_DECL := ''; :my $*HAS_YOU_ARE_HERE := 0; :my $*MAIN_SUB; :my $*UNIT := $*W.push_lexpad($/); # Create GLOBALish - the current GLOBAL view, created fresh # for each compilation unit so we get separate compilation. :my $*GLOBALish := $*W.pkg_create_mo(self.how('knowhow'), :name('GLOBALish')); { $*GLOBALish.HOW.compose($*GLOBALish); $*W.install_lexical_symbol($*UNIT, 'GLOBALish', $*GLOBALish); } # This is also the starting package. :my $*PACKAGE := $*GLOBALish; { $/.set_package($*PACKAGE); $*W.install_lexical_symbol($*UNIT, '$?PACKAGE', $*PACKAGE); } # Create EXPORT::DEFAULT. :my $*EXPORT; { unless %*COMPILING<%?OPTIONS> eq 'NULL' { $*EXPORT := $*W.pkg_create_mo(self.how('knowhow'), :name('EXPORT')); $*EXPORT.HOW.compose($*EXPORT); $*W.install_lexical_symbol($*UNIT, 'EXPORT', $*EXPORT); my $DEFAULT := $*W.pkg_create_mo(self.how('knowhow'), :name('DEFAULT')); $DEFAULT.HOW.compose($DEFAULT); ($*EXPORT.WHO) := $DEFAULT; } } { $*W.add_initializations(); } <.outerctx> <.set_braid_from(self)> <.check_PACKAGE_oopsies('comp_unit')> [ $ || <.panic: 'Confused'> ] } rule statementlist { :my $*LANG := self; '' [ | $ | > | [ <.eat_terminator> ]* ] } token label { ':' <.ws> { $*LABEL := ~$; my $label := $*W.find_sym(['NQPLabel']).new(); $*W.add_object($label); $*W.install_lexical_symbol($*W.cur_lexpad(), $*LABEL, $label); } } token statement($*LABEL = '') { | $ > [ |