Lexer now eats :arf symbol at file beginning

This commit is contained in:
Sasha Koshka 2022-08-12 10:38:23 -05:00
parent c09c9860b8
commit f4f19a809a

View File

@ -28,6 +28,20 @@ func Tokenize (file *file.File) (tokens []Token, err error) {
// tokenize converts a file into a slice of tokens (lexemes). It will always // tokenize converts a file into a slice of tokens (lexemes). It will always
// return a non-nil error, but if nothing went wrong it will return io.EOF. // return a non-nil error, but if nothing went wrong it will return io.EOF.
func (lexer *LexingOperation) tokenize () (err error) { func (lexer *LexingOperation) tokenize () (err error) {
// check to see if the beginning of the file says :arf
var shebangCheck = []rune(":arf\n")
for index := 0; index < 5; index ++ {
err = lexer.nextRune()
if err != nil || shebangCheck[index] != lexer.char {
err = file.NewError (
lexer.file.Location(), 1,
"not an arf file",
file.ErrorKindError)
return
}
}
err = lexer.nextRune() err = lexer.nextRune()
if err != nil { return } if err != nil { return }