@@ -1648,10 +1648,17 @@ grammar P6 is STD {
1648
1648
token scope_declarator :our { <sym > <scoped (' our' )> }
1649
1649
token scope_declarator :anon { <sym > <scoped (' anon' )> }
1650
1650
token scope_declarator :state { <sym > <scoped (' state' )> }
1651
- token scope_declarator :has { <sym > <scoped (' has' )> }
1652
1651
token scope_declarator :augment { <sym > <scoped (' augment' )> }
1653
1652
token scope_declarator :supersede { <sym > <scoped (' supersede' )> }
1654
-
1653
+ token scope_declarator :has {
1654
+ <sym > {
1655
+ given $ * PKGDECL {
1656
+ when ' class' | ' grammar' | ' role' {}
1657
+ default { $¢. worry(" 'has' declaration outside of class" ) }
1658
+ }
1659
+ }
1660
+ <scoped (' has' )>
1661
+ }
1655
1662
1656
1663
token package_declarator :class {
1657
1664
:my $ * PKGDECL ::= 'class' ;
@@ -1808,13 +1815,13 @@ grammar P6 is STD {
1808
1815
}
1809
1816
1810
1817
token routine_declarator :sub { <sym > <routine_def (' sub' )> }
1811
- token routine_declarator :method { <sym > <method_def > }
1812
- token routine_declarator :submethod { <sym > <method_def > }
1818
+ token routine_declarator :method { <sym > <method_def ( ' method ' ) > }
1819
+ token routine_declarator :submethod { <sym > <method_def ( ' submethod ' ) > }
1813
1820
token routine_declarator :macro { <sym > <macro_def > }
1814
1821
1815
- token regex_declarator :regex { <sym > <regex_def (:! r,:! s)> }
1816
- token regex_declarator :token { <sym > <regex_def (: r,:! s)> }
1817
- token regex_declarator :rule { <sym > <regex_def (: r,: s)> }
1822
+ token regex_declarator :regex { <sym > <regex_def (' regex ' , :! r,:! s)> }
1823
+ token regex_declarator :token { <sym > <regex_def (' token ' , : r,:! s)> }
1824
+ token regex_declarator :rule { <sym > <regex_def (' rule ' , : r,: s)> }
1818
1825
1819
1826
rule multisig {
1820
1827
:my $ signum = 0;
@@ -1863,10 +1870,16 @@ grammar P6 is STD {
1863
1870
] || <.panic : "Malformed routine" >
1864
1871
}
1865
1872
1866
- rule method_def () {
1873
+ rule method_def ($ d ) {
1867
1874
:temp $ * CURLEX ;
1868
- :my $ * IN_DECL = 'method' ;
1875
+ :my $ * IN_DECL = $ d ;
1869
1876
:my $ * DECLARAND ;
1877
+ {
1878
+ given $ * PKGDECL {
1879
+ when ' class' | ' grammar' | ' role' {}
1880
+ default {$¢. worry(" '$ d ' declaration outside of class" ) unless $ * SCOPE }
1881
+ }
1882
+ }
1870
1883
<.newlex (1 )>
1871
1884
[
1872
1885
[
@@ -1891,11 +1904,17 @@ grammar P6 is STD {
1891
1904
] || <.panic : "Malformed method" >
1892
1905
}
1893
1906
1894
- rule regex_def (: $ r , : $ s ) {
1907
+ rule regex_def ($ d , : $ r , : $ s ) {
1895
1908
:temp $ * CURLEX ;
1896
- :my $ * IN_DECL = 'regex' ;
1909
+ :my $ * IN_DECL = $ d ;
1897
1910
:temp % * RX ;
1898
1911
:my $ * DECLARAND ;
1912
+ {
1913
+ given $ * PKGDECL {
1914
+ when ' grammar' | ' role' {}
1915
+ default { $¢. worry(" '$ d ' declaration outside of grammar" ) unless $ * SCOPE }
1916
+ }
1917
+ }
1899
1918
{ % * RX <s > = $ s ; % * RX <r > = $ r ; }
1900
1919
[
1901
1920
[ '&' <deflongname >? | <deflongname > ]?
@@ -5832,6 +5851,18 @@ method check_variable ($variable) {
5832
5851
$ * CURLEX {$ name }<used >++ ;
5833
5852
}
5834
5853
}
5854
+ when ' !' {
5855
+ given $ * SCOPE {
5856
+ when ' method' | ' submethod' {}
5857
+ default { $ variable . worry(" Variable $ name used outside of method/submethod declaration" ); }
5858
+ }
5859
+ }
5860
+ when ' .' {
5861
+ given $ * SCOPE {
5862
+ when ' method' {}
5863
+ default { $ variable . worry(" Variable $ name used outside of method declaration" ); }
5864
+ }
5865
+ }
5835
5866
when ' ^' {
5836
5867
my $ * MULTINESS = ' multi' ;
5837
5868
$ variable . add_placeholder($ name );
0 commit comments