mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
Get it all to compile!
This commit is contained in:
parent
555478cdf0
commit
8272ea876f
21 changed files with 217 additions and 21 deletions
|
@ -746,6 +746,7 @@ fn pattern_to_vars_by_symbol(
|
|||
| IntLiteral(_, _, _)
|
||||
| FloatLiteral(_, _, _)
|
||||
| StrLiteral(_)
|
||||
| SingleQuote(_)
|
||||
| Underscore
|
||||
| MalformedPattern(_, _)
|
||||
| UnsupportedPattern(_) => {}
|
||||
|
|
|
@ -58,6 +58,7 @@ pub enum Expr {
|
|||
Int(Variable, Variable, Box<str>, i128),
|
||||
Float(Variable, Variable, Box<str>, f64),
|
||||
Str(Box<str>),
|
||||
SingleQuote(char),
|
||||
List {
|
||||
elem_var: Variable,
|
||||
loc_elems: Vec<Located<Expr>>,
|
||||
|
@ -305,6 +306,26 @@ pub fn canonicalize_expr<'a>(
|
|||
}
|
||||
}
|
||||
ast::Expr::Str(literal) => flatten_str_literal(env, var_store, scope, literal),
|
||||
ast::Expr::SingleQuote(string) => {
|
||||
let mut it = string.chars().peekable();
|
||||
if let Some(char) = it.next() {
|
||||
if it.peek().is_none() {
|
||||
(Expr::SingleQuote(char), Output::default())
|
||||
} else {
|
||||
// multiple chars is found
|
||||
let error = roc_problem::can::RuntimeError::MulitpleCharsInSingleQuote(region);
|
||||
let answer = Expr::RuntimeError(error.clone());
|
||||
|
||||
(answer, Output::default())
|
||||
}
|
||||
} else {
|
||||
// no characters found
|
||||
let error = roc_problem::can::RuntimeError::EmptySingleQuote(region);
|
||||
let answer = Expr::RuntimeError(error.clone());
|
||||
|
||||
(answer, Output::default())
|
||||
}
|
||||
}
|
||||
ast::Expr::List {
|
||||
items: loc_elems, ..
|
||||
} => {
|
||||
|
@ -1238,6 +1259,7 @@ pub fn inline_calls(var_store: &mut VarStore, scope: &mut Scope, expr: Expr) ->
|
|||
| other @ Int(_, _, _, _)
|
||||
| other @ Float(_, _, _, _)
|
||||
| other @ Str { .. }
|
||||
| other @ SingleQuote(_)
|
||||
| other @ RuntimeError(_)
|
||||
| other @ EmptyRecord
|
||||
| other @ Accessor { .. }
|
||||
|
|
|
@ -386,6 +386,7 @@ fn fix_values_captured_in_closure_pattern(
|
|||
| IntLiteral(_, _, _)
|
||||
| FloatLiteral(_, _, _)
|
||||
| StrLiteral(_)
|
||||
| SingleQuote(_)
|
||||
| Underscore
|
||||
| Shadowed(_, _)
|
||||
| MalformedPattern(_, _)
|
||||
|
@ -442,6 +443,7 @@ fn fix_values_captured_in_closure_expr(
|
|||
| Int(_, _, _, _)
|
||||
| Float(_, _, _, _)
|
||||
| Str(_)
|
||||
| SingleQuote(_)
|
||||
| Var(_)
|
||||
| EmptyRecord
|
||||
| RuntimeError(_)
|
||||
|
|
|
@ -125,6 +125,7 @@ pub fn desugar_expr<'a>(arena: &'a Bump, loc_expr: &'a Located<Expr<'a>>) -> &'a
|
|||
| Num(_)
|
||||
| NonBase10Int { .. }
|
||||
| Str(_)
|
||||
| SingleQuote(_)
|
||||
| AccessorFunction(_)
|
||||
| Var { .. }
|
||||
| Underscore { .. }
|
||||
|
|
|
@ -29,6 +29,7 @@ pub enum Pattern {
|
|||
NumLiteral(Variable, Box<str>, i64),
|
||||
FloatLiteral(Variable, Box<str>, f64),
|
||||
StrLiteral(Box<str>),
|
||||
SingleQuote(char),
|
||||
Underscore,
|
||||
|
||||
// Runtime Exceptions
|
||||
|
@ -89,6 +90,7 @@ pub fn symbols_from_pattern_help(pattern: &Pattern, symbols: &mut Vec<Symbol>) {
|
|||
| IntLiteral(_, _, _)
|
||||
| FloatLiteral(_, _, _)
|
||||
| StrLiteral(_)
|
||||
| SingleQuote(_)
|
||||
| Underscore
|
||||
| MalformedPattern(_, _)
|
||||
| UnsupportedPattern(_) => {}
|
||||
|
@ -237,6 +239,23 @@ pub fn canonicalize_pattern<'a>(
|
|||
ptype => unsupported_pattern(env, ptype, region),
|
||||
},
|
||||
|
||||
SingleQuote(string) => {
|
||||
let mut it = string.chars().peekable();
|
||||
if let Some(char) = it.next() {
|
||||
if it.peek().is_none() {
|
||||
Pattern::SingleQuote(char)
|
||||
} else {
|
||||
// multiple chars is found
|
||||
let problem = MalformedPatternProblem::MulitpleCharsInSingleQuote;
|
||||
malformed_pattern(env, problem, region)
|
||||
}
|
||||
} else {
|
||||
// no characters found
|
||||
let problem = MalformedPatternProblem::EmptySingleQuote;
|
||||
malformed_pattern(env, problem, region)
|
||||
}
|
||||
}
|
||||
|
||||
SpaceBefore(sub_pattern, _) | SpaceAfter(sub_pattern, _) => {
|
||||
return canonicalize_pattern(env, var_store, scope, pattern_type, sub_pattern, region)
|
||||
}
|
||||
|
@ -476,6 +495,7 @@ fn add_bindings_from_patterns(
|
|||
| IntLiteral(_, _, _)
|
||||
| FloatLiteral(_, _, _)
|
||||
| StrLiteral(_)
|
||||
| SingleQuote(_)
|
||||
| Underscore
|
||||
| Shadowed(_, _)
|
||||
| MalformedPattern(_, _)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue