Bitshift
This commit is contained in:
@@ -116,6 +116,11 @@ func (l *Lexer) NextToken() token.Token {
|
||||
l.readChar()
|
||||
tok = newToken(token.LTE, l.ch)
|
||||
tok.Literal = "<="
|
||||
} else if l.peekChar() == '<' {
|
||||
ch := l.ch
|
||||
l.readChar()
|
||||
literal := string(ch) + string(l.ch)
|
||||
tok = token.Token{Type: token.LEFT_SHIFT, Literal: literal}
|
||||
} else {
|
||||
tok = newToken(token.LT, l.ch)
|
||||
}
|
||||
@@ -124,6 +129,11 @@ func (l *Lexer) NextToken() token.Token {
|
||||
l.readChar()
|
||||
tok = newToken(token.GTE, l.ch)
|
||||
tok.Literal = ">="
|
||||
} else if l.peekChar() == '>' {
|
||||
ch := l.ch
|
||||
l.readChar()
|
||||
literal := string(ch) + string(l.ch)
|
||||
tok = token.Token{Type: token.RIGHT_SHIFT, Literal: literal}
|
||||
} else {
|
||||
tok = newToken(token.GT, l.ch)
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ func TestNextToken(t *testing.T) {
|
||||
d.foo
|
||||
&|^~
|
||||
!&&||
|
||||
<<>>
|
||||
`
|
||||
|
||||
tests := []struct {
|
||||
@@ -146,6 +147,8 @@ func TestNextToken(t *testing.T) {
|
||||
{token.NOT, "!"},
|
||||
{token.AND, "&&"},
|
||||
{token.OR, "||"},
|
||||
{token.LEFT_SHIFT, "<<"},
|
||||
{token.RIGHT_SHIFT, ">>"},
|
||||
{token.EOF, ""},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user