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
|
yylex.pos(lval) // our pos
|
||||||
s := yylex.Text()
|
s := yylex.Text()
|
||||||
lp := yylex.cast()
|
lp := yylex.cast()
|
||||||
|
e := ErrLexerUnrecognized
|
||||||
|
if s == "\r" { // windows!
|
||||||
|
e = ErrLexerUnrecognizedCR
|
||||||
|
}
|
||||||
lp.lexerErr = &LexParseErr{
|
lp.lexerErr = &LexParseErr{
|
||||||
Err: ErrLexerUnrecognized,
|
Err: e,
|
||||||
Str: s,
|
Str: s,
|
||||||
Row: yylex.Line(),
|
Row: yylex.Line(),
|
||||||
Col: yylex.Column(),
|
Col: yylex.Column(),
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ const (
|
|||||||
// These constants represent the different possible lexer/parser errors.
|
// These constants represent the different possible lexer/parser errors.
|
||||||
const (
|
const (
|
||||||
ErrLexerUnrecognized = interfaces.Error("unrecognized")
|
ErrLexerUnrecognized = interfaces.Error("unrecognized")
|
||||||
|
ErrLexerUnrecognizedCR = interfaces.Error("unrecognized carriage return")
|
||||||
ErrLexerStringBadEscaping = interfaces.Error("string: bad escaping")
|
ErrLexerStringBadEscaping = interfaces.Error("string: bad escaping")
|
||||||
ErrLexerIntegerOverflow = interfaces.Error("integer: overflow")
|
ErrLexerIntegerOverflow = interfaces.Error("integer: overflow")
|
||||||
ErrLexerFloatOverflow = interfaces.Error("float: overflow")
|
ErrLexerFloatOverflow = interfaces.Error("float: overflow")
|
||||||
|
|||||||
Reference in New Issue
Block a user