Merge pull request #4863 from joshuawarner32/better-scalar-literals

Improve parsing of scalar literals
This commit is contained in:
Richard Feldman 2023-01-09 11:42:44 -05:00 committed by GitHub
commit ab7de647e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 411 additions and 173 deletions

View file

@ -18,7 +18,7 @@ use roc_module::called_via::CalledVia;
use roc_module::ident::{ForeignSymbol, Lowercase, TagName};
use roc_module::low_level::LowLevel;
use roc_module::symbol::Symbol;
use roc_parse::ast::{self, Defs, EscapedChar, StrLiteral};
use roc_parse::ast::{self, Defs, StrLiteral};
use roc_parse::pattern::PatternType::*;
use roc_problem::can::{PrecedenceProblem, Problem, RuntimeError};
use roc_region::all::{Loc, Region};
@ -2297,7 +2297,7 @@ fn flatten_str_lines<'a>(
);
}
}
EscapedChar(escaped) => buf.push(unescape_char(escaped)),
EscapedChar(escaped) => buf.push(escaped.unescape()),
}
}
}
@ -2355,19 +2355,6 @@ fn desugar_str_segments(var_store: &mut VarStore, segments: Vec<StrSegment>) ->
loc_expr.value
}
/// Returns the char that would have been originally parsed to
pub fn unescape_char(escaped: &EscapedChar) -> char {
use EscapedChar::*;
match escaped {
Backslash => '\\',
Quote => '"',
CarriageReturn => '\r',
Tab => '\t',
Newline => '\n',
}
}
#[derive(Clone, Debug)]
pub struct Declarations {
pub declarations: Vec<DeclarationTag>,

View file

@ -1,6 +1,6 @@
use crate::annotation::freshen_opaque_def;
use crate::env::Env;
use crate::expr::{canonicalize_expr, unescape_char, Expr, IntValue, Output};
use crate::expr::{canonicalize_expr, Expr, IntValue, Output};
use crate::num::{
finish_parsing_base, finish_parsing_float, finish_parsing_num, FloatBound, IntBound, NumBound,
ParsedNumResult,
@ -1003,7 +1003,7 @@ fn flatten_str_lines(lines: &[&[StrSegment<'_>]]) -> Pattern {
Interpolated(loc_expr) => {
return Pattern::UnsupportedPattern(loc_expr.region);
}
EscapedChar(escaped) => buf.push(unescape_char(escaped)),
EscapedChar(escaped) => buf.push(escaped.unescape()),
}
}
}