Data section initialization values are now skimmed over

This commit is contained in:
Sasha Koshka 2022-09-05 15:04:39 -04:00
parent 613ccc3fba
commit ae0166b509
3 changed files with 20 additions and 7 deletions

View File

@ -28,6 +28,13 @@ func (parser *ParsingOperation) parseDataSection () (
section.what, err = parser.parseType()
if err != nil { return }
// skip the rest of the section if we are only skimming it
if parser.skimming {
section.external = true
err = parser.skipIndentLevel(1)
return
}
if parser.token.Is(lexer.TokenKindNewline) {
err = parser.nextToken()
if err != nil { return }

View File

@ -13,6 +13,7 @@ type ParsingOperation struct {
token lexer.Token
tokens []lexer.Token
tokenIndex int
skimming bool
tree SyntaxTree
}
@ -42,6 +43,7 @@ func Fetch (modulePath string, skim bool) (tree SyntaxTree, err error) {
// miss, so parse the module.
parser := ParsingOperation {
modulePath: modulePath,
skimming: skim,
tree: SyntaxTree {
sections: make(map[string] Section),
},
@ -155,13 +157,18 @@ func (parser *ParsingOperation) previousToken () {
// equal to or greater than the specified indent.
func (parser *ParsingOperation) skipIndentLevel (indent int) (err error) {
for {
if parser.token.Is(lexer.TokenKindNewline) {
err = parser.nextToken()
if err != nil { return }
if !parser.token.Is(lexer.TokenKindIndent) ||
parser.token.Value().(int) < indent {
return
}
}
err = parser.nextToken()
if err != nil { return }
if parser.token.Is(lexer.TokenKindIndent) &&
parser.token.Value().(int) < indent {
return
}
}
}

View File

@ -9,7 +9,6 @@ import "path/filepath"
func checkTree (modulePath string, skim bool, correct string, test *testing.T) {
cwd, _ := os.Getwd()
modulePath = filepath.Join(cwd, modulePath)
println(modulePath)
tree, err := Fetch(modulePath, skim)
treeString := tree.ToString(0)