英文:
Irony parse null value in c#
问题
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 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?
答案1
得分: 1
这个正则表达式匹配了"NULL",然后你可以无错误地进行解析。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论