store is_negative for all number literals in the parse ast

This commit is contained in:
Folkert 2021-03-12 16:11:46 +01:00
parent 866fa14590
commit 182fd5201d
12 changed files with 142 additions and 46 deletions

View file

@ -77,8 +77,14 @@ pub enum StrLiteral<'a> {
#[derive(Clone, Debug, PartialEq)]
pub enum Expr<'a> {
// Number Literals
Float(&'a str),
Num(&'a str),
Float {
string: &'a str,
is_negative: bool,
},
Num {
string: &'a str,
is_negative: bool,
},
NonBase10Int {
string: &'a str,
base: Base,
@ -341,13 +347,19 @@ pub enum Pattern<'a> {
Nested(&'a Pattern<'a>),
// Literal
NumLiteral(&'a str),
NumLiteral {
string: &'a str,
is_negative: bool,
},
NonBase10Literal {
string: &'a str,
base: Base,
is_negative: bool,
},
FloatLiteral(&'a str),
FloatLiteral {
string: &'a str,
is_negative: bool,
},
StrLiteral(StrLiteral<'a>),
Underscore(&'a str),
@ -452,7 +464,16 @@ impl<'a> Pattern<'a> {
(Nested(x), Nested(y)) => x.equivalent(y),
// Literal
(NumLiteral(x), NumLiteral(y)) => x == y,
(
NumLiteral {
string: string_x,
is_negative: is_negative_x,
},
NumLiteral {
string: string_y,
is_negative: is_negative_y,
},
) => string_x == string_y && is_negative_x == is_negative_y,
(
NonBase10Literal {
string: string_x,
@ -465,7 +486,16 @@ impl<'a> Pattern<'a> {
is_negative: is_negative_y,
},
) => string_x == string_y && base_x == base_y && is_negative_x == is_negative_y,
(FloatLiteral(x), FloatLiteral(y)) => x == y,
(
FloatLiteral {
string: string_x,
is_negative: is_negative_x,
},
FloatLiteral {
string: string_y,
is_negative: is_negative_y,
},
) => string_x == string_y && is_negative_x == is_negative_y,
(StrLiteral(x), StrLiteral(y)) => x == y,
(Underscore(x), Underscore(y)) => x == y,

View file

@ -646,8 +646,20 @@ fn expr_to_pattern_help<'a>(arena: &'a Bump, expr: &Expr<'a>) -> Result<Pattern<
Ok(Pattern::RecordDestructure(loc_patterns.into_bump_slice()))
}
Expr::Float(string) => Ok(Pattern::FloatLiteral(string)),
Expr::Num(string) => Ok(Pattern::NumLiteral(string)),
Expr::Float {
string,
is_negative,
} => Ok(Pattern::FloatLiteral {
string,
is_negative: *is_negative,
}),
Expr::Num {
string,
is_negative,
} => Ok(Pattern::NumLiteral {
string,
is_negative: *is_negative,
}),
Expr::NonBase10Int {
string,
base,
@ -985,7 +997,7 @@ fn annotation_or_alias<'a>(
QualifiedIdentifier { .. } => {
Def::NotYetImplemented("TODO gracefully handle trying to annotate a qualified identifier, e.g. `Foo.bar : ...`")
}
NumLiteral(_) | NonBase10Literal { .. } | FloatLiteral(_) | StrLiteral(_) => {
NumLiteral { ..} | NonBase10Literal { .. } | FloatLiteral { .. } | StrLiteral(_) => {
Def::NotYetImplemented("TODO gracefully handle trying to annotate a litera")
}
Underscore(_) => {
@ -2361,8 +2373,14 @@ fn number_literal_help<'a>() -> impl Parser<'a, Expr<'a>, Number> {
use crate::number_literal::NumLiteral::*;
match literal {
Num(s) => Expr::Num(s),
Float(s) => Expr::Float(s),
Num(s) => Expr::Num {
string: s,
is_negative: false,
},
Float(s) => Expr::Float {
string: s,
is_negative: false,
},
NonBase10Int {
string,
base,

View file

@ -141,8 +141,14 @@ fn number_pattern_help<'a>() -> impl Parser<'a, Pattern<'a>, EPattern<'a>> {
use crate::number_literal::NumLiteral::*;
match literal {
Num(s) => Pattern::NumLiteral(s),
Float(s) => Pattern::FloatLiteral(s),
Num(s) => Pattern::NumLiteral {
string: s,
is_negative: false,
},
Float(s) => Pattern::FloatLiteral {
string: s,
is_negative: false,
},
NonBase10Int {
string,
base,