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,20 +62,29 @@ 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 }
if parser.token.Is(lexer.TokenKindName) {
// parse type qualifier
qualifier := parser.token.Value().(string) qualifier := parser.token.Value().(string)
switch qualifier { switch qualifier {
case "mut": case "mut":
what.mutable = true what.mutable = true
default: default:
err = parser.token.NewError ( err = parser.token.NewError (
"unknown type qualifier \"" + qualifier + "\"", "unknown type qualifier \"" +
qualifier + "\"",
infoerr.ErrorKindError) infoerr.ErrorKindError)
return return
} }
} else {
// parse fixed array length
what.length = parser.token.Value().(uint64)
}
err = parser.nextToken() err = parser.nextToken()
if err != nil { return } if err != nil { return }