Prefixes in identifier terminals

May 20, 2014 at 8:39 PM
I try to use Irony.Net with this syntax:
!!test
!test1

there !!test - global variable
and !test1 - local variable

i wrote this code:
var local_identifier = new IdentifierTerminal("localidentifier","","!");
var global_identifier = new IdentifierTerminal("globalidentifier","","!!");
var param_identifier = new NonTerminal("paramidentifier");
param_identifier.Rule = local_identifier | global_identifier;

and i get shift-reduce error

What i am doing wrong?
Coordinator
May 20, 2014 at 9:08 PM
Edited May 20, 2014 at 9:09 PM
your global identifier is no different from local - the double ! is the same as single - these are 'allowed' characters, so if you allow !, you allow many of them. You should probably use special 'prefix' feature in identifier (look at using '@' character in c# identifier, in c# grammar sample)
As for shift-reduce conflict, it seems to me it is coming from different place, usually these 'inconsistencies' in internal term definitions are not manifested in grammar conflicts - they show up only in actual parsing, when scanner selects wrong terminal for an input string
Marked as answer by levich on 5/20/2014 at 1:30 PM
May 20, 2014 at 9:30 PM
Thank you!

I am use sample code from c# grammar sample as base.

This code solves my problem:
public static IdentifierTerminal CreateLocalIdentifier(string name)
        {
            var id = new IdentifierTerminal(name, IdOptions.None);
            id.AddPrefix("!", IdOptions.IsNotKeyword);
            id.StartCharCategories.AddRange(new[]
            {
                UnicodeCategory.UppercaseLetter, //Ul
                UnicodeCategory.LowercaseLetter, //Ll
                UnicodeCategory.TitlecaseLetter, //Lt
                UnicodeCategory.ModifierLetter, //Lm
                UnicodeCategory.OtherLetter, //Lo
                UnicodeCategory.LetterNumber //Nl
            });

            id.CharCategories.AddRange(new[]
            {
                UnicodeCategory.DecimalDigitNumber, //Nd
                UnicodeCategory.ConnectorPunctuation, //Pc
                UnicodeCategory.SpacingCombiningMark, //Mc
                UnicodeCategory.NonSpacingMark, //Mn
                UnicodeCategory.Format //Cf
            });
            id.CharsToRemoveCategories.Add(UnicodeCategory.Format);
            return id;
        }

        public static IdentifierTerminal CreateGlobalIdentifier(string name)
        {
            var id = new IdentifierTerminal(name, IdOptions.None);
            id.AddPrefix("!!", IdOptions.IsNotKeyword);
            id.StartCharCategories.AddRange(new[]
            {
                UnicodeCategory.UppercaseLetter, //Ul
                UnicodeCategory.LowercaseLetter, //Ll
                UnicodeCategory.TitlecaseLetter, //Lt
                UnicodeCategory.ModifierLetter, //Lm
                UnicodeCategory.OtherLetter, //Lo
                UnicodeCategory.LetterNumber //Nl
            });
            id.CharCategories.AddRange(new[]
            {
                UnicodeCategory.DecimalDigitNumber, //Nd
                UnicodeCategory.ConnectorPunctuation, //Pc
                UnicodeCategory.SpacingCombiningMark, //Mc
                UnicodeCategory.NonSpacingMark, //Mn
                UnicodeCategory.Format //Cf
            });
            id.CharsToRemoveCategories.Add(UnicodeCategory.Format);
            return id;
        }
May 20, 2014 at 9:44 PM
As for shift-reduce error, in my case error was in MakePlusRule

It was
member_params.Rule = Empty|MakePlusRule(member_params, null, member_param);
became
member_params.Rule = Empty|MakePlusRule(member_params, ToTerm(","), member_param);
Thanks again for the help.