we in era3 boys; overhauled expression system, and variables are now in maps
This commit is contained in:
parent
bf29e6c3dd
commit
43e450c207
14 changed files with 945 additions and 452 deletions
|
|
@ -9,13 +9,13 @@ import (
|
|||
type Token struct {
|
||||
Type TokenType
|
||||
Start Pos
|
||||
Length Pos
|
||||
End Pos
|
||||
Line Pos
|
||||
Lexeme string
|
||||
}
|
||||
|
||||
func (t Token) String() string {
|
||||
return fmt.Sprintf("token %s, '%s' %d -> %d, line %d", t.Type.String(), t.Lexeme, t.Start, t.Length, t.Line)
|
||||
return fmt.Sprintf("token %s, '%s' %d -> %d, line %d", t.Type.String(), t.Lexeme, t.Start, t.End, t.Line)
|
||||
}
|
||||
|
||||
type TokenType uint64
|
||||
|
|
@ -71,6 +71,7 @@ const (
|
|||
TokenPipe
|
||||
TokenDoublePipe
|
||||
|
||||
TokenNewLine
|
||||
TokenBreakpoint
|
||||
TokenEOF
|
||||
TokenError
|
||||
|
|
@ -168,6 +169,8 @@ func (t TokenType) String() string {
|
|||
return "hexadecimal"
|
||||
case TokenArrow:
|
||||
return "arrow"
|
||||
case TokenNewLine:
|
||||
return "newline"
|
||||
}
|
||||
|
||||
panic("UNDEFINED TOKENTYPE STRING CONVERSION")
|
||||
|
|
@ -212,6 +215,8 @@ func (l *Lexer) NextToken() (Token, error) {
|
|||
l.advance()
|
||||
|
||||
switch c {
|
||||
case '\n':
|
||||
return l.makeToken(TokenNewLine), nil
|
||||
case '+':
|
||||
return l.makeToken(TokenPlus), nil
|
||||
case '-':
|
||||
|
|
@ -395,11 +400,11 @@ func (l *Lexer) NextToken() (Token, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func NewToken(t TokenType, start Pos, length Pos, line Pos, lexeme string) Token {
|
||||
func NewToken(t TokenType, start Pos, end Pos, line Pos, lexeme string) Token {
|
||||
return Token{
|
||||
Type: t,
|
||||
Start: start,
|
||||
Length: length,
|
||||
End: end,
|
||||
Line: line,
|
||||
Lexeme: lexeme,
|
||||
}
|
||||
|
|
@ -421,7 +426,7 @@ func (l *Lexer) Tokenize() ([]Token, error) {
|
|||
}
|
||||
|
||||
func (l *Lexer) makeToken(t TokenType) Token {
|
||||
return NewToken(t, l.start, l.current-l.start, l.line, string(l.src[l.start:l.current]))
|
||||
return NewToken(t, l.start, l.current, l.line, string(l.src[l.start:l.current]))
|
||||
}
|
||||
|
||||
func (l *Lexer) peek() rune {
|
||||
|
|
@ -470,7 +475,7 @@ func (l *Lexer) isAtEnd() bool {
|
|||
}
|
||||
|
||||
func (l *Lexer) skipWhitespace() {
|
||||
for !l.isAtEnd() && unicode.IsSpace(l.peek()) {
|
||||
for !l.isAtEnd() && unicode.IsSpace(l.peek()) && l.peek() != '\n' {
|
||||
l.advance()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue