mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
cmd/easm: added comments ;;
This commit is contained in:
parent
c7e04bf4c3
commit
22457f8cd8
2 changed files with 31 additions and 0 deletions
20
cmd/easm/lex_test.go
Normal file
20
cmd/easm/lex_test.go
Normal 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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -186,6 +186,8 @@ func lexLine(l *Lexer) stateFn {
|
||||||
l.lineno++
|
l.lineno++
|
||||||
|
|
||||||
l.emit(lineStart)
|
l.emit(lineStart)
|
||||||
|
case r == ';' && l.peek() == ';':
|
||||||
|
return lexComment
|
||||||
case isSpace(r):
|
case isSpace(r):
|
||||||
l.ignore()
|
l.ignore()
|
||||||
case isAlphaNumeric(r) || r == '_':
|
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
|
// lexLabel parses the current label, emits and returns
|
||||||
// the lex text state function to advance the parsing
|
// the lex text state function to advance the parsing
|
||||||
// process.
|
// process.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue