Added base function parsing

This commit is contained in:
Sasha Koshka 2022-08-25 20:01:12 -04:00
parent 723b506005
commit c3b6330b22
3 changed files with 39 additions and 1 deletions

View File

@ -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 + "\"",

30
parser/func.go Normal file
View File

@ -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
}

View File

@ -2,7 +2,7 @@ package parser
import "testing"
func TestData (test *testing.T) {
func TestFunc (test *testing.T) {
checkTree ("../tests/parser/func",
`:arf
---