Lexer now accepts files with no blank line at the end
This commit is contained in:
parent
13a36e43ba
commit
598e3412be
@ -56,8 +56,7 @@ Using a C compiler will link the C standard library to your program, which may
|
|||||||
be useful for building normal user applications.
|
be useful for building normal user applications.
|
||||||
|
|
||||||
## Bugs
|
## Bugs
|
||||||
There are a lot of them. But something to be wary of, especially on Windows:
|
This compiler has *many* bugs. If you come accross any please create an issue.
|
||||||
currently, the compiler only excepts files with a blank line at the end.
|
|
||||||
|
|
||||||
## Roadmap
|
## Roadmap
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ func (this *fsplLexer) nextInternal () (token lexer.Token, err error) {
|
|||||||
|
|
||||||
token.Pos = this.pos()
|
token.Pos = this.pos()
|
||||||
|
|
||||||
if this.eof == true {
|
if this.eof {
|
||||||
token.Type = EOF
|
token.Type = EOF
|
||||||
err = nil
|
err = nil
|
||||||
return
|
return
|
||||||
@ -105,6 +105,7 @@ func (this *fsplLexer) nextInternal () (token lexer.Token, err error) {
|
|||||||
token.Type = Int
|
token.Type = Int
|
||||||
for isDigit(this.rune) {
|
for isDigit(this.rune) {
|
||||||
appendRune()
|
appendRune()
|
||||||
|
if this.eof { err = nil; return }
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
}
|
}
|
||||||
if this.rune == '.' {
|
if this.rune == '.' {
|
||||||
@ -131,6 +132,7 @@ func (this *fsplLexer) nextInternal () (token lexer.Token, err error) {
|
|||||||
token.Type = Ident
|
token.Type = Ident
|
||||||
for unicode.IsLetter(this.rune) || isDigit(this.rune) {
|
for unicode.IsLetter(this.rune) || isDigit(this.rune) {
|
||||||
appendRune()
|
appendRune()
|
||||||
|
if this.eof { err = nil; return }
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
}
|
}
|
||||||
// TypeIdent
|
// TypeIdent
|
||||||
@ -138,6 +140,7 @@ func (this *fsplLexer) nextInternal () (token lexer.Token, err error) {
|
|||||||
token.Type = TypeIdent
|
token.Type = TypeIdent
|
||||||
for unicode.IsLetter(this.rune) || isDigit(this.rune) {
|
for unicode.IsLetter(this.rune) || isDigit(this.rune) {
|
||||||
appendRune()
|
appendRune()
|
||||||
|
if this.eof { err = nil; return }
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
}
|
}
|
||||||
// Int, Float
|
// Int, Float
|
||||||
@ -157,10 +160,12 @@ func (this *fsplLexer) nextInternal () (token lexer.Token, err error) {
|
|||||||
token.Value += string(result)
|
token.Value += string(result)
|
||||||
} else {
|
} else {
|
||||||
appendRune()
|
appendRune()
|
||||||
|
if this.eof { err = nil; return }
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = this.nextRune()
|
err = this.nextRune()
|
||||||
|
if this.eof { err = nil; return }
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
// Symbol, Int, Float
|
// Symbol, Int, Float
|
||||||
case this.rune == '-':
|
case this.rune == '-':
|
||||||
@ -169,12 +174,15 @@ func (this *fsplLexer) nextInternal () (token lexer.Token, err error) {
|
|||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
if isDigit(this.rune) {
|
if isDigit(this.rune) {
|
||||||
doNumber()
|
doNumber()
|
||||||
|
if this.eof { err = nil; return }
|
||||||
} else if isSymbol(this.rune) {
|
} else if isSymbol(this.rune) {
|
||||||
doSymbol()
|
doSymbol()
|
||||||
|
if this.eof { err = nil; return }
|
||||||
}
|
}
|
||||||
// Symbol
|
// Symbol
|
||||||
case isSymbol(this.rune):
|
case isSymbol(this.rune):
|
||||||
doSymbol()
|
doSymbol()
|
||||||
|
if this.eof { err = nil; return }
|
||||||
case this.rune == '(':
|
case this.rune == '(':
|
||||||
token.Type = LParen
|
token.Type = LParen
|
||||||
appendRune()
|
appendRune()
|
||||||
|
@ -97,3 +97,31 @@ tok(RParen, ")"),
|
|||||||
|
|
||||||
tok(EOF, ""),
|
tok(EOF, ""),
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
func TestLexerNoTrailingEOLInt (test *testing.T) {
|
||||||
|
testString(test,
|
||||||
|
`12345`,
|
||||||
|
tok(Int, "12345"),
|
||||||
|
tok(EOF, ""),
|
||||||
|
)}
|
||||||
|
|
||||||
|
func TestLexerNoTrailingEOLString (test *testing.T) {
|
||||||
|
testString(test,
|
||||||
|
`'12345'`,
|
||||||
|
tok(String, "12345"),
|
||||||
|
tok(EOF, ""),
|
||||||
|
)}
|
||||||
|
|
||||||
|
func TestLexerNoTrailingEOLIdent (test *testing.T) {
|
||||||
|
testString(test,
|
||||||
|
`hello`,
|
||||||
|
tok(Ident, "hello"),
|
||||||
|
tok(EOF, ""),
|
||||||
|
)}
|
||||||
|
|
||||||
|
func TestLexerNoTrailingEOLSymbol (test *testing.T) {
|
||||||
|
testString(test,
|
||||||
|
`@#$`,
|
||||||
|
tok(Symbol, "@#$"),
|
||||||
|
tok(EOF, ""),
|
||||||
|
)}
|
||||||
|
Loading…
Reference in New Issue
Block a user