Skip to content

Commit

Permalink
#2912 Properly lex special variables followed by operator
Browse files Browse the repository at this point in the history
Fixes #2912
  • Loading branch information
hurricup committed Sep 28, 2024
1 parent 9406cb0 commit 8263348
Show file tree
Hide file tree
Showing 13 changed files with 5,942 additions and 5,342 deletions.
11 changes: 6 additions & 5 deletions plugin/core/grammar/Perl.flex
Original file line number Diff line number Diff line change
Expand Up @@ -880,11 +880,12 @@ POSIX_CHARGROUP_ANY = {POSIX_CHARGROUP}|{POSIX_CHARGROUP_DOUBLE}
}

<VARIABLE_UNBRACED>{
// we are here after a sigil, and we can't cast to the $OLD_PERL_VERSION variable $]
"$" / "]" {return getUnbracedVariableNameToken();}
// this is a subset of builtins, $;, $, for example, can't be dereferenced
"$" / [\{\"\'\[\]\`\\\!\%\&\(\+\-\.\/\<\=\>\|\~\?\:\*\^\@\_\$\:\w_\d] {return processUnbracedScalarSigil();}
"{" {return startBracedVariable();}
// followed by the built-in variable which can't be dereferenced, so this is a variable name
"$" / [\.\,\/\\\|\%\-\+\?\:\=\^\~\!\@\#\*\(\)\<\>0\;\[\]\&\`\'\"] {return getUnbracedVariableNameToken();}
// this is definitely a sigil
"$" / [\{\_\$\w_] {return processUnbracedScalarSigil();}

"{" {return startBracedVariable();}
{VARIABLE_NAME} {return getUnbracedVariableNameToken();}
}

Expand Down
10,574 changes: 5,287 additions & 5,287 deletions plugin/core/src/main/gen/com/perl5/lang/perl/lexer/PerlLexer.java

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions plugin/src/test/java/unit/perl/parser/PerlParserLikeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ protected String getBaseDataPath() {
return "unit/perl/parser";
}

@Test
public void testDoubleBuckConcat() { doTest(false); }

@Test
public void testHeredocInRegexp() { doTest(false); }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,284 @@
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
.
PERL_OPERATOR => DEFAULT_OPERATION_SIGN
1
PERL_NUMBER => DEFAULT_NUMBER
;
PERL_SEMICOLON => DEFAULT_SEMICOLON
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
,
PERL_COMMA => DEFAULT_COMMA
1
PERL_NUMBER => DEFAULT_NUMBER
;
PERL_SEMICOLON => DEFAULT_SEMICOLON
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
/
PERL_OPERATOR => DEFAULT_OPERATION_SIGN
1
PERL_NUMBER => DEFAULT_NUMBER
;
PERL_SEMICOLON => DEFAULT_SEMICOLON
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
\
PERL_OPERATOR => DEFAULT_OPERATION_SIGN
1
PERL_NUMBER => DEFAULT_NUMBER
;
PERL_SEMICOLON => DEFAULT_SEMICOLON
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
|
PERL_OPERATOR => DEFAULT_OPERATION_SIGN
1
PERL_NUMBER => DEFAULT_NUMBER
;
PERL_SEMICOLON => DEFAULT_SEMICOLON
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
%
PERL_OPERATOR => DEFAULT_OPERATION_SIGN
;
PERL_SEMICOLON => DEFAULT_SEMICOLON
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
-
PERL_OPERATOR => DEFAULT_OPERATION_SIGN
1
PERL_NUMBER => DEFAULT_NUMBER
;
PERL_SEMICOLON => DEFAULT_SEMICOLON
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
+
PERL_OPERATOR => DEFAULT_OPERATION_SIGN
1
PERL_NUMBER => DEFAULT_NUMBER
;
PERL_SEMICOLON => DEFAULT_SEMICOLON
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
?
PERL_OPERATOR => DEFAULT_OPERATION_SIGN
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
:
PERL_OPERATOR => DEFAULT_OPERATION_SIGN
1
PERL_NUMBER => DEFAULT_NUMBER
;
PERL_SEMICOLON => DEFAULT_SEMICOLON
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
=
PERL_OPERATOR => DEFAULT_OPERATION_SIGN
1
PERL_NUMBER => DEFAULT_NUMBER
;
PERL_SEMICOLON => DEFAULT_SEMICOLON
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
^
PERL_OPERATOR => DEFAULT_OPERATION_SIGN
1
PERL_NUMBER => DEFAULT_NUMBER
;
PERL_SEMICOLON => DEFAULT_SEMICOLON
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
~
PERL_OPERATOR => DEFAULT_OPERATION_SIGN
1
PERL_NUMBER => DEFAULT_NUMBER
;
PERL_SEMICOLON => DEFAULT_SEMICOLON
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
!
PERL_OPERATOR => DEFAULT_OPERATION_SIGN
1
PERL_NUMBER => DEFAULT_NUMBER
;
PERL_SEMICOLON => DEFAULT_SEMICOLON
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
@
PERL_ARRAY => DEFAULT_IDENTIFIER => TEXT
a
PERL_ARRAY => DEFAULT_IDENTIFIER => TEXT
;
PERL_SEMICOLON => DEFAULT_SEMICOLON
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
#test;
PERL_COMMENT => DEFAULT_LINE_COMMENT
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
*
PERL_OPERATOR => DEFAULT_OPERATION_SIGN
1
PERL_NUMBER => DEFAULT_NUMBER
;
PERL_SEMICOLON => DEFAULT_SEMICOLON
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
[
PERL_BRACKETS => DEFAULT_BRACKETS
1
PERL_NUMBER => DEFAULT_NUMBER
]
PERL_BRACKETS => DEFAULT_BRACKETS
;
PERL_SEMICOLON => DEFAULT_SEMICOLON
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
(
PERL_PARENTESS => DEFAULT_PARENTHS
)
PERL_PARENTESS => DEFAULT_PARENTHS
;
PERL_SEMICOLON => DEFAULT_SEMICOLON
(
PERL_PARENTESS => DEFAULT_PARENTHS
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
)
PERL_PARENTESS => DEFAULT_PARENTHS
;
PERL_SEMICOLON => DEFAULT_SEMICOLON
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
<
PERL_OPERATOR => DEFAULT_OPERATION_SIGN
1
PERL_NUMBER => DEFAULT_NUMBER
;
PERL_SEMICOLON => DEFAULT_SEMICOLON
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
>
PERL_OPERATOR => DEFAULT_OPERATION_SIGN
2
PERL_NUMBER => DEFAULT_NUMBER
;
PERL_SEMICOLON => DEFAULT_SEMICOLON
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
0
PERL_NUMBER => DEFAULT_NUMBER
;
PERL_SEMICOLON => DEFAULT_SEMICOLON
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
1
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
;
PERL_SEMICOLON => DEFAULT_SEMICOLON
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
;
PERL_SEMICOLON => DEFAULT_SEMICOLON
[
PERL_BRACKETS => DEFAULT_BRACKETS
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
]
PERL_BRACKETS => DEFAULT_BRACKETS
;
PERL_SEMICOLON => DEFAULT_SEMICOLON
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
&
PERL_OPERATOR => DEFAULT_OPERATION_SIGN
;
PERL_SEMICOLON => DEFAULT_SEMICOLON
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
`
PERL_DX_STRING => DEFAULT_STRING
`
PERL_DX_STRING => DEFAULT_STRING
;
PERL_SEMICOLON => DEFAULT_SEMICOLON
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
'
PERL_SQ_STRING => DEFAULT_STRING
'
PERL_SQ_STRING => DEFAULT_STRING
;
PERL_SEMICOLON => DEFAULT_SEMICOLON
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
$
PERL_SCALAR => DEFAULT_IDENTIFIER => TEXT
"
PERL_DQ_STRING => DEFAULT_STRING
test
PERL_DQ_STRING => DEFAULT_STRING
"
PERL_DQ_STRING => DEFAULT_STRING
;
PERL_SEMICOLON => DEFAULT_SEMICOLON
29 changes: 29 additions & 0 deletions plugin/src/test/resources/unit/perl/parser/doubleBuckConcat.code
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
$$.1;
$$,1;
$$/1;
$$\1;
$$|1;
$$%;
$$-1;
$$+1;
$$?$$:1;
$$=1;
$$^1;
$$~1;
$$!1;
$$@a;
$$#test;
$$*1;
$$[1];
$$();
($$);
$$<1;
$$>2;
$$0;
$$1;
$$;
[$$];
$$&;
$$``;
$$'';
$$"test";
Loading

0 comments on commit 8263348

Please sign in to comment.