我要解析看起來像這樣的文件:我可以改進這個GOLD解析器語法嗎?
versioninfo
{
"editorversion" "400"
"editorbuild" "4715"
}
visgroups
{
}
world
{
"id" "1"
"mapversion" "525"
"classname" "worldspawn"
solid
{
"id" "2"
side
{
"id" "1"
"plane" "(-544 -400 0) (-544 -240 0) (-272 -240 0)"
}
side
{
"id" "2"
"plane" "(-544 -240 -16) (-544 -400 -16) (-272 -400 -16)"
}
}
}
我必須從頭開始編寫的解析器,但它有我不能追查一些錯誤,我想這將是困難的如果格式在未來發生變化,請維持。我決定使用GOLD Parsing System來生成解析器。我的語法如下:
"Start Symbol" = <SectionList>
! SETS
{Section Chars} = {AlphaNumeric} + [_]
{Property Chars} = {Printable} - ["]
! TERMINALS
SectionName = {Section Chars}+
PropertyPart = '"' {Property Chars}* '"'
! RULES
<SectionList> ::= <Section>
| <Section> <SectionList>
<SectionBody> ::= <PropertyList>
| <SectionList>
| <PropertyList> <SectionList>
<Section> ::= SectionName '{' '}'
| SectionName '{' <SectionBody> '}'
<PropertyList> ::= <Property>
| <Property> <PropertyList>
<Property> ::= PropertyPart PropertyPart
沒有錯誤,它解析我的2000行測試文件就好了。然而,這是我第一次編寫自定義語法,所以我不確定我是否正確地做了。
我可以對上面的語法做任何改進嗎?下面