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

Support for TreatWarningsAsErrors, SuperClass, ContextSuperClass options in build task #328

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ The following table describes the properties available for customizing the code
| `ForceAtn` | Force ATN | `True` or `False` | When `True`, the generated parser will use `AdaptivePredict` for all decisions, including LL(1) decisions. |
| `Listener` | Generate Listener | `True` or `False` | When `True`, a parse tree listener interface and base class will be generated for the parLitser. |
| `Visitor` | Generate Visitor | `True` or `False` | When `True`, a parse tree visitor interface and base class will be generated for the parser. |
| `TreatWarningsAsErrors` | Treat Warnings as Errors | `True` or `False` | When `True`, the warning are treated as errors. |
| `SuperClass` | SuperClass | `string` | Set the superclass of the generated parser or lexer. For combined grammars, it sets the superclass of the parser. |
| `ContextSuperClass` | ContextSuperClass | `string` | Specify the super class of parse tree internal nodes. Should derive from ultimately RuleContext at minimum. |

#### Using the ANTLR Language Support extension

Expand Down
10 changes: 8 additions & 2 deletions runtime/CSharp/Antlr4BuildTasks/Antlr4.CodeGenerator.targets
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@
<Visitor>true</Visitor>
<Abstract>false</Abstract>
<ForceAtn>false</ForceAtn>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<SuperClass></SuperClass>
<ContextSuperClass></ContextSuperClass>
</Antlr4>
</ItemDefinitionGroup>

Expand Down Expand Up @@ -149,7 +152,10 @@
GenerateVisitor="%(Antlr4.Visitor)"
ForceAtn="%(Antlr4.ForceAtn)"
AbstractGrammar="%(Antlr4.Abstract)"
UseCSharpGenerator="$(Antlr4UseCSharpGenerator)">
UseCSharpGenerator="$(Antlr4UseCSharpGenerator)"
TreatWarningsAsErrors="%(Antlr4.TreatWarningsAsErrors)"
SuperClass="%(Antlr4.SuperClass)"
ContextSuperClass="%(Antlr4.ContextSuperClass)">

<Output ItemName="Antlr4GeneratedCodeFiles" TaskParameter="GeneratedCodeFiles" />
</Antlr4ClassGenerationTask>
Expand Down Expand Up @@ -196,7 +202,7 @@
</Choose>

<Import Condition="'$(Antlr4IsSdkProject)' == 'True'" Project="Antlr4.CodeGenerator.DefaultItems.targets" />

<!-- Support for NCrunch -->
<ItemGroup Condition="'$(NCrunch)' == '1'">
<!-- NCrunch tries to copy the fewest possible files to its build directory, those it misses are declared here. -->
Expand Down
18 changes: 18 additions & 0 deletions runtime/CSharp/Antlr4BuildTasks/Antlr4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@
DisplayName="Abstract Grammar"
Default="false"
Description="When true, the generated classes are marked as abstract." />
<BoolProperty
Category="ANTLR"
Name="TreatWarningsAsErrors"
DisplayName="Treat Warnings as Errors"
Default="false"
Description="When true, the warning are treated as errors." />
<BoolProperty
Category="ANTLR"
Name="SuperClass"
DisplayName="SuperClass"
Default=""
Description="Set the superclass of the generated parser or lexer. For combined grammars, it sets the superclass of the parser." />
<BoolProperty
Category="ANTLR"
Name="ContextSuperClass"
DisplayName="ContextSuperClass"
Default=""
Description="Specify the super class of parse tree internal nodes. Should derive from ultimately RuleContext at minimum." />

<!--
The rest of these properties are not ANTLR-specific, but CPS provides no way to inherit properties, so if we fail to
Expand Down
21 changes: 21 additions & 0 deletions runtime/CSharp/Antlr4BuildTasks/Antlr4ClassGenerationTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,24 @@ public bool UseCSharpGenerator
set;
}

public bool TreatWarningsAsErrors
{
get;
set;
}

public string SuperClass
{
get;
set;
}

public string ContextSuperClass
{
get;
set;
}

[Output]
public ITaskItem[] GeneratedCodeFiles
{
Expand Down Expand Up @@ -306,6 +324,9 @@ private AntlrClassGenerationTaskInternal CreateBuildTaskWrapper()
wrapper.JavaInstallation = JavaInstallation;
wrapper.JavaExecutable = JavaExecutable;
wrapper.UseCSharpGenerator = UseCSharpGenerator;
wrapper.TreatWarningsAsErrors = TreatWarningsAsErrors;
wrapper.SuperClass = SuperClass;
wrapper.ContextSuperClass = ContextSuperClass;
return wrapper;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,24 @@ public bool UseCSharpGenerator
set;
}

public bool TreatWarningsAsErrors
{
get;
set;
}

public string SuperClass
{
get;
set;
}

public string ContextSuperClass
{
get;
set;
}

public IList<string> SourceCodeFiles
{
get
Expand Down Expand Up @@ -282,6 +300,21 @@ public bool Execute()
arguments.Add(TargetNamespace);
}

if (TreatWarningsAsErrors)
arguments.Add("-Werror");

if (!string.IsNullOrEmpty(SuperClass))
{
arguments.Add("-DsuperClass");
arguments.Add(SuperClass);
}

if (!string.IsNullOrEmpty(ContextSuperClass))
{
arguments.Add("-DcontextSuperClass");
arguments.Add(ContextSuperClass);
}

arguments.AddRange(SourceCodeFiles);

#if NETSTANDARD
Expand Down