This project has moved and is read-only. For the latest updates, please go here.

RegexBasedTerminal vs IdentifierTerminal

Jul 21, 2011 at 11:29 AM


I am creating my first simple grammar - so I am a newbie. Included in this there are a couple of terminals

            Dim identifier = New IdentifierTerminal("identifier")
            Dim dataitem = New RegexBasedTerminal("dataitem", "M[1-9][0-9]{0,2}E[1-9][0-9]{0,2}I[1-9][0-9]{0,2}")

I am trying to  parse the string "M1E1I1"

At the moment it is recognising the string as an identifier rather than a dataitem. I have tried raising the precedence of the dataitem over the identifier. I have also tried inheriting an IdetifierTerminal into my own custom DataItemTerminal and also removing the identifier terminal in the OnScannerSelectTerminal override. If the latter, is there a sample for this since when I have tried to do this, I am getting a nullreferenceexception in GetUnfilteredTokens and I am struggling to work out what I am failing to configure properly to get my own terminal to dovetail into the mechanism.

What is the right way to do this with Irony?

Further, if I would identify the string M1E1I1Hello as an identifier rather than as a dataitem followed by an identifier, is that possible or would I need to included delimiters as in

Dim dataitemExpression = New NonTerminal("dataitemExpression", GetType(DataItemExpressionNode))

dataitemExpression.Rule = "[" + dataitem + "]"


Many thanks in advance




Jul 21, 2011 at 12:32 PM
Edited Jul 21, 2011 at 1:34 PM

OK .. so I realised I needed to set the terminal priority rather than precedence.

I'd be grateful if someone could confirm that is the right way to do it as well as advising me wrt my second question.

Many thx again


Jul 21, 2011 at 6:24 PM


Yes, setting priority is the right way to do this.

I don't quite understand what is your "second" question. Please provide more explanations what the problem is.


Jul 22, 2011 at 9:08 AM
Edited Jul 22, 2011 at 9:53 AM

Thx for the confirmation, Roman.

I realised I just needed to enhance my regex with a \b at the end to achieve what  I was after

Thx again