Skip to content

Commit

Permalink
parser: stop after parsing end psuedo op line (#82)
Browse files Browse the repository at this point in the history
compile_test88: 47 -> 45 errors
  • Loading branch information
bobertlo authored Nov 20, 2024
1 parent 4c8a3e3 commit 91b1a4e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type parser struct {
err error
currentLine sourceLine
metadata WarriorData
endSeen bool

// collected lines
lines []sourceLine
Expand Down Expand Up @@ -172,6 +173,10 @@ func (p *parser) consumeEmitLine(nextState parseStateFn) parseStateFn {
// eof: nil
// anything else: error
func parseLine(p *parser) parseStateFn {
if p.endSeen {
return nil
}

p.currentLine = sourceLine{line: p.line}

switch p.nextToken.typ {
Expand Down Expand Up @@ -298,6 +303,10 @@ func parsePseudoOp(p *parser) parseStateFn {
p.currentLine.op = p.nextToken.val
p.currentLine.typ = linePseudoOp

if strings.ToLower(p.nextToken.val) == "end" {
p.endSeen = true
}

lastToken := p.nextToken
p.next()

Expand Down
1 change: 1 addition & 0 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ func TestParserNoError(t *testing.T) {
"dat 0\n",
"label: label2: dat 0",
"label: : dat 0",
"end\n\n--",
}

for _, val := range testCases {
Expand Down

0 comments on commit 91b1a4e

Please sign in to comment.