次のようなファイルを解析する必要があります。
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解析システムを使用してパーサーを生成することにしました。私の文法は次のようになります。
"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行のテストファイルを問題なく解析します。ただし、カスタム文法を書くのは初めてなので、正しく書いているかどうかはわかりません。
上記の文法に改善を加えることができますか?