cmd/easm: added comments ;;

This commit is contained in:
Jeffrey Wilcke 2017-02-20 08:59:14 +01:00
parent c7e04bf4c3
commit 22457f8cd8
No known key found for this signature in database
GPG key ID: 63FF149CD6945F9E
2 changed files with 31 additions and 0 deletions

20
cmd/easm/lex_test.go Normal file
View file

@ -0,0 +1,20 @@
package main
import "testing"
func lexAll(src string) []item {
ch := lex("test.asm", []byte(src), false)
var tokens []item
for i := range ch {
tokens = append(tokens, i)
}
return tokens
}
func TestComment(t *testing.T) {
tokens := lexAll(";; this is a comment")
if len(tokens) != 2 { // {new line, EOF}
t.Error("expected no tokens")
}
}

View file

@ -186,6 +186,8 @@ func lexLine(l *Lexer) stateFn {
l.lineno++
l.emit(lineStart)
case r == ';' && l.peek() == ';':
return lexComment
case isSpace(r):
l.ignore()
case isAlphaNumeric(r) || r == '_':
@ -203,6 +205,15 @@ func lexLine(l *Lexer) stateFn {
}
}
// lexComment parses the current position until the end
// of the line and discards the text.
func lexComment(l *Lexer) stateFn {
l.acceptRunUntil('\n')
l.ignore()
return lexLine
}
// lexLabel parses the current label, emits and returns
// the lex text state function to advance the parsing
// process.