Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[antlr4 grammar/CI build] Fix for 2609 #2610

Merged
merged 4 commits into from
May 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ jobs:
- name: Install trgen
shell: pwsh
run: |
dotnet tool install -g trgen --version 0.16.1
dotnet tool install -g trwdog --version 0.16.1
dotnet tool install -g trgen --version 0.16.3
dotnet tool install -g trwdog --version 0.16.3
if ("${{ matrix.os }}" -eq "ubuntu-latest") {
echo "$HOME/.dotnet/tools" >> $env:GITHUB_PATH
}
Expand Down
4 changes: 2 additions & 2 deletions _scripts/really-run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ $antlrPath = _scripts/get-antlr.ps1 "4.10"
# Set up env as it is used in test script.
echo "antlr_path=$antlrPath" >> $env:GITHUB_ENV

dotnet tool install -g trgen --version 0.16.1
dotnet tool install -g trwdog --version 0.16.1
dotnet tool install -g trgen --version 0.16.3
dotnet tool install -g trwdog --version 0.16.3

# Call test script.
$env:ANTLR_JAR_PATH="$antlrPath"
Expand Down
6 changes: 3 additions & 3 deletions _scripts/regtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ setupdeps()
date
echo "Setting up trgen and antlr jar."
dotnet tool uninstall -g trgen
dotnet tool install -g trgen --version 0.16.1
dotnet tool install -g trgen --version 0.16.3
dotnet tool uninstall -g trxml2
dotnet tool install -g trxml2 --version 0.16.1
dotnet tool install -g trxml2 --version 0.16.3
dotnet tool uninstall -g trwdog
dotnet tool install -g trwdog --version 0.16.1
dotnet tool install -g trwdog --version 0.16.3
case "${unameOut}" in
Linux*) curl 'https://repo1.maven.org/maven2/org/antlr/antlr4/4.10/antlr4-4.10-complete.jar' -o /tmp/antlr4-4.10-complete.jar;;
Darwin*) curl 'https://repo1.maven.org/maven2/org/antlr/antlr4/4.10/antlr4-4.10-complete.jar' -o /tmp/antlr4-4.10-complete.jar;;
Expand Down
1 change: 0 additions & 1 deletion _scripts/skip-cpp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ alpaca
angelscript
antlr/antlr2
antlr/antlr3
antlr/antlr4
apex
apt
arithmetic
Expand Down
1 change: 0 additions & 1 deletion _scripts/skip-python3.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
_grammar-test
antlr/antlr2
antlr/antlr3
antlr/antlr4
apex
asm/asmMASM
asm/masm
Expand Down
5 changes: 5 additions & 0 deletions antlr/antlr4/ANTLRv4Lexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ ARGUMENT_CONTENT
: .
;

// TODO: This grammar and the one used in the Intellij Antlr4 plugin differ
// for "actions". This needs to be resolved at some point.
// The Intellij Antlr4 grammar is here:
// https://github.com/antlr/intellij-plugin-v4/blob/1f36fde17f7fa63cb18d7eeb9cb213815ac658fb/src/main/antlr/org/antlr/intellij/plugin/parser/ANTLRv4Lexer.g4#L587

// -------------------------
// Target Language Actions
//
Expand Down
2 changes: 1 addition & 1 deletion antlr/antlr4/ANTLRv4Parser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ labeledAlt
// Lexer rules

lexerRuleSpec
: FRAGMENT? TOKEN_REF COLON lexerRuleBlock SEMI
: FRAGMENT? TOKEN_REF optionsSpec? COLON lexerRuleBlock SEMI
;

lexerRuleBlock
Expand Down
39 changes: 18 additions & 21 deletions antlr/antlr4/CSharp/LexerAdaptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
public abstract class LexerAdaptor : Lexer
{
private static readonly int PREQUEL_CONSTRUCT = -10;
private static readonly int OPTIONS_CONSTRUCT = -11;

// I copy a reference to the stream, so It can be used as a Char Stream, not as a IISStream
readonly ICharStream stream;
Expand All @@ -45,16 +46,16 @@ public abstract class LexerAdaptor : Lexer
protected LexerAdaptor(ICharStream input)
: base(input, Console.Out, Console.Error)
{
CurrentRuleType = TokenConstants.InvalidType;
_insideOptionsBlock = false;
CurrentRuleType = TokenConstants.InvalidType;
_insideOptionsBlock = false;
stream = input;
}

protected LexerAdaptor(ICharStream input, TextWriter output, TextWriter errorOutput)
: base(input, output, errorOutput)
{
CurrentRuleType = TokenConstants.InvalidType;
_insideOptionsBlock = false;
CurrentRuleType = TokenConstants.InvalidType;
_insideOptionsBlock = false;
stream = input;
}

Expand Down Expand Up @@ -107,20 +108,6 @@ protected void handleEndAction()
}
}

protected void handleOptionsLBrace()
{
if (_insideOptionsBlock)
{
Type = ANTLRv4Lexer.BEGIN_ACTION;
PushMode(ANTLRv4Lexer.TargetLanguageAction);
}
else
{
Type = ANTLRv4Lexer.LBRACE;
_insideOptionsBlock = true;
}
}

private bool InLexerRule
{
get { return CurrentRuleType == ANTLRv4Lexer.TOKEN_REF; }
Expand All @@ -133,16 +120,27 @@ public override IToken Emit()
// enter prequel construct ending with an RBRACE
CurrentRuleType = PREQUEL_CONSTRUCT;
}
else if (Type == ANTLRv4Lexer.OPTIONS && CurrentRuleType == ANTLRv4Lexer.TOKEN_REF)
{
CurrentRuleType = OPTIONS_CONSTRUCT;
}
else if (Type == ANTLRv4Lexer.RBRACE && CurrentRuleType == PREQUEL_CONSTRUCT)
{
// exit prequel construct
CurrentRuleType = TokenConstants.InvalidType;
}
else if (Type == ANTLRv4Lexer.RBRACE && CurrentRuleType == OPTIONS_CONSTRUCT)
{ // exit options
CurrentRuleType = ANTLRv4Lexer.TOKEN_REF;
}
else if (Type == ANTLRv4Lexer.AT && CurrentRuleType == TokenConstants.InvalidType)
{
// enter action
CurrentRuleType = ANTLRv4Lexer.AT;
}
else if (Type == ANTLRv4Lexer.SEMI && CurrentRuleType == OPTIONS_CONSTRUCT)
{ // ';' in options { .... }. Don't change anything.
}
else if (Type == ANTLRv4Lexer.END_ACTION && CurrentRuleType == ANTLRv4Lexer.AT)
{
// exit action
Expand All @@ -155,7 +153,6 @@ public override IToken Emit()
{
Type = ANTLRv4Lexer.TOKEN_REF;
}

if (char.IsLower(firstChar))
{
Type = ANTLRv4Lexer.RULE_REF;
Expand All @@ -177,8 +174,8 @@ public override IToken Emit()

public override void Reset()
{
CurrentRuleType = TokenConstants.InvalidType;
_insideOptionsBlock = false;
CurrentRuleType = TokenConstants.InvalidType;
_insideOptionsBlock = false;
base.Reset();
}
}
Loading