Skip to content

Commit

Permalink
Merge 34d6705 into 5e90b88
Browse files Browse the repository at this point in the history
  • Loading branch information
gromgit committed Aug 5, 2020
2 parents 5e90b88 + 34d6705 commit b3a8a4c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
15 changes: 9 additions & 6 deletions lexer/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func (l *Lexer) newToken(tokenType token.TokenType) token.Token {
func (l *Lexer) NextToken() token.Token {
var tok token.Token

getNextToken:
l.skipWhitespace()

switch l.ch {
Expand Down Expand Up @@ -138,9 +139,10 @@ func (l *Lexer) NextToken() token.Token {
}
case '/':
if l.peekChar() == '/' {
tok.Type = token.COMMENT
tok.Position = l.position
tok.Literal = l.readLine()
// comment chunk - skip it
_ = l.readLine()
l.readChar()
goto getNextToken
} else if l.peekChar() == '=' {
tok.Type = token.COMP_SLASH
tok.Position = l.position
Expand All @@ -150,9 +152,10 @@ func (l *Lexer) NextToken() token.Token {
tok = l.newToken(token.SLASH)
}
case '#':
tok.Type = token.COMMENT
tok.Position = l.position
tok.Literal = l.readLine()
// comment chunk - skip it
_ = l.readLine()
l.readChar()
goto getNextToken
case '&':
if l.peekChar() == '&' {
tok.Type = token.AND
Expand Down
4 changes: 2 additions & 2 deletions lexer/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ f hello(x, y) {
{token.IDENT, "a"},
{token.DOT, "."},
{token.IDENT, "prop"},
{token.COMMENT, "# Comment"},
{token.COMMENT, "// Comment"},
{token.NUMBER, "1 # Comment"},
{token.TRUE, "true // Comment"},
{token.IDENT, "hello"},
{token.COMMAND, "command; command"},
{token.COMMAND, "command2; command2"},
Expand Down
1 change: 0 additions & 1 deletion parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ func New(l *lexer.Lexer) *Parser {
p.registerPrefix(token.LBRACKET, p.ParseArrayLiteral)
p.registerPrefix(token.LBRACE, p.ParseHashLiteral)
p.registerPrefix(token.COMMAND, p.parseCommand)
p.registerPrefix(token.COMMENT, p.parseComment)
p.registerPrefix(token.BREAK, p.parseBreak)
p.registerPrefix(token.CONTINUE, p.parseContinue)
p.registerPrefix(token.CURRENT_ARGS, p.parseCurrentArgsLiteral)
Expand Down
1 change: 0 additions & 1 deletion token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const (
IDENT = "IDENT" // add, foobar, x, y, ...
NUMBER = "NUMBER" // 1343456, 1.23456
STRING = "STRING" // "foobar"
COMMENT = "#" // # Comment
AT = "@" // @ At symbol
NULL = "NULL" // # null
CURRENT_ARGS = "..." // # ... function args
Expand Down

0 comments on commit b3a8a4c

Please sign in to comment.