I am looking for a way to parse a string (key-value pair) that has null value. I am using Irony nuget in c#.
Example string 1: key = "value"
Example string 2: key = null
I am able to parse Example string 1 using the below way:
var stringLiteral = new StringLiteral("String", "\"");
var filterRule = new BnfExpression();
filterRule |= ((new NonTerminal("Key") { Rule = "Key" }) + (new NonTerminal("ComparisonOp")) + stringLiteral);
I am not quite sure with Example string 2. Is there actually a way to parse nullable values in Irony?
I guess I found an answer to this. Posting here so someone with the same requirement can get it.
var nullLiteral = new RegexBasedTerminal("Nullable", "(NULL)");
var filterRule = new BnfExpression();
filterRule |= ((new NonTerminal("Key") { Rule = "Key" }) + (new NonTerminal("ComparisonOp")) + nullLiteral );
This regular expression gets the null match and then you can parse without errors.