Parser has been updated to handle new syntax

This commit is contained in:
Sasha Koshka 2022-09-05 11:28:27 -04:00
parent 0b71ab8787
commit 5127b80630
3 changed files with 31 additions and 30 deletions

View File

@ -15,37 +15,37 @@ func (parser *ParsingOperation) parseBody () (err error) {
section, parseErr := parser.parseDataSection() section, parseErr := parser.parseDataSection()
err = parser.tree.addSection(section) err = parser.tree.addSection(section)
if err != nil { return } if err != nil { return }
if parseErr != nil { return } if parseErr != nil { return parseErr }
case "type": case "type":
section, parseErr := parser.parseTypeSection() section, parseErr := parser.parseTypeSection()
err = parser.tree.addSection(section) err = parser.tree.addSection(section)
if err != nil { return } if err != nil { return }
if parseErr != nil { return } if parseErr != nil { return parseErr }
case "objt": case "objt":
section, parseErr := parser.parseObjtSection() section, parseErr := parser.parseObjtSection()
err = parser.tree.addSection(section) err = parser.tree.addSection(section)
if err != nil { return } if err != nil { return }
if parseErr != nil { return } if parseErr != nil { return parseErr }
case "face": case "face":
section, parseErr := parser.parseFaceSection() section, parseErr := parser.parseFaceSection()
err = parser.tree.addSection(section) err = parser.tree.addSection(section)
if err != nil { return } if err != nil { return }
if parseErr != nil { return } if parseErr != nil { return parseErr }
case "enum": case "enum":
section, parseErr := parser.parseEnumSection() section, parseErr := parser.parseEnumSection()
err = parser.tree.addSection(section) err = parser.tree.addSection(section)
if err != nil { return } if err != nil { return }
if parseErr != nil { return } if parseErr != nil { return parseErr }
case "func": case "func":
section, parseErr := parser.parseFuncSection() section, parseErr := parser.parseFuncSection()
err = parser.tree.addSection(section) err = parser.tree.addSection(section)
if err != nil { return } if err != nil { return }
if parseErr != nil { return } if parseErr != nil { return parseErr }
default: default:
err = parser.token.NewError ( err = parser.token.NewError (

View File

@ -25,15 +25,15 @@ data ro gIntegerArrayInitialized:Int:16
4785 4785
92 92
data ro jObject:thing.Thing.thing.thing data ro jObject:thing.Thing.thing.thing
.this 324
.that 2139 .that 2139
.this 324
data ro kNestedObject:Obj data ro kNestedObject:Obj
.this
.bird0 324
.bird1 "hello world"
.that .that
.bird2 123.8439 .bird2 123.8439
.bird3 9328.21348239 .bird3 9328.21348239
.this
.bird0 324
.bird1 "hello world"
data ro lMutIntegerArray16:Int:16:mut data ro lMutIntegerArray16:Int:16:mut
data ro mIntegerArrayInitialized:Int:16:mut data ro mIntegerArrayInitialized:Int:16:mut
3948 3948

View File

@ -44,19 +44,11 @@ func (parser *ParsingOperation) parseType () (what Type, err error) {
what.points = &points what.points = &points
err = parser.expect ( err = parser.expect (
lexer.TokenKindUInt,
lexer.TokenKindRBrace, lexer.TokenKindRBrace,
lexer.TokenKindElipsis) lexer.TokenKindElipsis)
if err != nil { return } if err != nil { return }
if parser.token.Is(lexer.TokenKindUInt) { if parser.token.Is(lexer.TokenKindElipsis) {
what.kind = TypeKindArray
what.length = parser.token.Value().(uint64)
err = parser.nextToken(lexer.TokenKindRBrace)
if err != nil { return }
} else if parser.token.Is(lexer.TokenKindElipsis) {
what.kind = TypeKindVariableArray what.kind = TypeKindVariableArray
err = parser.nextToken(lexer.TokenKindRBrace) err = parser.nextToken(lexer.TokenKindRBrace)
@ -70,19 +62,28 @@ func (parser *ParsingOperation) parseType () (what Type, err error) {
if err != nil { return } if err != nil { return }
} }
if parser.token.Is(lexer.TokenKindColon) { for {
err = parser.nextToken(lexer.TokenKindName) if !parser.token.Is(lexer.TokenKindColon) { break }
err = parser.nextToken(lexer.TokenKindName, lexer.TokenKindUInt)
if err != nil { return } if err != nil { return }
qualifier := parser.token.Value().(string) if parser.token.Is(lexer.TokenKindName) {
switch qualifier { // parse type qualifier
case "mut": qualifier := parser.token.Value().(string)
what.mutable = true switch qualifier {
default: case "mut":
err = parser.token.NewError ( what.mutable = true
"unknown type qualifier \"" + qualifier + "\"", default:
infoerr.ErrorKindError) err = parser.token.NewError (
return "unknown type qualifier \"" +
qualifier + "\"",
infoerr.ErrorKindError)
return
}
} else {
// parse fixed array length
what.length = parser.token.Value().(uint64)
} }
err = parser.nextToken() err = parser.nextToken()