Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Perlito5 - parser: optimize Match calls

  • Loading branch information...
commit cdf577f6a664da3e75c37e69b03ab2931439ee4d 1 parent 9f4fec0
Flavio S. Glock authored
16 html/perlito5.js
View
@@ -5265,11 +5265,11 @@ var p5100 = p5pkg['main'];
var v_res = null;
(v_res = (p5call(v_prec, "precedence_parse", [], 0)));
if ( (p5num(p5129.scalar([(v_res || (v_res = new p5ArrayRef([])))._array_], 0)) == 0) ) {
- throw(p5context([p5call(p5pkg["Perlito5::Match"], "new", p5list_to_a('str', v_str, 'from', v_pos, 'to', v_last_pos, 'capture', (new p5HashRef(p5a_to_h(p5list_to_a('exp', '*undef*', 'terminated', null))))), p5want)], p5want));
+ throw(p5context([(new p5HashRef(p5a_to_h(p5list_to_a('str', v_str, 'from', v_pos, 'to', v_last_pos, 'capture', (new p5HashRef(p5a_to_h(p5list_to_a('exp', '*undef*', 'terminated', null))))))))], p5want));
};
var v_result = null;
(v_result = (p5129.pop_term(p5list_to_a(v_res), 0)));
- return (p5context([p5call(p5pkg["Perlito5::Match"], "new", p5list_to_a('str', v_str, 'from', v_pos, 'to', v_last_pos, 'capture', (new p5HashRef(p5a_to_h(p5list_to_a('exp', v_result, 'terminated', v_terminated))))), p5want)], p5want));
+ return (p5context([(new p5HashRef(p5a_to_h(p5list_to_a('str', v_str, 'from', v_pos, 'to', v_last_pos, 'capture', (new p5HashRef(p5a_to_h(p5list_to_a('exp', v_result, 'terminated', v_terminated))))))))], p5want));
}
catch(err) {
if ( err instanceof Error ) {
@@ -5323,7 +5323,7 @@ var p5100 = p5pkg['main'];
if ( !( p5bool((v_res != null))) ) {
(v_res = ('*undef*'));
};
- return (p5context([p5call(p5pkg["Perlito5::Match"], "new", p5list_to_a('str', v_str, 'from', v_pos, 'to', v_last_pos, 'capture', v_res), p5want)], p5want));
+ return (p5context([(new p5HashRef(p5a_to_h(p5list_to_a('str', v_str, 'from', v_pos, 'to', v_last_pos, 'capture', v_res))))], p5want));
});
p5make_sub("Perlito5::Expression", "ternary5_parse", function (List__, p5want) {
var v_self = null;
@@ -5423,7 +5423,7 @@ var p5100 = p5pkg['main'];
};
var v_result = null;
(v_result = (p5129.pop_term(p5list_to_a(v_res), 0)));
- return (p5context([p5call(p5pkg["Perlito5::Match"], "new", p5list_to_a('str', v_str, 'from', v_pos, 'to', v_last_pos, 'capture', (new p5HashRef(p5a_to_h(p5list_to_a('exp', v_result, 'terminated', v_terminated))))), p5want)], p5want));
+ return (p5context([(new p5HashRef(p5a_to_h(p5list_to_a('str', v_str, 'from', v_pos, 'to', v_last_pos, 'capture', (new p5HashRef(p5a_to_h(p5list_to_a('exp', v_result, 'terminated', v_terminated))))))))], p5want));
}
catch(err) {
if ( err instanceof Error ) {
@@ -5545,16 +5545,16 @@ var p5100 = p5pkg['main'];
p5129.die([p5list_to_a('Expected expression after ' + String.fromCharCode(39), p5pkg["Perlito5::Match"].flat(p5list_to_a(v_modifier), 1), String.fromCharCode(39))], null);
};
if ( (p5str(v_modifier) == 'if') ) {
- throw(p5context([p5call(p5pkg["Perlito5::Match"], "new", p5list_to_a('str', v_str, 'from', v_pos, 'to', (v_modifier_exp || (v_modifier_exp = new p5HashRef({})))._hash_['to'], 'capture', p5call(p5pkg["Perlito5::AST::If"], "new", p5list_to_a('cond', (p5pkg["Perlito5::Match"].flat(p5list_to_a(v_modifier_exp), p5want) || (p5pkg["Perlito5::Match"].flat(p5list_to_a(v_modifier_exp), p5want) = new p5HashRef({})))._hash_['exp'], 'body', p5call(p5pkg["Perlito5::AST::Lit::Block"], "new", p5list_to_a('stmts', (new p5ArrayRef(p5list_to_a(v_expression)))), 1), 'otherwise', p5call(p5pkg["Perlito5::AST::Lit::Block"], "new", p5list_to_a('stmts', (new p5ArrayRef([]))), 1)), 1)), p5want)], p5want));
+ throw(p5context([(new p5HashRef(p5a_to_h(p5list_to_a('str', v_str, 'from', v_pos, 'to', (v_modifier_exp || (v_modifier_exp = new p5HashRef({})))._hash_['to'], 'capture', p5call(p5pkg["Perlito5::AST::If"], "new", p5list_to_a('cond', (p5pkg["Perlito5::Match"].flat(p5list_to_a(v_modifier_exp), p5want) || (p5pkg["Perlito5::Match"].flat(p5list_to_a(v_modifier_exp), p5want) = new p5HashRef({})))._hash_['exp'], 'body', p5call(p5pkg["Perlito5::AST::Lit::Block"], "new", p5list_to_a('stmts', (new p5ArrayRef(p5list_to_a(v_expression)))), 1), 'otherwise', p5call(p5pkg["Perlito5::AST::Lit::Block"], "new", p5list_to_a('stmts', (new p5ArrayRef([]))), 1)), 1)))))], p5want));
};
if ( (p5str(v_modifier) == 'unless') ) {
- throw(p5context([p5call(p5pkg["Perlito5::Match"], "new", p5list_to_a('str', v_str, 'from', v_pos, 'to', (v_modifier_exp || (v_modifier_exp = new p5HashRef({})))._hash_['to'], 'capture', p5call(p5pkg["Perlito5::AST::If"], "new", p5list_to_a('cond', (p5pkg["Perlito5::Match"].flat(p5list_to_a(v_modifier_exp), p5want) || (p5pkg["Perlito5::Match"].flat(p5list_to_a(v_modifier_exp), p5want) = new p5HashRef({})))._hash_['exp'], 'body', p5call(p5pkg["Perlito5::AST::Lit::Block"], "new", p5list_to_a('stmts', (new p5ArrayRef([]))), 1), 'otherwise', p5call(p5pkg["Perlito5::AST::Lit::Block"], "new", p5list_to_a('stmts', (new p5ArrayRef(p5list_to_a(v_expression)))), 1)), 1)), p5want)], p5want));
+ throw(p5context([(new p5HashRef(p5a_to_h(p5list_to_a('str', v_str, 'from', v_pos, 'to', (v_modifier_exp || (v_modifier_exp = new p5HashRef({})))._hash_['to'], 'capture', p5call(p5pkg["Perlito5::AST::If"], "new", p5list_to_a('cond', (p5pkg["Perlito5::Match"].flat(p5list_to_a(v_modifier_exp), p5want) || (p5pkg["Perlito5::Match"].flat(p5list_to_a(v_modifier_exp), p5want) = new p5HashRef({})))._hash_['exp'], 'body', p5call(p5pkg["Perlito5::AST::Lit::Block"], "new", p5list_to_a('stmts', (new p5ArrayRef([]))), 1), 'otherwise', p5call(p5pkg["Perlito5::AST::Lit::Block"], "new", p5list_to_a('stmts', (new p5ArrayRef(p5list_to_a(v_expression)))), 1)), 1)))))], p5want));
};
if ( (p5str(v_modifier) == 'while') ) {
- throw(p5context([p5call(p5pkg["Perlito5::Match"], "new", p5list_to_a('str', v_str, 'from', v_pos, 'to', (v_modifier_exp || (v_modifier_exp = new p5HashRef({})))._hash_['to'], 'capture', p5call(p5pkg["Perlito5::AST::While"], "new", p5list_to_a('cond', (p5pkg["Perlito5::Match"].flat(p5list_to_a(v_modifier_exp), p5want) || (p5pkg["Perlito5::Match"].flat(p5list_to_a(v_modifier_exp), p5want) = new p5HashRef({})))._hash_['exp'], 'body', p5call(p5pkg["Perlito5::AST::Lit::Block"], "new", p5list_to_a('stmts', (new p5ArrayRef(p5list_to_a(v_expression)))), 1)), 1)), p5want)], p5want));
+ throw(p5context([(new p5HashRef(p5a_to_h(p5list_to_a('str', v_str, 'from', v_pos, 'to', (v_modifier_exp || (v_modifier_exp = new p5HashRef({})))._hash_['to'], 'capture', p5call(p5pkg["Perlito5::AST::While"], "new", p5list_to_a('cond', (p5pkg["Perlito5::Match"].flat(p5list_to_a(v_modifier_exp), p5want) || (p5pkg["Perlito5::Match"].flat(p5list_to_a(v_modifier_exp), p5want) = new p5HashRef({})))._hash_['exp'], 'body', p5call(p5pkg["Perlito5::AST::Lit::Block"], "new", p5list_to_a('stmts', (new p5ArrayRef(p5list_to_a(v_expression)))), 1)), 1)))))], p5want));
};
if ( ((p5str(v_modifier) == 'for') || (p5str(v_modifier) == 'foreach')) ) {
- throw(p5context([p5call(p5pkg["Perlito5::Match"], "new", p5list_to_a('str', v_str, 'from', v_pos, 'to', (v_modifier_exp || (v_modifier_exp = new p5HashRef({})))._hash_['to'], 'capture', p5call(p5pkg["Perlito5::AST::For"], "new", p5list_to_a('cond', (p5pkg["Perlito5::Match"].flat(p5list_to_a(v_modifier_exp), p5want) || (p5pkg["Perlito5::Match"].flat(p5list_to_a(v_modifier_exp), p5want) = new p5HashRef({})))._hash_['exp'], 'body', p5call(p5pkg["Perlito5::AST::Lit::Block"], "new", p5list_to_a('stmts', (new p5ArrayRef(p5list_to_a(v_expression)))), 1)), 1)), p5want)], p5want));
+ throw(p5context([(new p5HashRef(p5a_to_h(p5list_to_a('str', v_str, 'from', v_pos, 'to', (v_modifier_exp || (v_modifier_exp = new p5HashRef({})))._hash_['to'], 'capture', p5call(p5pkg["Perlito5::AST::For"], "new", p5list_to_a('cond', (p5pkg["Perlito5::Match"].flat(p5list_to_a(v_modifier_exp), p5want) || (p5pkg["Perlito5::Match"].flat(p5list_to_a(v_modifier_exp), p5want) = new p5HashRef({})))._hash_['exp'], 'body', p5call(p5pkg["Perlito5::AST::Lit::Block"], "new", p5list_to_a('stmts', (new p5ArrayRef(p5list_to_a(v_expression)))), 1)), 1)))))], p5want));
};
return (p5context([p5129.die([p5list_to_a(('Unexpected statement modifier ' + String.fromCharCode(39) + p5str(v_modifier) + String.fromCharCode(39)))], p5want)], p5want));
}
16 lib5/Perlito5/Expression.pm
View
@@ -1278,10 +1278,10 @@ sub Perlito5::Expression::list_parse {
((my $prec) = Perlito5::Precedence->new(('get_token' => $get_token), ('reduce' => $reduce_to_ast), ('end_token' => $List_end_token), ('end_token_chars' => $List_end_token_chars)));
((my $res) = $prec->precedence_parse());
if ((scalar(@{$res}) == 0)) {
- return (Perlito5::Match->new(('str' => $str), ('from' => $pos), ('to' => $last_pos), ('capture' => {('exp' => '*undef*'), ('terminated' => undef())})))
+ return ({('str' => $str), ('from' => $pos), ('to' => $last_pos), ('capture' => {('exp' => '*undef*'), ('terminated' => undef())})})
};
((my $result) = pop_term($res));
- return (Perlito5::Match->new(('str' => $str), ('from' => $pos), ('to' => $last_pos), ('capture' => {('exp' => $result), ('terminated' => $terminated)})))
+ return ({('str' => $str), ('from' => $pos), ('to' => $last_pos), ('capture' => {('exp' => $result), ('terminated' => $terminated)})})
};
sub Perlito5::Expression::circumfix_parse {
((my $self) = $_[0]);
@@ -1316,7 +1316,7 @@ sub Perlito5::Expression::circumfix_parse {
if (!((defined($res)))) {
($res = '*undef*')
};
- return (Perlito5::Match->new(('str' => $str), ('from' => $pos), ('to' => $last_pos), ('capture' => $res)))
+ return ({('str' => $str), ('from' => $pos), ('to' => $last_pos), ('capture' => $res)})
};
sub Perlito5::Expression::ternary5_parse {
((my $self) = $_[0]);
@@ -1380,7 +1380,7 @@ sub Perlito5::Expression::exp_parse {
return (0)
};
((my $result) = pop_term($res));
- return (Perlito5::Match->new(('str' => $str), ('from' => $pos), ('to' => $last_pos), ('capture' => {('exp' => $result), ('terminated' => $terminated)})))
+ return ({('str' => $str), ('from' => $pos), ('to' => $last_pos), ('capture' => {('exp' => $result), ('terminated' => $terminated)})})
};
((my @Statement_chars) = (9, 8, 7, 6, 5, 4, 3, 2, 1));
((my %Statement) = (('if' => sub {
@@ -1445,16 +1445,16 @@ sub Perlito5::Expression::modifier {
die('Expected expression after ' . chr(39), Perlito5::Match::flat($modifier), chr(39))
};
if (($modifier eq 'if')) {
- return (Perlito5::Match->new(('str' => $str), ('from' => $pos), ('to' => $modifier_exp->{'to'}), ('capture' => Perlito5::AST::If->new(('cond' => Perlito5::Match::flat($modifier_exp)->{'exp'}), ('body' => Perlito5::AST::Lit::Block->new(('stmts' => [$expression]))), ('otherwise' => Perlito5::AST::Lit::Block->new(('stmts' => [])))))))
+ return ({('str' => $str), ('from' => $pos), ('to' => $modifier_exp->{'to'}), ('capture' => Perlito5::AST::If->new(('cond' => Perlito5::Match::flat($modifier_exp)->{'exp'}), ('body' => Perlito5::AST::Lit::Block->new(('stmts' => [$expression]))), ('otherwise' => Perlito5::AST::Lit::Block->new(('stmts' => [])))))})
};
if (($modifier eq 'unless')) {
- return (Perlito5::Match->new(('str' => $str), ('from' => $pos), ('to' => $modifier_exp->{'to'}), ('capture' => Perlito5::AST::If->new(('cond' => Perlito5::Match::flat($modifier_exp)->{'exp'}), ('body' => Perlito5::AST::Lit::Block->new(('stmts' => []))), ('otherwise' => Perlito5::AST::Lit::Block->new(('stmts' => [$expression])))))))
+ return ({('str' => $str), ('from' => $pos), ('to' => $modifier_exp->{'to'}), ('capture' => Perlito5::AST::If->new(('cond' => Perlito5::Match::flat($modifier_exp)->{'exp'}), ('body' => Perlito5::AST::Lit::Block->new(('stmts' => []))), ('otherwise' => Perlito5::AST::Lit::Block->new(('stmts' => [$expression])))))})
};
if (($modifier eq 'while')) {
- return (Perlito5::Match->new(('str' => $str), ('from' => $pos), ('to' => $modifier_exp->{'to'}), ('capture' => Perlito5::AST::While->new(('cond' => Perlito5::Match::flat($modifier_exp)->{'exp'}), ('body' => Perlito5::AST::Lit::Block->new(('stmts' => [$expression])))))))
+ return ({('str' => $str), ('from' => $pos), ('to' => $modifier_exp->{'to'}), ('capture' => Perlito5::AST::While->new(('cond' => Perlito5::Match::flat($modifier_exp)->{'exp'}), ('body' => Perlito5::AST::Lit::Block->new(('stmts' => [$expression])))))})
};
if ((($modifier eq 'for') || ($modifier eq 'foreach'))) {
- return (Perlito5::Match->new(('str' => $str), ('from' => $pos), ('to' => $modifier_exp->{'to'}), ('capture' => Perlito5::AST::For->new(('cond' => Perlito5::Match::flat($modifier_exp)->{'exp'}), ('body' => Perlito5::AST::Lit::Block->new(('stmts' => [$expression])))))))
+ return ({('str' => $str), ('from' => $pos), ('to' => $modifier_exp->{'to'}), ('capture' => Perlito5::AST::For->new(('cond' => Perlito5::Match::flat($modifier_exp)->{'exp'}), ('body' => Perlito5::AST::Lit::Block->new(('stmts' => [$expression])))))})
};
die(('Unexpected statement modifier ' . chr(39) . $modifier . chr(39)))
};
42 src5/lib/Perlito5/Expression.pm
View
@@ -939,18 +939,20 @@ sub list_parse {
my $res = $prec->precedence_parse;
# say "# list_lexer return: ", $res->perl;
if (scalar(@$res) == 0) {
- return Perlito5::Match->new(
+ return {
'str' => $str, 'from' => $pos, 'to' => $last_pos,
capture => {
exp => '*undef*',
- terminated => undef } )
+ terminated => undef }
+ };
}
my $result = pop_term($res);
- return Perlito5::Match->new(
+ return {
'str' => $str, 'from' => $pos, 'to' => $last_pos,
capture => {
exp => $result,
- terminated => $terminated } )
+ terminated => $terminated }
+ };
}
sub circumfix_parse {
@@ -992,8 +994,9 @@ sub circumfix_parse {
# can't return undef in a capture (BUG in Match object?)
$res = '*undef*';
}
- return Perlito5::Match->new(
- 'str' => $str, 'from' => $pos, 'to' => $last_pos, capture => $res);
+ return {
+ 'str' => $str, 'from' => $pos, 'to' => $last_pos, capture => $res
+ };
}
sub ternary5_parse {
@@ -1070,11 +1073,12 @@ sub exp_parse {
}
my $result = pop_term($res);
# say "# exp_parse result: ", $result->perl;
- return Perlito5::Match->new(
+ return {
'str' => $str, 'from' => $pos, 'to' => $last_pos,
capture => {
exp => $result,
- terminated => $terminated } )
+ terminated => $terminated }
+ };
}
@@ -1153,37 +1157,43 @@ sub modifier {
# say "# statement_parse modifier result: ", $modifier_exp->perl;
if ($modifier eq 'if') {
- return Perlito5::Match->new(
+ return {
'str' => $str, 'from' => $pos, 'to' => $modifier_exp->{"to"},
capture => Perlito5::AST::If->new(
cond => Perlito5::Match::flat($modifier_exp)->{'exp'},
body => Perlito5::AST::Lit::Block->new(stmts => [ $expression ]),
- otherwise => Perlito5::AST::Lit::Block->new(stmts => [ ]) ) );
+ otherwise => Perlito5::AST::Lit::Block->new(stmts => [ ])
+ ),
+ };
}
if ($modifier eq 'unless') {
- return Perlito5::Match->new(
+ return {
'str' => $str, 'from' => $pos, 'to' => $modifier_exp->{"to"},
capture => Perlito5::AST::If->new(
cond => Perlito5::Match::flat($modifier_exp)->{'exp'},
body => Perlito5::AST::Lit::Block->new(stmts => [ ]),
- otherwise => Perlito5::AST::Lit::Block->new(stmts => [ $expression ]) ) );
+ otherwise => Perlito5::AST::Lit::Block->new(stmts => [ $expression ])
+ ),
+ };
}
if ($modifier eq 'while') {
- return Perlito5::Match->new(
+ return {
'str' => $str, 'from' => $pos, 'to' => $modifier_exp->{"to"},
capture => Perlito5::AST::While->new(
cond => Perlito5::Match::flat($modifier_exp)->{'exp'},
- body => Perlito5::AST::Lit::Block->new(stmts => [ $expression ] ) ) );
+ body => Perlito5::AST::Lit::Block->new(stmts => [ $expression ] ) )
+ };
}
if ( $modifier eq 'for'
|| $modifier eq 'foreach'
)
{
- return Perlito5::Match->new(
+ return {
'str' => $str, 'from' => $pos, 'to' => $modifier_exp->{"to"},
capture => Perlito5::AST::For->new(
cond => Perlito5::Match::flat($modifier_exp)->{'exp'},
- body => Perlito5::AST::Lit::Block->new(stmts => [ $expression ] ) ) );
+ body => Perlito5::AST::Lit::Block->new(stmts => [ $expression ] ) )
+ };
}
die "Unexpected statement modifier '$modifier'";
}
Please sign in to comment.
Something went wrong with that request. Please try again.