Git Product home page Git Product logo

antlrcs's People

Contributors

parrt avatar sharwell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

antlrcs's Issues

Add netstandard 2.0 target to Antlr3.Runtime

Currently I'm receiving the following error in a .net core project:
error PS0264: Ambiguous match: need to map 'System.Runtime.Serialization.StreamingContext, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Context=Runtime' and have several candidates: 'System.Runtime.Serialization.StreamingContext, Antlr3.Runtime, Version=3.5.0.2, Culture=neutral, PublicKeyToken=eb42632606e9261f, Context=Reference', 'System.Runtime.Serialization.StreamingContext, System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, Context=Reference.

Because it is referencing the netstandard1.1 version of Antrl3.Runtime package which has a hack for the StreamingContext sturct:
https://github.com/antlr/antlrcs/blob/master/Runtime/Antlr3.Runtime/System/StreamingContext.cs

This hack is not needed in netstandard2.0

StringRenderer

In StringRenderer line 67 is intended to handle formatting of all the formats, other than predefined.
However, it will never work since in line 48 attribute value is converted to string, and then String.Format() is used to format String type value.

Please modify line line 67 as follow:

return string.Format(culture, formatString, o);

Below my optimized implementation, handling html-encode.

Tomasz Jastrzębski

public virtual string ToString(object o, string formatString, CultureInfo culture)
    {
        if (formatString == null) return o.ToString();

        switch (formatString) {
            case "upper":
                return o.ToString().ToUpper(culture);
            case "lower":
                return o.ToString().ToLower(culture);
            case "cap":
                string s = o.ToString();
                return s.Length > 0 ? Char.ToUpper(s[0], culture) + s.Substring(1) : s;
            case "url-encode":
                return HttpUtility.UrlEncode(o.ToString(), Encoding.UTF8);
            case "xml-encode":
                return SecurityElement.Escape(o.ToString());
            case "html-encode":
                return HttpUtility.HtmlEncode(o);
            default:
                return String.Format(culture, formatString, o);
        }
    }

antlr3 template generating wrong code

Hi,

i was trying to upgrade our project from older antlr 3.4 to the latest 3.5 (tried various version including the latest 3.5.2-rc1) but I keep getting a compilation error of the produced .cs file.

I have found traces of other people running into the same issue and they can describe it better then me :)
https://stackoverflow.com/questions/9923639/antlr-grammar-generating-invalid-c-sharp-code
https://www.antlr3.org/pipermail/antlr-interest/2012-February/044153.html

But the solution suggested (setting ASTLabelType to StringTemplate) doesnt make much sense as ASTLabelType should be of the AST type.

I have attached a minimal solution for easier diagnosing.

Subtree is lost during tree construction

I have a rule like this

list options {
  backtrack=true;
}
  : (d=decl e=delim l=list) -> ^($d $e) $l
  | decl

and the input like

decl delim decl delim decl

The expected tree is: (decl delim) (decl delim) decl, which works with Java-based Antlr 3.2 generator.
However, with this generator, the first two trees are flat, producing decl decl decl. Furthermore, if decl is a subtree, the first two objects would contain only the root nodes, while the last decl would have a correct subtree.

My system is:

Mono JIT compiler version 4.6.1 (Stable 4.6.1.5/ef43c15 Wed Oct 12 09:05:00 UTC 2016)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           __thread
	SIGSEGV:       altstack
	Notifications: epoll
	Architecture:  x86
	Disabled:      none
	Misc:          softdebug 
	LLVM:          supported, not enabled.
	GC:            sgen

the grammar is with following options:

options {
	language=CSharp3;
	output=AST;
	TokenLabelType=CommonToken;
}

Does Antlr have an ECCN?

Hello. Our team would like to use/include your library in our product, and since we export outside of the U.S., we're required to provide ECCN (Export Control Classification Number) information for all 3rd-party libraries that may use/include encryption.

Antlr4.StringTemplate.Format Issue

Hi,

I found a small issue with Antlr4.StringTemplate.Format (line 628).

The statement as follows:

template = Regex.Replace(template, "[0-9]+", @"arg\0");

does not substitute numeric values (Number) with 'argNumber' and it results in an error similar to the following one:

1:8: invalid character '\'
1:9: '0' came as a complete surprise to me

It should be replaces with that statement:

template = Regex.Replace(template, "[0-9]+", @"arg$0");

That will help.

Kind regards,
Tom

Main license issue

Hello,

I am writing regarding the main license of component antlrcs 3.5.1. The LICENSE.txt file lists one kind of BSD 3 Clause (with the name of the copyright holder in the 3rd clause), whereas the files have references of another kind of BSD 3 Clause license (with the name of the author in the 3rd clause). So which license does apply as a main to this component? (the one from LICENSE.txt or the one listed at the beginning of most of the files)?

Thank you in advance for your help.
Best regards,
Julia

Supress the build warning

I got this in Visual Studio:

Warning 4   'Willinsoft.RAD.BPL.IntellisenseDebugGrammarParser.StatementContext.Stop' hides inherited member 'Antlr4.Runtime.ParserRuleContext.Stop'. Use the new keyword if hiding was intended.   E:\Project\Willinsoft Development Platform\Willinsoft.RAD\obj\Debug\IntellisenseDebugGrammarParser.cs   4346    17  Willinsoft.RAD

It's better to suppress this warning which makes warning list huge.

separator omitted when first argument is null or empty

consider the template
<["Wendy",,"Jane"]; separator=",", null="">
it will print
Wendy,,Jane
however the template
<[,"Wendy","Jane"]; separator=",", null="">
will print
Wendy,Jane
and not
,Wendy,Jane

This is an issue for a template i have that builds a csv output, when the first column happens to contain null values. A work around is to use null=" " however that means there would be no distinction between "" and " "

Further to that if i have a dictionary i wish to print in a line and use
<d.keys:{k | <d.(k)>}; separator=",", null=" ">
then there is nothing i can do to keep the leading comma as the dictionary lookup resolves to "" even if the value is null and therefore doesn't count towards the null replacement.

Add support for C# dynamics

TemplateGroup tg=new TemplateGroupString("test",@"
test(a,b,c) ::= <<
a = $a$
a.name = $a.name$
b = $b$
b.name = $b.name$
c = $c$
c.name = $c.name$
>>
",'$','$');

Template t=tg.GetInstanceOf("test");

object a=new { name = "A object" };
t.Add("a",a);

object b= Newtonsoft.Json.JsonConvert.DeserializeObject("{ name: \"B object\" }");
t.Add("b",b);

dynamic c=new ExpandoObject();
c.name="C object";
t.Add("c",c);

System.Console.WriteLine(t.Render());

The output is:

a = { name = A object }
a.name = A object
b =
b.name =
c = [name, C object]
c.name =

Expected output:

a = { name = A object }
a.name = A object
b = (not really matters)
b.name = B object
c = [name, C object]
c.name = C object

I can't find any other way to be able to preview my templates easily (user passes a JSON object, deserialized into a Dictionary<string,dynamic>, then each dictionary KVP are sent to the template individually).
Let me know if you need clarification about this use case.

Improve exception message for not found variables

Improve exception message for not found variables

Currently, when a variable is missing it shows line: Column number, it should be better if it puts the whole string source code into the error message. As it is hard to detect which when we have a number of templates.

Md. Alim Ul Karim
C# Software Architect at Crossover
Co-creator and Architect of Aurea Automatic Unit Test Solution for C#

Moving from Antlr 3.1.1 to 3.5.0.2

I currently have antlr 3.1.1 in my code. I am planning to move to 3.5.0.2 so I installed it from Nuget. Upon installing I encountered errors in the generated Lexer and Parser.cs. I have looked at release notes, articles, etc but couldn't find the right way of fixing these errors. I would like to seek guidance:

1.) The type or namespace name 'Collections' does not exist in the namespace 'Antlr.Runtime'.
I get this error in "using Antlr.Runtime.Collections.StackList;"

2.) What parameter should I put in ParserRuleReturnScope? What are the changes why a parameter was added here?

3.) Tree property does not exist in ParserRuleReturnScope anymore.

4.) Lexer - DEFAULT_TOKEN_CHANNEL, HIDDEN does not exist.

5.) this.dfa19.specialStateTransitionHandler - CS1061 'ExpressionLexer.DFA19' does not contain a definition for 'specialStateTransitionHandler' and no extension method 'specialStateTransitionHandler' accepting a first argument of type 'ExpressionLexer.DFA19' could be found (are you missing a using directive or an assembly reference?)

There are a lot more errors but I would like to focus first on this.

NuGet Package : Add `repository` metadata.

Basically, we can now add a repository metadata on a nuspec file to allow the repository to be surfaced on NuGet. This allows you to have a projectUrl as well a repository URL now.

I've talked about it on Twitter but the most basic things to know is here:

NuSpec Reference

Reference Implementation in Json .NET
image

"new TemplateGroupFile(fileName)" only works with full file path

The constructor for a new template group, created from an .stg file, only works when a full path is supplied. A call like:
var stg = new TemplateGroupFile("Template.stg");
gives a System.UriFormatException

I suggest calling System.IO.Path.GetFullPath on the supplied filename, before creating the Uri.

Internal modifier for imported grammars

From Ranco

When updating ANTLR in one of our projects from version 3.4 to the latest 3.5.0.1, I noticed that the internal modifier of imported grammars is not respected anymore. In version 3.4, when adding @modifier { internal } to main grammar Grammar1.g (which imports Grammar2.g), a recognizer Grammar1_Grammar2.g.cs would be generated with modifier internal, in 3.5.0.1 it is public. Is this by design, and if so, how can the recognizer of the imported grammar be made internal now?

Missing Constructor in Antlr4.StringTemplate.Visualizer When Running AntlrCS on File in Mono

When I run the antlr3.exe using mono without specifying a grammar, everything runs fine. However, when I specify a grammar file to generate a parser from using mono, I get the following message:

Missing method .ctor in assembly {FILEPATH}/antlr-dotnet-tool-3.5.0.2/Antlr4.StringTemplate.Visualizer.dll, type System.Windows.ThemeInfoAttribute
Can't find custom attr constructor image: {FILEPATH}/antlr-dotnet-tool-3.5.0.2/Antlr4.StringTemplate.Visualizer.dll mtoken: 0x0a00000d

I'm not sure why this happens, or whether the StringTemplate Visualizer is even needed, but it is definitely preventing me from using Antlrcs.

Dynamically included templates dont accept multiple arguments

The documentation describes these two ways of including a template (amongst others):

  • name: <template(argument-list)>
  • dynamic <(expr)(argument-list)>

Both of these are described as a taking an argument-list but there appears to be a bug in the C# port of StringTemplate such that the dynamic version doesn't accept a list of arguments, only a single argument. If you try this you get the following exception:

'=' came as a complete surprise to me
Antlr4.StringTemplate.Compiler.TemplateException: Exception of type 'Antlr4.StringTemplate.Compiler.TemplateException' was thrown.

I have recreated this here: https://github.com/hisuwh/StringTemplate.BugReproduction

StringTemplate 4.0.8

I have some errors during compilation...

I am not using your build process, so it's not your error,
but i have question what is wrong with mine compilation

Antlr3.StringTemplate/Language/ActionEvaluatorHelper.cs(71,30): error CS0115: 'ActionEvaluator.ReportError(RecognitionException)': no suitable method found to override
Antlr3.StringTemplate/Language/ActionParserHelper.cs(52,22): error CS0759: No defining declaration found for implementing declaration of partial method 'ActionParser.CreateTreeAdaptor(ref StringTemplateTreeAdaptor)'
Antlr3.StringTemplate/Language/ActionParserHelper.cs(57,30): error CS0115: 'ActionParser.ReportError(RecognitionException)': no suitable method found to override
Antlr3.StringTemplate/Language/AngleBracketTemplateLexerHelper.cs(50,30): error CS0115: 'AngleBracketTemplateLexer.ReportError(RecognitionException)': no suitable method found to override
Antlr3.StringTemplate/Language/AngleBracketTemplateLexerHelper.cs(55,34): error CS0115: 'AngleBracketTemplateLexer.TokenNames': no suitable method found to override
Antlr3.StringTemplate/Language/GroupParserHelper.cs(43,30): error CS0115: 'GroupParser.ReportError(RecognitionException)': no suitable method found to override
Antlr3.StringTemplate/Language/InterfaceParserHelper.cs(43,30): error CS0115: 'InterfaceParser.ReportError(RecognitionException)': no suitable method found to override
Antlr3.StringTemplate/Language/TemplateLexerHelper.cs(44,34): error CS0115: 'TemplateLexer.TokenNames': no suitable method found to override
Antlr3.StringTemplate/Language/TemplateLexerHelper.cs(58,30): error CS0115: 'TemplateLexer.ReportError(RecognitionException)': no suitable method found to override
Antlr3.StringTemplate/Language/TemplateParserHelper.cs(41,30): error CS0115: 'TemplateParser.ReportError(RecognitionException)': no suitable method found to override
Antlr4.StringTemplate/Compiler/Group.g3.lexer.cs(43,30): error CS0115: 'GroupLexer.ReportError(RecognitionException)': no suitable method found to override
Antlr4.StringTemplate/Compiler/Group.g3.lexer.cs(62,32): error CS0115: 'GroupLexer.SourceName': no suitable method found to override
Antlr4.StringTemplate/Compiler/Group.g3.parser.cs(56,30): error CS0115: 'GroupParser.DisplayRecognitionError(string[], RecognitionException)': no suitable method found to override
Antlr4.StringTemplate/Compiler/Group.g3.parser.cs(62,32): error CS0115: 'GroupParser.SourceName': no suitable method found to override
Antlr4.StringTemplate/Compiler/TemplateParser.g3.cs(50,35): error CS0115: 'TemplateParser.RecoverFromMismatchedToken(IIntStream, int, BitSet)': no suitable method found to override
Antlr4.StringTemplate/Debug/DebugTemplate.cs(79,34): error CS0115: 'DebugTemplate.CreateShadow(Template)': no suitable method found to override
Grammars/ANTLRLexerHelper.cs(48,34): error CS0115: 'ANTLRLexer.TokenNames': no suitable method found to override
Grammars/ANTLRLexerHelper.cs(56,32): error CS0115: 'ANTLRLexer.NextToken()': no suitable method found to override
Grammars/ANTLRParserHelper.cs(209,22): error CS0759: No defining declaration found for implementing declaration of partial method 'ANTLRParser.CreateTreeAdaptor(ref ITreeAdaptor)'
Grammars/ANTLRParserHelper.cs(333,30): error CS0115: 'ANTLRParser.ReportError(RecognitionException)': no suitable method found to override
Grammars/ANTLRTreePrinterHelper.cs(72,30): error CS0115: 'ANTLRTreePrinter.ReportError(RecognitionException)': no suitable method found to override
Grammars/AssignTokenTypesWalkerHelper.cs(50,30): error CS0115: 'AssignTokenTypesWalker.ReportError(RecognitionException)': no suitable method found to override
Grammars/CodeGenTreeWalkerHelper.cs(72,30): error CS0115: 'CodeGenTreeWalker.ReportError(RecognitionException)': no suitable method found to override
Grammars/LeftRecursiveRuleWalker.g3.cs(45,30): error CS0115: 'LeftRecursiveRuleWalker.ReportError(RecognitionException)': no suitable method found to override
Grammars/TreeToNFAConverterHelper.cs(151,30): error CS0115: 'TreeToNFAConverter.ReportError(RecognitionException)': no suitable method found to override
Tool/AssignTokenTypesBehavior.cs(45,18): error CS0060: Inconsistent accessibility: base class 'AssignTokenTypesWalker' is less accessible than class 'AssignTokenTypesBehavior'
Tool/Grammar.cs(3607,29): error CS0051: Inconsistent accessibility: parameter type 'TreeToNFAConverter' is less accessible than method 'Grammar.IsValidSet(TreeToNFAConverter, GrammarAST)'
Tool/Grammar.cs(3635,32): error CS0051: Inconsistent accessibility: parameter type 'TreeToNFAConverter' is less accessible than method 'Grammar.GetSetFromRule(TreeToNFAConverter, string)'
Tool/LeftRecursiveRuleAnalyzer.cs(49,18): error CS0060: Inconsistent accessibility: base class 'LeftRecursiveRuleWalker' is less accessible than class 'LeftRecursiveRuleAnalyzer'

Version Number mismatch

Hi,

This is more of a clarification on the versioning numbers used.
We have been updating our packages and we wanted to use Antlr3.Runtime version 3.5.2 RC. However when I added the package and looked at the reference properties I found that the Version is set at 3.5.0.2 rather than 3.5.2 is this correct?

From what I gathered 3.5.0.2 is for the Antlr3 package rather than the Antlr3.Runtime package.

image

C# StringTemplate4 throwing NullReferenceException

I have a directory containing several .st files. When I issue the following commands, the calling of GetInstanceOf throws NulReferenceException.

Both the directory and the "CGlobals.st" file cited below exists and are visible to the application.

Sample code:

 TemplateGroup group = new TemplateGroupDirectory(@"D:\Templates");
 var f = group.GetInstanceOf("CGlobals");

Check for 64-bit build

(from the ANTLR mailing list)

Make sure Antlr3.Runtime.dll is being built as an AnyCPU DLL.

Exception on osx/mono in Antlr4.StringTemplate.Visualizer.dll

When trying to run antlr on Mac OSX, mono crashes with the following error:

Missing method .ctor in assembly /path/to/antlr-dotnet-tool-3.5.0.2/Antlr4.StringTemplate.Visualizer.dll, type System.Windows.ThemeInfoAttribute
Can't find custom attr constructor image: /path/to/antlr-dotnet-tool-3.5.0.2/Antlr4.StringTemplate.Visualizer.dll mtoken: 0x0a00000d
* Assertion at class.c:5594, condition `!mono_loader_get_last_error ()' not met

The mono version is:

Mono JIT compiler version 3.2.3 ((no/8d3b4b7 Mon Sep 16 23:46:28 EDT 2013)
Copyright (C) 2002-2012 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           normal
        SIGSEGV:       altstack
        Notification:  kqueue
        Architecture:  x86
        Disabled:      none
        Misc:          softdebug
        LLVM:          yes(3.3svn-mono)
        GC:            sgen

The issue occurs because mono does not support WPF, and Antlr4.StringTemplate.Visualizer.dll uses WPF.

Looking into the code, I see the Antlr3 project has an assembly reference to Antlr4.StringTemplate.Visualizer.dll. The only place string visualization is used is in Antlr3\Codegen\CodeGenerator.cs and the code is all wrapped in "#if DEBUG" blocks.

Removing the Antlr4.StringTemplate.Visualizer.dll reference from Antlr3 and compiling in release mode fixes the issue. I'm happy to submit a pull request, but am not sure what the best solution is. The simplest fix would be for Antlr3 to conditionally link to Antlr4.StringTemplate.Visualizer.dll for debug builds only.

Separator output bug

When iterating over a list, separators for items skipped at the beginning of a list are not output, but once an item in the list is output, separators are output for subsequent items, even when items are skipped. The following C# code illustrates this. The output is: "2 is even," (note the trailing comma separator, but there isn't a comma before the 2, for the first skipped item)

static void Main (string [] args)
        {
        List <Item> items = new List <Item> () { new Item ("1", false), new Item ("2", true), new Item ("3",false)};
        string      string_template_group =
@"
even_params (parameters) ::=
<<
<parameters:{p|<if (p.is_even)><p.value> is even<endif>}; separator = "", "">
>>
";
        TemplateGroup   group = new TemplateGroupString (string_template_group);

        Template even_params = group.GetInstanceOf ("even_params");
        even_params.Add ("parameters", items);
        Console.WriteLine (even_params.Render ());
        }   // End Main

class Item
    {
    public string   value   { get; set; }
    public bool     is_even { get; set; }

    public Item (string V, bool E)
        {
        value = V;
        is_even = E;
        }

    }   // End class Item

dotnet build fails to build a project containing Antrl3 targets

Way to reproduce:

The simplest possible project:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard1.4</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <None Remove="**/*.g" />
  </ItemGroup>
  <ItemGroup>
    <Antlr3 Include="**/*.g" />
  </ItemGroup>

  <ItemGroup>
      <PackageReference Include="Antlr3" Version="3.5.1" />
  </ItemGroup>

</Project>

Some grammar files (one empty .g file should do the trick)

C:\Projects\ttt>dotnet build
Microsoft (R) Build Engine version 15.1.1012.6693
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Users\hazzik\.nuget\packages\antlr3\3.5.1\build\Antlr3.targets(126,5): error MSB4062: The "Antlr3.Build.Tasks.AntlrClassGenerationTask" task could not be loaded from the assembly C:\Users\hazzik\.nuget\pack
ages\antlr3\3.5.1\build\.\AntlrBuildTask.dll. Could not load file or assembly 'Microsoft.Build.Utilities.v3.5, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the fil
e specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.I
Task. [C:\Projects\ttt\ttt.csproj]

Build FAILED.

C:\Users\hazzik\.nuget\packages\antlr3\3.5.1\build\Antlr3.targets(126,5): error MSB4062: The "Antlr3.Build.Tasks.AntlrClassGenerationTask" task could not be loaded from the assembly C:\Users\hazzik\.nuget\pack
ages\antlr3\3.5.1\build\.\AntlrBuildTask.dll. Could not load file or assembly 'Microsoft.Build.Utilities.v3.5, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the fil
e specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.I
Task. [C:\Projects\ttt\ttt.csproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.82                                                                                                                                                                                     ```

Trying to write Grammer and Tree parser for SQL IN Operator

I Am new to the Antlr, Started Going through "The Definitive ANTLR Reference". And in one of the existing product Antlr is already used for SQL statement parsing, and For some filter technique in the UI we need to parse IN Operator inside Where Clause. With the Implementation what I have done, I am able to get the Half result. (Code is in Antlr Version 3)
Combinations of IN Operator
-- IN (21) -- Works correct, even for (21, 86, 155)
-- IN (50-100) -- Works correct even for Multiple Ranges ( (50-100, 120-200, 350-420))
-- IN (21, 50-100)
-- IN (50-100, 21, 150-200)
-- IN (21, 50-100, 155)
-- IN (21, 86, 50-100, 155)
And all other scenario's it's not working as expected as I am missing some thing.
This is What I have written in the Grammar file:

.........
.......
// in expression
inExpression
    :   field_name RESERVED_NOT? RESERVED_IN^ inCondition   
    ;

inCondition
    :   OPEN_PAREN! 
        ( (select_statement) => select_statement
        | (inElement) (COMMA! inElement)*)
        CLOSE_PAREN!
    ;

inElement
    : unary_expression
    | range_expression
    ;

...........
............
unary_expression
    : constant
    ;

// MCK
range_expression
    : unary_expression RANGE^ unary_expression
    ;

constant 
    : INT 
    | FLOAT 
    | STRING 
    | CHAR
    ;

In Tree Parser below is the Code which I have written, I am not able to figure out what needs to be done to support all the scanario's mentioned above for IN Operator.

joinCondition returns [SqlWhere cond = null;]
    @init {
        List<string> inList = new List<string>();
        bool notModifier = false;
        StringBuilder builder = new StringBuilder(255);
        List<string> rangeList = new List<string>();    
    }
: ^(RESERVED_IN field = fieldName (RESERVED_NOT { notModifier = true; })? ((node1 = unaryExpression 
        {       
            inList.Add(node1.Text);
        }
    )* 
    |
    (rlist = rangeExpression
        {
            foreach(CommonTree ritem in rlist)
            {
                rangeList.Add(ritem.Text);
            }
        }
    )* ) )
    {
        if(inList.Count > 0)
        {
            int i = 0;

            if (!field.IsComplex)
            {
                field.Parameters = parameters;

                // Append the field name into the buffer
                //builder.Append("(");
                builder.Append(field.ToString());

                // If the not modifier is being used
                if (notModifier)
                {
                    builder.Append(" NOT ");
                }

                // Place the paren
                builder.Append(" IN (");

                // Build the in list
                foreach (string inItem in inList)
                {
                    if (i == 0)
                    {
                        builder.Append(inItem);
                    }
                    else
                    {
                        builder.Append(", ");
                        builder.Append(inItem);
                    }
                    i++;
                }

                builder.Append(')');

                if (field.Type == ColumnType.ForeignKey)
                {
                    Query.AddSubQueryWhere(new SqlWhere(builder.ToString()));
                }
                else
                {
                    $cond = new SqlWhere(builder.ToString());
                }
            }
        }               
        if (rangeList.Count > 0)
        {
            int i = 0;
            // build the rangeList with BETWEEN and AND
            foreach(string rangeItem in rangeList)
            {
                if (i == 0 || ((i \% 2) == 0))
                {
                    if(inList.Count > 0 || i > 1)
                    {
                        builder.Append(" OR ");
                    }
                    builder.Append("(");
                    builder.Append(field.ToString());
                    builder.Append(" BETWEEN ");
                    builder.Append(rangeItem);
                    builder.Append(" AND ");
                }
                else
                {
                    builder.Append(rangeItem);
                    builder.Append(") ");
                }                           
                i++;            
            }
            if (field.Type == ColumnType.ForeignKey)
            {
                Query.AddSubQueryWhere(new SqlWhere(builder.ToString()));
            }
            else
            {
                $cond = new SqlWhere(builder.ToString());
            }
        }       
    }

...
.....
unaryExpression returns [string cons]
: #(UNARY_MINUS conString = constant)
{
$cons = String.Format("-{0}", conString);
}
| #(UNARY_PLUS conString = constant)
{
$cons = conString;
}
| conString = constant
{
$cons = conString;
}
;

// MCK
rangeExpression returns [List row]
@init
{
$row = new List();
}
: ^(RANGE left=unaryExpression right=unaryExpression)
{
$row.Add(left);
$row.Add(right);
}
;

constant returns [string cons]
: ni=INT
{
$cons = ni.Text;
}
| nf=FLOAT
{
$cons = nf.Text;
}
| sl=STRING
{
$cons = """ + sl.Text + """;
}
| cl=CHAR
{
$cons = cl.Text;
}
;

Please Suggest.
Thanks A Lot in Advance.

Best Regards
Mahantesh C K

Debugantlr problem

When I try to generate parser and lexer files from my grammar, Parser.cs inherits from DebugAntlr.Runtime.Parser which does not included in the reference assembly.

Build Error System.OutOfMemoryException

I am converting an old Java application to C# using VS2017 when I attempt to build a "larger" grammar I get an exception after a while
Antlr3.CodeGenerator.3.5.2-rc1\build\Antlr3.CodeGenerator.targets(146,5): error AC1000: Unknown build error: : error 10 : internal error: Grammar\BookPage.g3 : System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.

Instantiate TemplateGroupFile from URI expects local file path

Loading a template group file using a URI (as below) is expecting a local file path and not a web address.

            var templateGroupFile = new TemplateGroupFile(
                templateGroupS3Uri,
                Encoding.Default,
                '$',
                '$');
            var mainTemplate = templateGroupFile.GetInstanceOf(mainTemplateName);

I store my .stg files in an AWS S3 bucket because local file storage is not always available. I thought that the URI parameter would allow remote URIs.

Could be that I'm missing something?

What nuget package

I noticed you guys created like 20 nuget package that all look the same. Which one should I use that is the latest version? Is this library still being maintained?

TemplateGroupString.FileName is incorrect, causes errors

The TemplateGroupString.FileName property always returns "<string>" rather than the sourceName field value. Aside from being incorrect when one wants to query the file name, this also causes a bad failure in ErrorManager. The ErrorManager will attempt to parse the FileName during an error using Path.GetFileName(). However, since < is an illegal character, an exception is thrown by Path.GetFileName about invalid characters. This means that a compile error will result in an I/O error with no useful information, making the error reporting and debugging facility all but useless for string template groups.

Replacing the TemplateGroupString.FileName property to return the sourceName (in TemplateGroupString.cs) should fix the issue.

@leftfactor creates tokens with dollar signs in the generated parser

I tried specifying @leftfactor{rulename} in a grammar and some invalid tokens are generated in the xxxParser.cs:

RULE_var$lf$rulename = 0, RULE_var$nolf$rulename = 1,

doing a simple text replace of var$lf$rule in var_lf_rule and var$nolf$rule in var_nolf_rule solves the issue until the next regeneration of the grammar [so, not a showstopper].

AutoIndentWriter NullReferenceException

Submitted to java version as well at antlr/stringtemplate4#97 .

When processing a template that accesses an attribute returns is a null string, an exception is logged to the console:

context [anonymous] 1:0 internal error: System.NullReferenceException: Object re
ference not set to an instance of an object.
   at Antlr4.StringTemplate.AutoIndentWriter.Write(String value) in c:\dev\strin
gtemplate_main\antlrcs\main\Antlr4.StringTemplate\AutoIndentWriter.cs:line 179
   at Antlr4.StringTemplate.Interpreter.WritePlainObject(ITemplateWriter out, Te
mplateFrame frame, Object o, String[] options) in c:\dev\stringtemplate_main\ant
lrcs\main\Antlr4.StringTemplate\Interpreter.cs:line 905
   at Antlr4.StringTemplate.Interpreter.WriteObject(ITemplateWriter out, Templat
eFrame frame, Object o, String[] options) in c:\dev\stringtemplate_main\antlrcs\
main\Antlr4.StringTemplate\Interpreter.cs:line 836
   at Antlr4.StringTemplate.Interpreter.WriteObjectNoOptions(ITemplateWriter out
, TemplateFrame frame, Object o) in c:\dev\stringtemplate_main\antlrcs\main\Antl
r4.StringTemplate\Interpreter.cs:line 740
   at Antlr4.StringTemplate.Interpreter.ExecuteImpl(ITemplateWriter out, Templat
eFrame frame) in c:\dev\stringtemplate_main\antlrcs\main\Antlr4.StringTemplate\I
nterpreter.cs:line 328
   at Antlr4.StringTemplate.Interpreter.Execute(ITemplateWriter out, TemplateFra
me frame) in c:\dev\stringtemplate_main\antlrcs\main\Antlr4.StringTemplate\Inter
preter.cs:line 163
   at Antlr4.StringTemplate.AutoIndentWriter.Write(String value) in c:\dev\strin
gtemplate_main\antlrcs\main\Antlr4.StringTemplate\AutoIndentWriter.cs:line 179
   at Antlr4.StringTemplate.Interpreter.WritePlainObject(ITemplateWriter out, Te
mplateFrame frame, Object o, String[] options) in c:\dev\stringtemplate_main\ant
lrcs\main\Antlr4.StringTemplate\Interpreter.cs:line 905
   at Antlr4.StringTemplate.Interpreter.WriteObject(ITemplateWriter out, Templat
eFrame frame, Object o, String[] options) in c:\dev\stringtemplate_main\antlrcs\
main\Antlr4.StringTemplate\Interpreter.cs:line 836
   at Antlr4.StringTemplate.Interpreter.WriteObjectNoOptions(ITemplateWriter out
, TemplateFrame frame, Object o) in c:\dev\stringtemplate_main\antlrcs\main\Antl
r4.StringTemplate\Interpreter.cs:line 740
   at Antlr4.StringTemplate.Interpreter.ExecuteImpl(ITemplateWriter out, Templat
eFrame frame) in c:\dev\stringtemplate_main\antlrcs\main\Antlr4.StringTemplate\I
nterpreter.cs:line 328
   at Antlr4.StringTemplate.Interpreter.Execute(ITemplateWriter out, TemplateFra
me frame) in c:\dev\stringtemplate_main\antlrcs\main\Antlr4.StringTemplate\Inter
preter.cs:line 163

Likely issue:

In AutoIndentWriter.cs
public virtual int Write(string value) does not check if value is null before accessing value.Length .

I can provide more details reproduction steps if needed.

Does not work with indexer

Test is not working:

public class Row
    {
        readonly Dictionary<object,object> _values = new Dictionary<object, object>();

        public object this[ string key ]
        {
            get { return _values[key]; }
            set { _values[key] = value; }
        }
    }

    [Test]
    [Category(Categories.Home)]
    public void TestIndexerGetter( )
    {
        Row row = new Row();
        row["name"] = "alex";

        StringTemplate template = new StringTemplate( "Hello $row.Name$!" );
        template.SetAttribute( "row", row );
        Assert.That( template.ToString(), Is.EqualTo( "Hello alex!" ) );
    }

Intermittent build error in MSBuild or NCrunch or other possible tools

Can find a similar report and detailed analysis in http://forum.ncrunch.net/yaf_postst921_Intermittent-build-error-with-ANTLR-3.aspx

..\Reference\Antlr\Antlr3.targets (126)#0: Unknown build error: : error 10 : internal error: {my grammar file}.g3 : System.InvalidCastException: Unable to cast object of type 'Antlr3.Targets.CSharp3Target' to type 'Antlr3.Codegen.Target'. at Antlr3.Codegen.CodeGenerator.LoadLanguageTarget(String language, String targetsDirectory) in j:\dev\github\sharwell\antlrcs\Antlr3\Codegen\CodeGenerator.cs:line 358 at Antlr3.Tool.Grammar..ctor(AntlrTool tool, String fileName, CompositeGrammar composite) in j:\dev\github\sharwell\antlrcs\Antlr3\Tool\Grammar.cs:line 585 at Antlr3.AntlrTool.GetRootGrammar(String grammarFileName) in j:\dev\github\sharwell\antlrcs\Antlr3\AntlrTool.cs:line 776 at Antlr3.AntlrTool.Process() in j:\dev\github\sharwell\antlrcs\Antlr3\AntlrTool.cs:line 624 LoadLanguageTarget at offset 344 in file:line:column j:\dev\github\sharwell\antlrcs\Antlr3\Codegen\CodeGenerator.cs:358:21 .ctor at offset 932 in file:line:column j:\dev\github\sharwell\antlrcs\Antlr3\Tool\Grammar.cs:585:13 GetRootGrammar at offset 59 in file:line:column j:\dev\github\sharwell\antlrcs\Antlr3\AntlrTool.cs:776:13 Process at offset 398 in file:line:column j:\dev\github\sharwell\antlrcs\Antlr3\AntlrTool.cs:624:21

If a solution contains multiple projects that contain ANTLR grammars, then compiling the two at the same time (at VS command prompt or via NCrunch) can lead to such exceptions. There would be no exception when compiling in VS, as VS seems to use another way to build solution.

In CI systems, it is usually only MSBuild that builds the solutions. Thus, this issue is really annoying.

A workaround is to manually build the ANTLR projects one by one, and later the solution.

MSBuild project1.csproj
MSBuild project2.csproj
MSBuild solution.sln

Cascading import issue

Hi,

I need to embed 2 grammars X and Y in Z.

This is done by importing X in Y and Y and Z.

Unfortunately, this raises a minor bug in the C# version, where the reference to X in Y is marked as private, and cannot be accessed in Z.

The bug does not exist in the Java version.

StringTemplate4 cloned templates (shadow) work only once, subsequent calls render empty values

Here is a failing test
First template (t0) created with 'CreateShadow' works OK
Second (t1) does not, renders all model values as empty
ST4.0.8

`
public class Test
{
public string Name { get; set; }
public Test Parent { get; set; }
public string Title;
public decimal Age { get; set; }
public DateTime CreatedDate;

        public Test()
        {
            Name = "name of test";
            Title = "titel titel";
            Age = 198.88m;
            CreatedDate = DateTime.Now;
        }
    }

    [TestMethod]
    public void ReuseTemplateTest()
    {
        //temp\sttest is empty dir, just for test
        var stg = new TemplateRawGroupDirectory("c:\\temp\\sttest", '$', '$');

        var tpl = new Template(stg, "$model.Name$ $model.Title$");
        var mdl = new Test { Name = "zzzyzx", Title = "mmm" };
        var t0 = tpl.CreateShadow();
        t0.Add("model", mdl);
        var txt0 = t0.Render();
        Assert.IsTrue(txt0.Contains(mdl.Title) && txt0.Contains(mdl.Name));

        var t1 = tpl.CreateShadow();
        t1.Add("model", mdl);
        var txt1 = t1.Render();
        Assert.IsTrue(txt1.Contains(mdl.Title) && txt1.Contains(mdl.Name));
    }

`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.