Skip to content

Commit

Permalink
Perlito5 - misc/perl5_parser features
Browse files Browse the repository at this point in the history
  • Loading branch information
fglock committed Jul 7, 2024
1 parent 56c38b5 commit fda88e0
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions misc/perl5_parser/perl5_parser.pl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
CURLY_CLOSE => 27,
SEMICOLON => 28,
ARROW => 29,
EQUALS => 30,
};

my %TokenName = (
Expand Down Expand Up @@ -58,6 +59,7 @@
CURLY_CLOSE() => 'CURLY_CLOSE',
SEMICOLON() => 'SEMICOLON',
ARROW() => 'ARROW',
EQUALS() => 'EQUALS',
);

my %OPERATORS = (
Expand All @@ -83,9 +85,10 @@
'}' => CURLY_CLOSE(),
';' => SEMICOLON(),
'->' => ARROW(),
'=' => EQUALS(),
map { $_ => OPERATOR() }
qw(
== != <= >= < > <=> =
== != <= >= < > <=>
+ * ** / % ++ -- && || // ! ^ ~ ~~ & |
>> <<
=>
Expand Down Expand Up @@ -419,6 +422,21 @@ sub parse_optional_whitespace {
}
if ( $tokens->[$pos][0] == NEWLINE() ) {
$pos++;
if ( $tokens->[$pos][0] == EQUALS() ) {
$pos++;
if ( $tokens->[$pos][0] == IDENTIFIER() ) {

# documentation (pod):
# =for ... until end of paragraph
# =any_command ... until =cut or =end
# TODO
$pos++;
while ( $tokens->[$pos][0] != NEWLINE() ) {
$pos++;
}
redo;
}
}
redo;
}
if ( $tokens->[$pos][0] == START_COMMENT() ) {
Expand Down Expand Up @@ -553,12 +571,12 @@ sub parse_double_quote_string {
next;
}
}
if ( $type == SIGIL() ) {
if ( $type == SIGIL() && $tokens->[$pos][1] ne '%' ) {
my $expr = parse_variable( $tokens, $pos );
if ( $expr->{FAIL} ) {
return parse_fail( $tokens, $index );
}
push @ops, { type => 'STRING', index => $index, value => $value, next => $pos };
push @ops, { type => 'STRING', index => $index, value => $value, next => $pos } if length($value);
push @ops, $expr;
$value = '';
$pos = $expr->{next};
Expand Down Expand Up @@ -867,6 +885,9 @@ sub main {
q! abd !;
q< abd >;
{ q => 123 };
qq< abd [$v] >;
qq< abd [$v$a] >;
(-123, -123.56,
=for testing pod
1E10 + -1E-10 );

0 comments on commit fda88e0

Please sign in to comment.