Tree returns a section interface when given a name
This commit is contained in:
parent
d930e72c0c
commit
9269161138
@ -1,5 +1,12 @@
|
|||||||
package parser
|
package parser
|
||||||
|
|
||||||
|
// LookupSection looks returns the section under the give name. If the section
|
||||||
|
// does not exist, nil is returned.
|
||||||
|
func (tree *SyntaxTree) LookupSection (name string) (section Section) {
|
||||||
|
section = tree.sections[name]
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Kind returns the section's kind (SectionKindType).
|
// Kind returns the section's kind (SectionKindType).
|
||||||
func (section TypeSection) Kind () (kind SectionKind) {
|
func (section TypeSection) Kind () (kind SectionKind) {
|
||||||
kind = SectionKindType
|
kind = SectionKindType
|
||||||
|
@ -10,8 +10,8 @@ func (parser *ParsingOperation) parseBody () (err error) {
|
|||||||
for {
|
for {
|
||||||
err = parser.expect(lexer.TokenKindName)
|
err = parser.expect(lexer.TokenKindName)
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
sectionType := parser.token.Value().(string)
|
sectionType := parser.token.Value().(string)
|
||||||
|
|
||||||
switch sectionType {
|
switch sectionType {
|
||||||
case "data":
|
case "data":
|
||||||
var section *DataSection
|
var section *DataSection
|
||||||
@ -21,7 +21,9 @@ func (parser *ParsingOperation) parseBody () (err error) {
|
|||||||
make(map[string] *DataSection)
|
make(map[string] *DataSection)
|
||||||
}
|
}
|
||||||
parser.tree.dataSections[section.name] = section
|
parser.tree.dataSections[section.name] = section
|
||||||
|
parser.tree.sections[section.name] = section
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
case "type":
|
case "type":
|
||||||
var section *TypeSection
|
var section *TypeSection
|
||||||
section, err = parser.parseTypeSection()
|
section, err = parser.parseTypeSection()
|
||||||
@ -30,7 +32,9 @@ func (parser *ParsingOperation) parseBody () (err error) {
|
|||||||
make(map[string] *TypeSection)
|
make(map[string] *TypeSection)
|
||||||
}
|
}
|
||||||
parser.tree.typeSections[section.name] = section
|
parser.tree.typeSections[section.name] = section
|
||||||
|
parser.tree.sections[section.name] = section
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
case "objt":
|
case "objt":
|
||||||
var section *ObjtSection
|
var section *ObjtSection
|
||||||
section, err = parser.parseObjtSection()
|
section, err = parser.parseObjtSection()
|
||||||
@ -39,7 +43,9 @@ func (parser *ParsingOperation) parseBody () (err error) {
|
|||||||
make(map[string] *ObjtSection)
|
make(map[string] *ObjtSection)
|
||||||
}
|
}
|
||||||
parser.tree.objtSections[section.name] = section
|
parser.tree.objtSections[section.name] = section
|
||||||
|
parser.tree.sections[section.name] = section
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
case "face":
|
case "face":
|
||||||
var section *FaceSection
|
var section *FaceSection
|
||||||
section, err = parser.parseFaceSection()
|
section, err = parser.parseFaceSection()
|
||||||
@ -48,7 +54,9 @@ func (parser *ParsingOperation) parseBody () (err error) {
|
|||||||
make(map[string] *FaceSection)
|
make(map[string] *FaceSection)
|
||||||
}
|
}
|
||||||
parser.tree.faceSections[section.name] = section
|
parser.tree.faceSections[section.name] = section
|
||||||
|
parser.tree.sections[section.name] = section
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
case "enum":
|
case "enum":
|
||||||
var section *EnumSection
|
var section *EnumSection
|
||||||
section, err = parser.parseEnumSection()
|
section, err = parser.parseEnumSection()
|
||||||
@ -57,7 +65,9 @@ func (parser *ParsingOperation) parseBody () (err error) {
|
|||||||
make(map[string] *EnumSection)
|
make(map[string] *EnumSection)
|
||||||
}
|
}
|
||||||
parser.tree.enumSections[section.name] = section
|
parser.tree.enumSections[section.name] = section
|
||||||
|
parser.tree.sections[section.name] = section
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
case "func":
|
case "func":
|
||||||
var section *FuncSection
|
var section *FuncSection
|
||||||
section, err = parser.parseFuncSection()
|
section, err = parser.parseFuncSection()
|
||||||
@ -66,7 +76,9 @@ func (parser *ParsingOperation) parseBody () (err error) {
|
|||||||
make(map[string] *FuncSection)
|
make(map[string] *FuncSection)
|
||||||
}
|
}
|
||||||
parser.tree.funcSections[section.name] = section
|
parser.tree.funcSections[section.name] = section
|
||||||
|
parser.tree.sections[section.name] = section
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
default:
|
default:
|
||||||
err = parser.token.NewError (
|
err = parser.token.NewError (
|
||||||
"unknown section type \"" + sectionType + "\"",
|
"unknown section type \"" + sectionType + "\"",
|
||||||
|
@ -10,7 +10,9 @@ type SyntaxTree struct {
|
|||||||
license string
|
license string
|
||||||
author string
|
author string
|
||||||
|
|
||||||
requires []string
|
requires []string
|
||||||
|
sections map[string] Section
|
||||||
|
|
||||||
typeSections map[string] *TypeSection
|
typeSections map[string] *TypeSection
|
||||||
objtSections map[string] *ObjtSection
|
objtSections map[string] *ObjtSection
|
||||||
enumSections map[string] *EnumSection
|
enumSections map[string] *EnumSection
|
||||||
|
Reference in New Issue
Block a user