问题描述
我正在使用 Sprache 来解析旧文件。
该文件具有与键值字典非常相似的以下结构:
Entity
{
propertyA simple
propertyB 10-1
propertyC "first"
propertyD "I am a line that spawns
to another line"
propertyE "second"
propertyF 1,2,3,4,5,6,\
7,8,9,10,11,\
12,13,14
propertyG "one","two","three",\
"four","five","six","seven",\
"eight","nine"
}
我能够正确处理文件,但当它有 "\" 行延续时不能。
我所做的唯一肮脏的 hack 是替换作为输入发送到解析器的字符串并替换字符,因此没有行继续:
public static Document ParseLegsacyFile(string input)
{
// HACK
return Document.Parse(input.Replace("\\\r\n",string.Empty));
}
我不想承担这个技术债务...
无论如何指示解析器忽略模式“\”和“\r\n”并替换为空字符串?
我已经尝试过“Except”(带“Or”)、“Return”和“Then”,但都没有成功。
这是我正在使用的解析器的一部分。以下仅针对“价值”部分:
public static readonly Parser<GenericObject> Value =
from value in Parse.AnyChar.Until(Parse.LineEnd).Text()
select new GenericObject(value);
private static readonly Parser<GenericString> SingleString =
from result in (from open in Parse.Char(Quote)
from content in Parse.CharExcept(Quote).Many().Text()
from close in Parse.Char(Quote)
select content).Token()
select new GenericString(result);
public static readonly Parser<GenericString> StringValue =
from value in SingleString .DelimitedBy(Parse.Char(Char.Parse(Comma)))
select new StringLiteral(string.Join(Comma,value));
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)