Skip to content
Browse files

Perlito5 - parser: rewrite operator() in "perl5-land" for later tweaking

  • Loading branch information...
1 parent c0418d2 commit 61d64aa3567a31f891dd71151e057046bb71a9a0 @fglock committed
View
13 TODO-perlito5
@@ -34,7 +34,8 @@ TODO list for Perlito5
-- use an array to represent names that contain '::', because it is more flexible
--- implement signatures
+-- implement prototypes (signatures)
+--- *foo = sub () { ... } # does prototype work here?
-- check that \(@a) and \@a have different meanings
@@ -114,3 +115,13 @@ TODO list for Perlito5
-- source code - remove Perl 6 code such as "token"
(fixed: This is only loaded if the grammar compiler is needed)
+-- no warnings 'redefine';
+
+-- *{ $name }{CODE}->();
+
+-- $object->$method_name()
+
+-- local(*{$caller."::a"}) = \my $a;
+
+-- AUTOLOAD
+
View
251 html/perlito5.js
@@ -718,6 +718,24 @@ CORE.split = function(List__) {
make_sub("Perlito5::AST::Var", "name", function (List__) {
return ((List__[0] || (List__[0] = new HashRef({})))._hash_['name']);
});
+ make_sub("Perlito5::AST::Var", "plain_name", function (List__) {
+ try {
+ var v_self = null;
+ (v_self = NAMESPACE["Perlito5::AST::Var"].shift([List__]));
+ if ( bool(v_self._class_.namespace([v_self])) ) {
+ throw((string(v_self._class_.namespace([v_self])) + '::' + string(v_self._class_.name([v_self]))));
+ };
+ throw(v_self._class_.name([v_self]))
+ }
+ catch(err) {
+ if ( err instanceof Error ) {
+ throw(err);
+ }
+ else {
+ return(err);
+ }
+ }
+ });
make_package("Perlito5::AST::Proto");
make_sub("Perlito5::AST::Proto", "new", function (List__) {
var v_class = null;
@@ -3738,174 +3756,79 @@ CORE.split = function(List__) {
return (v_MATCH);
});
make_sub("Perlito5::Expression", "operator", function (List__) {
- var v_grammar = null;
- (v_grammar = List__[0]);
+ try {
+ var v_self = null;
+ (v_self = List__[0]);
var v_str = null;
(v_str = List__[1]);
var v_pos = null;
(v_pos = List__[2]);
- var v_MATCH = null;
- (v_MATCH = CLASS["Perlito5::Match"]._class_.new([CLASS["Perlito5::Match"],'str', v_str,'from', v_pos,'to', v_pos,'bool', 1]));
- ((v_MATCH || (v_MATCH = new HashRef({})))._hash_['bool'] = (((function () {
- var v_pos1 = null;
- (v_pos1 = (v_MATCH || (v_MATCH = new HashRef({})))._hash_['to']);
- return (or(((function () {
- return (and(((function () {
- var v_m2 = null;
- (v_m2 = CLASS["Perlito5::Precedence"]._class_.op_parse([CLASS["Perlito5::Precedence"],v_str,(v_MATCH || (v_MATCH = new HashRef({})))._hash_['to']]));
- if ( bool((v_m2 || (v_m2 = new HashRef({})))._hash_['bool']) ) {
- ((v_MATCH || (v_MATCH = new HashRef({})))._hash_['to'] = (v_m2 || (v_m2 = new HashRef({})))._hash_['to']);
- ((v_MATCH || (v_MATCH = new HashRef({})))._hash_['Perlito5::Precedence.op_parse'] = v_m2);
- return (1);
- }
-
- else {
- return (0);
- }
-})()), function () { return ((function () {
- ((v_MATCH || (v_MATCH = new HashRef({})))._hash_['capture'] = (v_MATCH || (v_MATCH = new HashRef({})))._hash_['Perlito5::Precedence.op_parse']._class_.flat([(v_MATCH || (v_MATCH = new HashRef({})))._hash_['Perlito5::Precedence.op_parse']]));
- return (1);
-})()); }));
-})()), function () { return ((function () {
- ((v_MATCH || (v_MATCH = new HashRef({})))._hash_['to'] = v_pos1);
- return ((and(and(((function () {
- var v_m2 = null;
- (v_m2 = CLASS["Perlito5::Grammar"]._class_.optional_namespace_before_ident([CLASS["Perlito5::Grammar"],v_str,(v_MATCH || (v_MATCH = new HashRef({})))._hash_['to']]));
- if ( bool((v_m2 || (v_m2 = new HashRef({})))._hash_['bool']) ) {
- ((v_MATCH || (v_MATCH = new HashRef({})))._hash_['to'] = (v_m2 || (v_m2 = new HashRef({})))._hash_['to']);
- ((v_MATCH || (v_MATCH = new HashRef({})))._hash_['Perlito5::Grammar.optional_namespace_before_ident'] = v_m2);
- return (1);
- }
-
- else {
- return (0);
- }
-})()), function () { return ((function () {
- var v_m2 = null;
- (v_m2 = CLASS["Perlito5::Grammar"]._class_.ident([CLASS["Perlito5::Grammar"],v_str,(v_MATCH || (v_MATCH = new HashRef({})))._hash_['to']]));
- if ( bool((v_m2 || (v_m2 = new HashRef({})))._hash_['bool']) ) {
- ((v_MATCH || (v_MATCH = new HashRef({})))._hash_['to'] = (v_m2 || (v_m2 = new HashRef({})))._hash_['to']);
- ((v_MATCH || (v_MATCH = new HashRef({})))._hash_['Perlito5::Grammar.ident'] = v_m2);
- return (1);
- }
-
- else {
- return (0);
- }
-})()); }), function () { return ((function () {
- var v_pos1 = null;
- (v_pos1 = (v_MATCH || (v_MATCH = new HashRef({})))._hash_['to']);
- return (or(or(or(((function () {
- return (and(((function () {
- var v_tmp = null;
- (v_tmp = v_MATCH);
- (v_MATCH = CLASS["Perlito5::Match"]._class_.new([CLASS["Perlito5::Match"],'str', v_str,'from', (v_tmp || (v_tmp = new HashRef({})))._hash_['to'],'to', (v_tmp || (v_tmp = new HashRef({})))._hash_['to'],'bool', 1]));
- ((v_MATCH || (v_MATCH = new HashRef({})))._hash_['bool'] = ((function () {
- var v_pos1 = null;
- (v_pos1 = (v_MATCH || (v_MATCH = new HashRef({})))._hash_['to']);
- return (((function () {
- return (and(((function () {
- var v_last_pos = null;
- (v_last_pos = (v_MATCH || (v_MATCH = new HashRef({})))._hash_['to']);
- if ( !( bool((function () {
- var v_m2 = null;
- (v_m2 = CLASS["Perlito5::Grammar"]._class_.ws([CLASS["Perlito5::Grammar"],v_str,(v_MATCH || (v_MATCH = new HashRef({})))._hash_['to']]));
- if ( bool((v_m2 || (v_m2 = new HashRef({})))._hash_['bool']) ) {
- ((v_MATCH || (v_MATCH = new HashRef({})))._hash_['to'] = (v_m2 || (v_m2 = new HashRef({})))._hash_['to']);
- return (1);
- }
-
- else {
- return (0);
- }
-})())) ) {
- ((v_MATCH || (v_MATCH = new HashRef({})))._hash_['to'] = v_last_pos);
- };
- return (1);
-})()), function () { return (and(('=>' == NAMESPACE["Perlito5::Expression"].substr([v_str, (v_MATCH || (v_MATCH = new HashRef({})))._hash_['to'], 2])), function () { return (((v_MATCH || (v_MATCH = new HashRef({})))._hash_['to'] = add(2, (v_MATCH || (v_MATCH = new HashRef({})))._hash_['to']))); })); }));
- })()));
- })()));
- ((v_tmp || (v_tmp = new HashRef({})))._hash_['bool'] = ( bool((v_MATCH || (v_MATCH = new HashRef({})))._hash_['bool']) ? 1 : 0));
- (v_MATCH = v_tmp);
- return (( bool((v_MATCH || (v_MATCH = new HashRef({})))._hash_['bool']) ? 1 : 0));
-})()), function () { return ((function () {
- var v_namespace = null;
- (v_namespace = (v_MATCH || (v_MATCH = new HashRef({})))._hash_['Perlito5::Grammar.optional_namespace_before_ident']._class_.flat([(v_MATCH || (v_MATCH = new HashRef({})))._hash_['Perlito5::Grammar.optional_namespace_before_ident']]));
- var v_name = null;
- (v_name = (v_MATCH || (v_MATCH = new HashRef({})))._hash_['Perlito5::Grammar.ident']._class_.flat([(v_MATCH || (v_MATCH = new HashRef({})))._hash_['Perlito5::Grammar.ident']]));
- if ( bool(v_namespace) ) {
- (v_name = (string(v_namespace) + '::' + string(v_name)));
- };
- ((v_MATCH || (v_MATCH = new HashRef({})))._hash_['capture'] = (new ArrayRef(interpolate_array('term', CLASS["Perlito5::AST::Val::Buf"]._class_.new([CLASS["Perlito5::AST::Val::Buf"],'buf', v_name])))));
- return (1);
-})()); }));
-})()), function () { return ((function () {
- ((v_MATCH || (v_MATCH = new HashRef({})))._hash_['to'] = v_pos1);
- return ((and(and(((function () {
- var v_m2 = null;
- (v_m2 = CLASS["Perlito5::Grammar"]._class_.ws([CLASS["Perlito5::Grammar"],v_str,(v_MATCH || (v_MATCH = new HashRef({})))._hash_['to']]));
- if ( bool((v_m2 || (v_m2 = new HashRef({})))._hash_['bool']) ) {
- ((v_MATCH || (v_MATCH = new HashRef({})))._hash_['to'] = (v_m2 || (v_m2 = new HashRef({})))._hash_['to']);
- return (1);
- }
-
- else {
- return (0);
- }
-})()), function () { return ((function () {
- var v_m2 = null;
- (v_m2 = v_grammar._class_.list_parse([v_grammar,v_str,(v_MATCH || (v_MATCH = new HashRef({})))._hash_['to']]));
- if ( bool((v_m2 || (v_m2 = new HashRef({})))._hash_['bool']) ) {
- ((v_MATCH || (v_MATCH = new HashRef({})))._hash_['to'] = (v_m2 || (v_m2 = new HashRef({})))._hash_['to']);
- ((v_MATCH || (v_MATCH = new HashRef({})))._hash_['list_parse'] = v_m2);
- return (1);
- }
-
- else {
- return (0);
- }
-})()); }), function () { return ((function () {
- ((v_MATCH || (v_MATCH = new HashRef({})))._hash_['capture'] = (new ArrayRef(interpolate_array('postfix_or_term', 'funcall', (v_MATCH || (v_MATCH = new HashRef({})))._hash_['Perlito5::Grammar.optional_namespace_before_ident']._class_.flat([(v_MATCH || (v_MATCH = new HashRef({})))._hash_['Perlito5::Grammar.optional_namespace_before_ident']]), (v_MATCH || (v_MATCH = new HashRef({})))._hash_['Perlito5::Grammar.ident']._class_.flat([(v_MATCH || (v_MATCH = new HashRef({})))._hash_['Perlito5::Grammar.ident']]), (v_MATCH || (v_MATCH = new HashRef({})))._hash_['list_parse']._class_.flat([(v_MATCH || (v_MATCH = new HashRef({})))._hash_['list_parse']])))));
- return (1);
-})()); })));
-})()); }), function () { return ((function () {
- ((v_MATCH || (v_MATCH = new HashRef({})))._hash_['to'] = v_pos1);
- return ((and(((function () {
- var v_tmp = null;
- (v_tmp = v_MATCH);
- (v_MATCH = CLASS["Perlito5::Match"]._class_.new([CLASS["Perlito5::Match"],'str', v_str,'from', (v_tmp || (v_tmp = new HashRef({})))._hash_['to'],'to', (v_tmp || (v_tmp = new HashRef({})))._hash_['to'],'bool', 1]));
- ((v_MATCH || (v_MATCH = new HashRef({})))._hash_['bool'] = ((function () {
- var v_pos1 = null;
- (v_pos1 = (v_MATCH || (v_MATCH = new HashRef({})))._hash_['to']);
- return (((function () {
- return (and(('->' == NAMESPACE["Perlito5::Expression"].substr([v_str, (v_MATCH || (v_MATCH = new HashRef({})))._hash_['to'], 2])), function () { return (((v_MATCH || (v_MATCH = new HashRef({})))._hash_['to'] = add(2, (v_MATCH || (v_MATCH = new HashRef({})))._hash_['to']))); }));
- })()));
- })()));
- ((v_tmp || (v_tmp = new HashRef({})))._hash_['bool'] = ( bool((v_MATCH || (v_MATCH = new HashRef({})))._hash_['bool']) ? 1 : 0));
- (v_MATCH = v_tmp);
- return (( bool((v_MATCH || (v_MATCH = new HashRef({})))._hash_['bool']) ? 1 : 0));
-})()), function () { return ((function () {
- var v_namespace = null;
- (v_namespace = (v_MATCH || (v_MATCH = new HashRef({})))._hash_['Perlito5::Grammar.optional_namespace_before_ident']._class_.flat([(v_MATCH || (v_MATCH = new HashRef({})))._hash_['Perlito5::Grammar.optional_namespace_before_ident']]));
- var v_name = null;
- (v_name = (v_MATCH || (v_MATCH = new HashRef({})))._hash_['Perlito5::Grammar.ident']._class_.flat([(v_MATCH || (v_MATCH = new HashRef({})))._hash_['Perlito5::Grammar.ident']]));
- if ( bool(v_namespace) ) {
- (v_name = (string(v_namespace) + '::' + string(v_name)));
- };
- ((v_MATCH || (v_MATCH = new HashRef({})))._hash_['capture'] = (new ArrayRef(interpolate_array('term', CLASS["Perlito5::AST::Proto"]._class_.new([CLASS["Perlito5::AST::Proto"],'name', v_name])))));
- return (1);
-})()); })));
-})()); }), function () { return ((function () {
- ((v_MATCH || (v_MATCH = new HashRef({})))._hash_['to'] = v_pos1);
- return ((((function () {
- ((v_MATCH || (v_MATCH = new HashRef({})))._hash_['capture'] = (new ArrayRef(interpolate_array('postfix_or_term', 'funcall_no_params', (v_MATCH || (v_MATCH = new HashRef({})))._hash_['Perlito5::Grammar.optional_namespace_before_ident']._class_.flat([(v_MATCH || (v_MATCH = new HashRef({})))._hash_['Perlito5::Grammar.optional_namespace_before_ident']]), (v_MATCH || (v_MATCH = new HashRef({})))._hash_['Perlito5::Grammar.ident']._class_.flat([(v_MATCH || (v_MATCH = new HashRef({})))._hash_['Perlito5::Grammar.ident']])))));
- return (1);
- })())));
-})()); }));
-})()); })));
-})()); }));
- })())));
- return (v_MATCH);
+ var v_p = null;
+ (v_p = v_pos);
+ var v_m = null;
+ (v_m = CLASS["Perlito5::Precedence"]._class_.op_parse([CLASS["Perlito5::Precedence"],v_str,v_p]));
+ if ( bool((v_m || (v_m = new HashRef({})))._hash_['bool']) ) {
+ throw(v_m);
+ };
+ var v_m_namespace = null;
+ (v_m_namespace = CLASS["Perlito5::Grammar"]._class_.optional_namespace_before_ident([CLASS["Perlito5::Grammar"],v_str,v_p]));
+ (v_p = (v_m_namespace || (v_m_namespace = new HashRef({})))._hash_['to']);
+ var v_m_name = null;
+ (v_m_name = CLASS["Perlito5::Grammar"]._class_.ident([CLASS["Perlito5::Grammar"],v_str,v_p]));
+ if ( bool((v_m_name || (v_m_name = new HashRef({})))._hash_['bool']) ) {
+ null;
+ }
+ else {
+ throw(v_m_name);
+ };
+ (v_p = (v_m_name || (v_m_name = new HashRef({})))._hash_['to']);
+ var v_name = null;
+ (v_name = v_m_name._class_.flat([v_m_name]));
+ var v_namespace = null;
+ (v_namespace = v_m_namespace._class_.flat([v_m_namespace]));
+ var v_full_name = null;
+ (v_full_name = v_name);
+ if ( bool(v_namespace) ) {
+ (v_full_name = (string(v_namespace) + '::' + string(v_name)));
+ };
+ var v_has_space_after = null;
+ (v_m = CLASS["Perlito5::Grammar"]._class_.ws([CLASS["Perlito5::Grammar"],v_str,v_p]));
+ if ( bool((v_m || (v_m = new HashRef({})))._hash_['bool']) ) {
+ (v_has_space_after = 1);
+ (v_p = (v_m || (v_m = new HashRef({})))._hash_['to']);
+ };
+ if ( (NAMESPACE["Perlito5::Expression"].substr([v_str, v_p, 2]) == '=>') ) {
+ ((v_m_name || (v_m_name = new HashRef({})))._hash_['capture'] = (new ArrayRef(interpolate_array('term', CLASS["Perlito5::AST::Val::Buf"]._class_.new([CLASS["Perlito5::AST::Val::Buf"],'buf', v_full_name])))));
+ ((v_m_name || (v_m_name = new HashRef({})))._hash_['to'] = v_p);
+ throw(v_m_name);
+ };
+ if ( (NAMESPACE["Perlito5::Expression"].substr([v_str, v_p, 2]) == '->') ) {
+ ((v_m_name || (v_m_name = new HashRef({})))._hash_['capture'] = (new ArrayRef(interpolate_array('term', CLASS["Perlito5::AST::Proto"]._class_.new([CLASS["Perlito5::AST::Proto"],'name', v_full_name])))));
+ ((v_m_name || (v_m_name = new HashRef({})))._hash_['to'] = v_p);
+ throw(v_m_name);
+ };
+ if ( bool(v_has_space_after) ) {
+ (function () {
+ var v_m_list = null;
+ (v_m_list = v_self._class_.list_parse([v_self,v_str,v_p]));
+ if ( bool((v_m_list || (v_m_list = new HashRef({})))._hash_['bool']) ) {
+ ((v_m_name || (v_m_name = new HashRef({})))._hash_['capture'] = (new ArrayRef(interpolate_array('postfix_or_term', 'funcall', v_namespace, v_name, v_m_list._class_.flat([v_m_list])))));
+ ((v_m_name || (v_m_name = new HashRef({})))._hash_['to'] = (v_m_list || (v_m_list = new HashRef({})))._hash_['to']);
+ throw(v_m_name);
+ };
+ })();
+ };
+ ((v_m_name || (v_m_name = new HashRef({})))._hash_['capture'] = (new ArrayRef(interpolate_array('postfix_or_term', 'funcall_no_params', v_namespace, v_name))));
+ throw(v_m_name)
+ }
+ catch(err) {
+ if ( err instanceof Error ) {
+ throw(err);
+ }
+ else {
+ return(err);
+ }
+ }
});
make_sub("Perlito5::Expression", "has_newline_after", function (List__) {
var v_grammar = null;
View
7 lib5/Perlito5/AST.pm
@@ -90,6 +90,13 @@ sub Perlito5::AST::Var::namespace {
sub Perlito5::AST::Var::name {
$_[0]->{'name'}
};
+sub Perlito5::AST::Var::plain_name {
+ ((my $self) = shift());
+ if (($self->namespace())) {
+ return (($self->namespace() . '::' . $self->name()))
+ };
+ return ($self->name())
+};
package Perlito5::AST::Proto;
sub Perlito5::AST::Proto::new {
((my $class) = shift());
View
11 lib5/Perlito5/Eval.pm
@@ -77,13 +77,6 @@ sub Perlito5::AST::Var::eval {
};
warn('Interpreter runtime error: variable ' . chr(39), $name, chr(39) . ' not found')
};
-sub Perlito5::AST::Var::plain_name {
- ((my $self) = $_[0]);
- if (($self->{'namespace'})) {
- return (($self->{'sigil'} . $self->{'namespace'} . '::' . $self->{'name'}))
- };
- return (($self->{'sigil'} . $self->{'name'}))
-};
package Perlito5::AST::Proto;
sub Perlito5::AST::Proto::eval {
((my $self) = $_[0]);
@@ -174,10 +167,6 @@ sub Perlito5::AST::Decl::eval {
};
return (undef())
};
-sub Perlito5::AST::Decl::plain_name {
- ((my $self) = $_[0]);
- $self->{'var'}->plain_name()
-};
package Perlito5::AST::Sub;
sub Perlito5::AST::Sub::eval {
((my $self) = $_[0]);
View
177 lib5/Perlito5/Expression.pm
@@ -913,147 +913,56 @@ sub Perlito5::Expression::term_space {
$MATCH
};
sub Perlito5::Expression::operator {
- ((my $grammar) = $_[0]);
+ ((my $self) = $_[0]);
((my $str) = $_[1]);
((my $pos) = $_[2]);
- ((my $MATCH) = Perlito5::Match->new(('str' => $str), ('from' => $pos), ('to' => $pos), ('bool' => 1)));
- ($MATCH->{'bool'} = (((do {
- ((my $pos1) = $MATCH->{'to'});
- (((do {
- (((do {
- ((my $m2) = Perlito5::Precedence->op_parse($str, $MATCH->{'to'}));
- if (($m2->{'bool'})) {
- ($MATCH->{'to'} = $m2->{'to'});
- ($MATCH->{'Perlito5::Precedence.op_parse'} = $m2);
- 1
- }
- else {
- 0
- }
-})) && ((do {
- ($MATCH->{'capture'} = $MATCH->{'Perlito5::Precedence.op_parse'}->flat());
- 1
-})))
-})) || ((do {
- ($MATCH->{'to'} = $pos1);
- (((((do {
- ((my $m2) = Perlito5::Grammar->optional_namespace_before_ident($str, $MATCH->{'to'}));
- if (($m2->{'bool'})) {
- ($MATCH->{'to'} = $m2->{'to'});
- ($MATCH->{'Perlito5::Grammar.optional_namespace_before_ident'} = $m2);
- 1
- }
- else {
- 0
- }
-})) && ((do {
- ((my $m2) = Perlito5::Grammar->ident($str, $MATCH->{'to'}));
- if (($m2->{'bool'})) {
- ($MATCH->{'to'} = $m2->{'to'});
- ($MATCH->{'Perlito5::Grammar.ident'} = $m2);
- 1
- }
- else {
- 0
- }
-}))) && ((do {
- ((my $pos1) = $MATCH->{'to'});
- (((((do {
- (((do {
- ((my $tmp) = $MATCH);
- ($MATCH = Perlito5::Match->new(('str' => $str), ('from' => $tmp->{'to'}), ('to' => $tmp->{'to'}), ('bool' => 1)));
- ($MATCH->{'bool'} = ((do {
- ((my $pos1) = $MATCH->{'to'});
- ((do {
- (((do {
- ((my $last_pos) = $MATCH->{'to'});
- if ((!(((do {
- ((my $m2) = Perlito5::Grammar->ws($str, $MATCH->{'to'}));
- if (($m2->{'bool'})) {
- ($MATCH->{'to'} = $m2->{'to'});
- 1
+ ((my $p) = $pos);
+ ((my $m) = Perlito5::Precedence->op_parse($str, $p));
+ if ($m->{'bool'}) {
+ return ($m)
+ };
+ ((my $m_namespace) = Perlito5::Grammar->optional_namespace_before_ident($str, $p));
+ ($p = $m_namespace->{'to'});
+ ((my $m_name) = Perlito5::Grammar->ident($str, $p));
+ if ($m_name->{'bool'}) {
+
}
else {
- 0
- }
-}))))) {
- ($MATCH->{'to'} = $last_pos)
+ return ($m_name)
};
- 1
-})) && ((('=>' eq substr($str, $MATCH->{'to'}, 2)) && (($MATCH->{'to'} = (2 + $MATCH->{'to'}))))))
-}))
-})));
- ($tmp->{'bool'} = ($MATCH->{'bool'} ? 1 : 0));
- ($MATCH = $tmp);
- ($MATCH->{'bool'} ? 1 : 0)
-})) && ((do {
- ((my $namespace) = $MATCH->{'Perlito5::Grammar.optional_namespace_before_ident'}->flat());
- ((my $name) = $MATCH->{'Perlito5::Grammar.ident'}->flat());
- if (($namespace)) {
- ($name = ($namespace . '::' . $name))
+ ($p = $m_name->{'to'});
+ ((my $name) = $m_name->flat());
+ ((my $namespace) = $m_namespace->flat());
+ ((my $full_name) = $name);
+ if ($namespace) {
+ ($full_name = ($namespace . '::' . $name))
};
- ($MATCH->{'capture'} = ['term', Perlito5::AST::Val::Buf->new(('buf' => $name))]);
- 1
-})))
-})) || ((do {
- ($MATCH->{'to'} = $pos1);
- (((((do {
- ((my $m2) = Perlito5::Grammar->ws($str, $MATCH->{'to'}));
- if (($m2->{'bool'})) {
- ($MATCH->{'to'} = $m2->{'to'});
- 1
- }
- else {
- 0
- }
-})) && ((do {
- ((my $m2) = $grammar->list_parse($str, $MATCH->{'to'}));
- if (($m2->{'bool'})) {
- ($MATCH->{'to'} = $m2->{'to'});
- ($MATCH->{'list_parse'} = $m2);
- 1
- }
- else {
- 0
- }
-}))) && ((do {
- ($MATCH->{'capture'} = ['postfix_or_term', 'funcall', $MATCH->{'Perlito5::Grammar.optional_namespace_before_ident'}->flat(), $MATCH->{'Perlito5::Grammar.ident'}->flat(), $MATCH->{'list_parse'}->flat()]);
- 1
-}))))
-}))) || ((do {
- ($MATCH->{'to'} = $pos1);
- ((((do {
- ((my $tmp) = $MATCH);
- ($MATCH = Perlito5::Match->new(('str' => $str), ('from' => $tmp->{'to'}), ('to' => $tmp->{'to'}), ('bool' => 1)));
- ($MATCH->{'bool'} = ((do {
- ((my $pos1) = $MATCH->{'to'});
- ((do {
- (('->' eq substr($str, $MATCH->{'to'}, 2)) && (($MATCH->{'to'} = (2 + $MATCH->{'to'}))))
-}))
-})));
- ($tmp->{'bool'} = ($MATCH->{'bool'} ? 1 : 0));
- ($MATCH = $tmp);
- ($MATCH->{'bool'} ? 1 : 0)
-})) && ((do {
- ((my $namespace) = $MATCH->{'Perlito5::Grammar.optional_namespace_before_ident'}->flat());
- ((my $name) = $MATCH->{'Perlito5::Grammar.ident'}->flat());
- if (($namespace)) {
- ($name = ($namespace . '::' . $name))
+ (my $has_space_after);
+ ($m = Perlito5::Grammar->ws($str, $p));
+ if (($m->{'bool'})) {
+ ($has_space_after = 1);
+ ($p = $m->{'to'})
};
- ($MATCH->{'capture'} = ['term', Perlito5::AST::Proto->new(('name' => $name))]);
- 1
-}))))
-}))) || ((do {
- ($MATCH->{'to'} = $pos1);
- (((do {
- ($MATCH->{'capture'} = ['postfix_or_term', 'funcall_no_params', $MATCH->{'Perlito5::Grammar.optional_namespace_before_ident'}->flat(), $MATCH->{'Perlito5::Grammar.ident'}->flat()]);
- 1
-})))
-})))
-}))))
-})))
-}))));
- $MATCH
+ if (((substr($str, $p, 2) eq '=>'))) {
+ ($m_name->{'capture'} = ['term', Perlito5::AST::Val::Buf->new(('buf' => $full_name))]);
+ ($m_name->{'to'} = $p);
+ return ($m_name)
+ };
+ if (((substr($str, $p, 2) eq '->'))) {
+ ($m_name->{'capture'} = ['term', Perlito5::AST::Proto->new(('name' => $full_name))]);
+ ($m_name->{'to'} = $p);
+ return ($m_name)
+ };
+ if (($has_space_after)) {
+ ((my $m_list) = $self->list_parse($str, $p));
+ if (($m_list->{'bool'})) {
+ ($m_name->{'capture'} = ['postfix_or_term', 'funcall', $namespace, $name, $m_list->flat()]);
+ ($m_name->{'to'} = $m_list->{'to'});
+ return ($m_name)
+ }
+ };
+ ($m_name->{'capture'} = ['postfix_or_term', 'funcall_no_params', $namespace, $name]);
+ return ($m_name)
};
sub Perlito5::Expression::has_newline_after {
((my $grammar) = $_[0]);
View
7 lib5/Perlito5/Perl5/Emitter.pm
@@ -162,13 +162,6 @@ package Perlito5::AST::Var;
($ns = ($self->{'namespace'} . '::'))
};
return ((Perlito5::Perl5::tab($level) . $self->{'sigil'} . $ns . $self->{'name'}))
- };
- sub Perlito5::AST::Var::plain_name {
- ((my $self) = $_[0]);
- if (($self->{'namespace'})) {
- return (($self->{'namespace'} . '::' . $self->{'name'}))
- };
- return ($self->{'name'})
}
});
package Perlito5::AST::Proto;
View
7 lib5/Perlito5/Perl6/Emitter.pm
@@ -286,13 +286,6 @@ package Perlito5::AST::Var;
($ns = ($self->{'namespace'} . '::'))
};
($ns . $self->{'sigil'} . $self->{'name'})
- };
- sub Perlito5::AST::Var::plain_name {
- ((my $self) = shift());
- if (($self->namespace())) {
- return (($self->namespace() . '::' . $self->name()))
- };
- return ($self->name())
}
});
package Perlito5::AST::Proto;
View
9 src5/lib/Perlito5/AST.pm
@@ -53,6 +53,15 @@ sub sigil { $_[0]->{'sigil'} }
sub namespace { $_[0]->{'namespace'} }
sub name { $_[0]->{'name'} }
+sub plain_name {
+ my $self = shift;
+ if ($self->namespace) {
+ return $self->namespace . '::' . $self->name
+ }
+ return $self->name
+}
+
+
package Perlito5::AST::Proto;
View
14 src5/lib/Perlito5/Eval.pm
@@ -87,15 +87,8 @@ sub eval {
}
}
warn "Interpreter runtime error: variable '", $name, "' not found";
-};
-sub plain_name {
- my $self = $_[0];
+}
- if ($self->{"namespace"}) {
- return $self->{"sigil"} . $self->{"namespace"} . '::' . $self->{"name"}
- }
- return $self->{"sigil"} . $self->{"name"}
-};
package Perlito5::AST::Proto;
@@ -208,11 +201,6 @@ sub eval {
}
return undef;
}
-sub plain_name {
- my $self = $_[0];
-
- $self->{"var"}->plain_name;
-}
package Perlito5::AST::Sub;
View
104 src5/lib/Perlito5/Expression.pm
@@ -487,41 +487,75 @@ package Perlito5::Expression;
<.Perlito5::Grammar.ws> { $MATCH->{"capture"} = [ 'space', ' ' ] }
}
- token operator {
- | <Perlito5::Precedence.op_parse> { $MATCH->{"capture"} = $MATCH->{"Perlito5::Precedence.op_parse"}->flat() }
-
- # other identifiers, barewords
- | <Perlito5::Grammar.optional_namespace_before_ident> <Perlito5::Grammar.ident>
-
- [
- <before <.Perlito5::Grammar.ws>? '=>' > # autoquote
- { my $namespace = $MATCH->{"Perlito5::Grammar.optional_namespace_before_ident"}->flat();
- my $name = $MATCH->{"Perlito5::Grammar.ident"}->flat();
- if ($namespace) {
- $name = $namespace . '::' . $name;
- }
- $MATCH->{"capture"} = [ 'term', Perlito5::AST::Val::Buf->new( buf => $name ) ]
- }
-
- | <.Perlito5::Grammar.ws> <list_parse>
- { $MATCH->{"capture"} = [ 'postfix_or_term', 'funcall',
- $MATCH->{"Perlito5::Grammar.optional_namespace_before_ident"}->flat(),
- $MATCH->{"Perlito5::Grammar.ident"}->flat(),
- $MATCH->{"list_parse"}->flat()
- ]
- }
- | <before '->' >
- { my $namespace = $MATCH->{"Perlito5::Grammar.optional_namespace_before_ident"}->flat();
- my $name = $MATCH->{"Perlito5::Grammar.ident"}->flat();
- if ($namespace) {
- $name = $namespace . '::' . $name;
- }
- $MATCH->{"capture"} = [ 'term', Perlito5::AST::Proto->new( name => $name ) ]
- }
- | { $MATCH->{"capture"} = [ 'postfix_or_term', 'funcall_no_params',
- $MATCH->{"Perlito5::Grammar.optional_namespace_before_ident"}->flat(),
- $MATCH->{"Perlito5::Grammar.ident"}->flat() ] }
- ]
+ sub operator {
+ my $self = $_[0];
+ my $str = $_[1];
+ my $pos = $_[2];
+
+ # maybe it's an operator or a term
+
+ my $p = $pos;
+ my $m = Perlito5::Precedence->op_parse( $str, $p );
+ return $m
+ if $m->{"bool"};
+
+ # it's not a known operator or term
+ # maybe it's a bareword
+
+ my $m_namespace = Perlito5::Grammar->optional_namespace_before_ident( $str, $p );
+ $p = $m_namespace->{"to"};
+ my $m_name = Perlito5::Grammar->ident( $str, $p );
+ return $m_name
+ unless $m_name->{"bool"};
+ $p = $m_name->{"to"};
+
+ my $name = $m_name->flat();
+ my $namespace = $m_namespace->flat();
+ my $full_name = $name;
+ $full_name = $namespace . '::' . $name if $namespace;
+
+ # we've got a bareword
+
+ my $has_space_after;
+ $m = Perlito5::Grammar->ws( $str, $p );
+ if ( $m->{"bool"} ) {
+ $has_space_after = 1;
+ $p = $m->{"to"};
+ }
+
+ if ( substr( $str, $p, 2 ) eq '=>' ) {
+ # autoquote
+ $m_name->{"capture"} = [ 'term', Perlito5::AST::Val::Buf->new( buf => $full_name ) ];
+ $m_name->{"to"} = $p;
+ return $m_name;
+ }
+ if ( substr( $str, $p, 2 ) eq '->' ) {
+ # class-method call
+ $m_name->{"capture"} = [ 'term', Perlito5::AST::Proto->new( name => $full_name ) ];
+ $m_name->{"to"} = $p;
+ return $m_name;
+ }
+
+ if ( $has_space_after ) {
+ # maybe it's a subroutine call
+ my $m_list = $self->list_parse( $str, $p );
+ if ( $m_list->{"bool"} ) {
+ $m_name->{"capture"} = [ 'postfix_or_term', 'funcall',
+ $namespace,
+ $name,
+ $m_list->flat()
+ ];
+ $m_name->{"to"} = $m_list->{"to"};
+ return $m_name;
+ }
+ }
+
+ # it's just a bareword - we will disambiguate later
+ $m_name->{"capture"} = [ 'postfix_or_term', 'funcall_no_params',
+ $namespace,
+ $name
+ ];
+ return $m_name;
}
token has_newline_after {
View
8 src5/lib/Perlito5/Perl5/Emitter.pm
@@ -218,14 +218,6 @@ package Perlito5::AST::Var;
}
return Perlito5::Perl5::tab($level) . $self->{"sigil"} . $ns . $self->{"name"}
}
- sub plain_name {
- my $self = $_[0];
-
- if ($self->{"namespace"}) {
- return $self->{"namespace"} . '::' . $self->{"name"}
- }
- return $self->{"name"}
- }
}
package Perlito5::AST::Proto;
View
7 src5/lib/Perlito5/Perl6/Emitter.pm
@@ -319,13 +319,6 @@ package Perlito5::AST::Var;
}
$ns . $self->{"sigil"} . $self->{"name"}
}
- sub plain_name {
- my $self = shift;
- if ($self->namespace) {
- return $self->namespace . '::' . $self->name
- }
- return $self->name
- }
}
package Perlito5::AST::Proto;

0 comments on commit 61d64aa

Please sign in to comment.
Something went wrong with that request. Please try again.