[antlr-interest] ANTLR3 C# InvariantCultureIgnoreCase

Dr. Hartmut Kocher hwk.cortex-brainware at t-online.de
Wed May 9 15:52:56 PDT 2007


Here is a solution for C#:

/// <summary>
    /// Look ahead for tokenizing is all lowercase, whereas the original
case of e input stream is preserved.
    /// </summary>
    public class CaseInsensitiveStringStream : ANTLRStringStream {
        public CaseInsensitiveStringStream(char[] data, int
numberOfActualCharsInArray) : base(data, numberOfActualCharsInArray) {}
        public CaseInsensitiveStringStream() {}
        public CaseInsensitiveStringStream(string input) : base(input) {}

        public override int LA(int i) {
            if (i == 0) {
                return 0;
            }
            if (i < 0) {
                i++;
            }
            if (((p + i) - 1) >= n) {
                return (int) CharStreamConstants.EOF;
            }
            return Char.ToLowerInvariant(data[(p + i) - 1]);
        }
    }

Works for me...

Regards

Dr. Hartmut Kocher
Cortex Brainware Consulting & Training GmbH
Kirchplatz 5
D-82049 Pullach

Tel: +49 (89) 744  850 0
Fax: +49 (89) 744  850 11

http://www.cortex-brainware.de
Handelsregister:
Registergericht: Amtsgericht München
HRB-Nr. 120614

Vertretungsberechtigte Geschäftsführer:
Dipl.-Inform. Dorothea Burger, Dr.-Ing. Hartmut Kocher, Dr.-Ing. Martin
Lang, Dr. rer. nat. Rolf Peter Wehrum  

-----Ursprüngliche Nachricht-----
Von: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] Im Auftrag von Fabio Maulo
Gesendet: Donnerstag, 10. Mai 2007 00:46
An: antlr-interest at antlr.org
Betreff: Re: [antlr-interest] ANTLR3 C# InvariantCultureIgnoreCase

Thanks. I just know the URL....

well.... an embedded ANTLRInvariantCultureIgnoreCaseInputStream directly in
Antlr3.Runtime.dll for .NET 2.0 ?

I think many people appreciate it.
Fabio.


Alexandre Porcelli escribió:
> I think this URL answers better your question :
> http://www.antlr.org/wiki/pages/viewpage.action?pageId=1782
>
> On 5/9/07, Fabio Maulo <fabiomaulo at gmail.com> wrote:
>> In C#, version for ANTLR3, can we have an option to use
>> System.StringComparison for rule and grammar options?
>>
>> Basically for InvariantCultureIgnoreCase to emulete old caseSensitive
>> option.
>>
>> Fabio.
>>
>





More information about the antlr-interest mailing list