je dois analyser un fichier qui ressemble à ceci:Puis-je améliorer cette grammaire PARser 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)"
}
}
}
J'ai un analyseur écrit à partir de zéro, mais il a quelques bugs que je ne peux pas traquer et j'imagine que ce sera difficile de maintenir si le format change dans le futur. J'ai décidé d'utiliser le système d'analyse d'or pour générer un analyseur à la place. Ma grammaire ressemble à ceci:
"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
Il n'y a pas d'erreurs et parse mon fichier de test 2000 en ligne très bien. Cependant, c'est la première fois que j'écris une grammaire personnalisée, donc je ne suis pas sûr de la faire correctement.
Y a-t-il des améliorations que je pourrais apporter à la grammaire ci-dessus?