lang: Detect windows style CR and return a better error
If you get a sneaky \r in your code, the error just looks like whitespace, so this way we can warn you explicitly.
This commit is contained in:
@@ -384,8 +384,12 @@
|
||||
yylex.pos(lval) // our pos
|
||||
s := yylex.Text()
|
||||
lp := yylex.cast()
|
||||
e := ErrLexerUnrecognized
|
||||
if s == "\r" { // windows!
|
||||
e = ErrLexerUnrecognizedCR
|
||||
}
|
||||
lp.lexerErr = &LexParseErr{
|
||||
Err: ErrLexerUnrecognized,
|
||||
Err: e,
|
||||
Str: s,
|
||||
Row: yylex.Line(),
|
||||
Col: yylex.Column(),
|
||||
|
||||
@@ -46,6 +46,7 @@ const (
|
||||
// These constants represent the different possible lexer/parser errors.
|
||||
const (
|
||||
ErrLexerUnrecognized = interfaces.Error("unrecognized")
|
||||
ErrLexerUnrecognizedCR = interfaces.Error("unrecognized carriage return")
|
||||
ErrLexerStringBadEscaping = interfaces.Error("string: bad escaping")
|
||||
ErrLexerIntegerOverflow = interfaces.Error("integer: overflow")
|
||||
ErrLexerFloatOverflow = interfaces.Error("float: overflow")
|
||||
|
||||
Reference in New Issue
Block a user