From 22457f8cd8805903720d7c8b4cfec8e9dcb6758d Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Mon, 20 Feb 2017 08:59:14 +0100 Subject: [PATCH] cmd/easm: added comments ;; --- cmd/easm/lex_test.go | 20 ++++++++++++++++++++ cmd/easm/lexer.go | 11 +++++++++++ 2 files changed, 31 insertions(+) create mode 100644 cmd/easm/lex_test.go diff --git a/cmd/easm/lex_test.go b/cmd/easm/lex_test.go new file mode 100644 index 0000000000..a1b513c49e --- /dev/null +++ b/cmd/easm/lex_test.go @@ -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") + } +} diff --git a/cmd/easm/lexer.go b/cmd/easm/lexer.go index d7320f399d..eb46f52d46 100644 --- a/cmd/easm/lexer.go +++ b/cmd/easm/lexer.go @@ -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.