diff --git a/parser/body.go b/parser/body.go index 3174e13..e6ff997 100644 --- a/parser/body.go +++ b/parser/body.go @@ -57,6 +57,14 @@ func (parser *ParsingOperation) parseBody () (err error) { parser.tree.enumSections[section.name] = section if err != nil { return } case "func": + var section *FuncSection + section, err = parser.parseFuncSection() + if parser.tree.funcSections == nil { + parser.tree.funcSections = + make(map[string] *FuncSection) + } + parser.tree.funcSections[section.name] = section + if err != nil { return } default: err = parser.token.NewError ( "unknown section type \"" + sectionType + "\"", diff --git a/parser/func.go b/parser/func.go new file mode 100644 index 0000000..723e1b4 --- /dev/null +++ b/parser/func.go @@ -0,0 +1,30 @@ +package parser + +import "git.tebibyte.media/sashakoshka/arf/types" +import "git.tebibyte.media/sashakoshka/arf/lexer" +// import "git.tebibyte.media/sashakoshka/arf/infoerr" + +// parseFunc parses a function section. +func (parser *ParsingOperation) parseFuncSection () ( + section *FuncSection, + err error, +) { + err = parser.expect(lexer.TokenKindName) + if err != nil { return } + + section = &FuncSection { location: parser.token.Location() } + + err = parser.nextToken(lexer.TokenKindPermission) + if err != nil { return } + section.permission = parser.token.Value().(types.Permission) + + err = parser.nextToken(lexer.TokenKindName) + if err != nil { return } + section.name = parser.token.Value().(string) + + err = parser.nextToken(lexer.TokenKindNewline) + if err != nil { return } + + return +} + diff --git a/parser/func_test.go b/parser/func_test.go index 5fade6f..44e735c 100644 --- a/parser/func_test.go +++ b/parser/func_test.go @@ -2,7 +2,7 @@ package parser import "testing" -func TestData (test *testing.T) { +func TestFunc (test *testing.T) { checkTree ("../tests/parser/func", `:arf ---