diff --git a/compiler/parse/src/expr.rs b/compiler/parse/src/expr.rs index dfdd3a41aa..0d9a06b59e 100644 --- a/compiler/parse/src/expr.rs +++ b/compiler/parse/src/expr.rs @@ -12,7 +12,8 @@ use crate::parser::{ self, allocated, and_then_with_indent_level, ascii_char, ascii_string, attempt, backtrackable, map, newline_char, not, not_followed_by, optional, sep_by1, sep_by1_e, specialize, specialize_ref, then, trailing_sep_by0, unexpected, unexpected_eof, word1, word2, EExpr, - EInParens, ELambda, ERecord, Either, If, List, ParseResult, Parser, State, SyntaxError, When, + EInParens, ELambda, ERecord, EString, Either, If, List, Number, ParseResult, Parser, State, + SyntaxError, When, }; use crate::pattern::loc_closure_param; use crate::type_annotation; @@ -2225,6 +2226,20 @@ fn record_literal<'a>(min_indent: u16) -> impl Parser<'a, Expr<'a>, SyntaxError< ) } -pub fn string_literal<'a>() -> impl Parser<'a, Expr<'a>, SyntaxError<'a>> { - map!(crate::string_literal::parse(), Expr::Str) +fn string_literal<'a>() -> impl Parser<'a, Expr<'a>, SyntaxError<'a>> { + specialize( + |_, r, c| SyntaxError::Expr(EExpr::Str(EString::EndlessSingle, r, c)), + map!(crate::string_literal::parse(), Expr::Str), + ) +} + +fn string_literal_help<'a>() -> impl Parser<'a, Expr<'a>, EString> { + specialize( + |_, _, _| EString::EndlessSingle, + map!(crate::string_literal::parse(), Expr::Str), + ) +} + +fn number_literal_help<'a>() -> impl Parser<'a, Expr<'a>, Number> { + specialize(|_, _, _| Number::NumberEnd, number_literal()) } diff --git a/compiler/parse/src/parser.rs b/compiler/parse/src/parser.rs index 9e411c49ed..805691b95a 100644 --- a/compiler/parse/src/parser.rs +++ b/compiler/parse/src/parser.rs @@ -393,12 +393,35 @@ pub enum EExpr<'a> { InParens(EInParens<'a>, Row, Col), Record(ERecord<'a>, Row, Col), + Str(EString, Row, Col), + Number(Number, Row, Col), List(List<'a>, Row, Col), IndentStart(Row, Col), IndentEnd(Row, Col), } +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum Number { + NumberEnd, + NumberDot(i64), +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum EString { + EndlessSingle, + EndlessMulti, + StringEscape(Escape), +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Escape { + EscapeUnknown, + BadUnicodeFormat(u16), + BadUnicodeCode(u16), + BadUnicodeLength(u16, i32, i32), +} + #[derive(Debug, Clone, PartialEq, Eq)] pub enum ERecord<'a> { End(Row, Col),