Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Perlito5 - parser - test end of term
  • Loading branch information
fglock committed Sep 29, 2012
1 parent c0ab727 commit 634599e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
12 changes: 12 additions & 0 deletions TODO-perlito5
Expand Up @@ -33,13 +33,25 @@ TODO list for Perlito5
* Parser

-- defined-or vs. m// (2012/9/25 Конрад Боровски <notifications@github.com>)
Note: fixed; see test t5/01-perlito/25-syntax-defined-or.t

$ perl perlito5.pl -Isrc5/lib -Cast-perl5 -e ' shift // 2 '
Number or Bareword found where operator expected

$ perl perlito5.pl -Isrc5/lib -Cast-perl5 -e ' shift / 2 '
Can't find string terminator '/' anywhere before EOF

-- quotes vs. hash lookups:

$ perl -e ' q}} '
# ok

$ perl -e ' $x{ q}} } '
Unmatched right curly bracket at -e line 1, at end of line

$ perl -e ' $x{ q]] } '
# ok

-- attributes - see: http://perldoc.perl.org/attributes.html

-- create __DATA__
Expand Down
15 changes: 11 additions & 4 deletions perlito5.pl

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src5/lib/Perlito5/Javascript3/CORE.pm
Expand Up @@ -72,6 +72,10 @@ CORE.warn = function(List__) {
for (i = 0; i < o.length; i++) {
s = s + p5str(o[i]);
}
try {
s = s + "\n" + new Error().stack;
}
catch(err) { }
CORE.print(["Warning: " + s + "\n"]);
};
Expand Down
12 changes: 10 additions & 2 deletions src5/lib/Perlito5/Precedence.pm
Expand Up @@ -33,6 +33,10 @@ sub is_term {
($token->[0] eq 'term') || ($token->[0] eq 'postfix_or_term') || ($token->[0] eq 'postfix')
}

sub is_num {
$_[0] ge '0' && $_[0] le '9'
}

sub is_ident_middle {
my $c = shift;
($c ge 'a' && $c le 'z')
Expand Down Expand Up @@ -125,8 +129,12 @@ sub op_parse {
for my $len ( @Term_chars ) {
my $term = substr($str, $pos, $len);
if (exists($Term{$term})) {
my $m = $Term{$term}->($str, $pos);
return $m if $m;
my $c1 = substr($str, $pos + length($term) - 1, 1);
my $c2 = substr($str, $pos + length($term), 1);
if ( is_num($c1) || !is_ident_middle($c1) || !is_ident_middle($c2) ) {
my $m = $Term{$term}->($str, $pos);
return $m if $m;
}
}
}
}
Expand Down

0 comments on commit 634599e

Please sign in to comment.