This commit is contained in:
Greg Shuflin 2021-11-23 23:56:25 -08:00
parent 0a471ed71c
commit d3866a1908
5 changed files with 14 additions and 1 deletions

View File

@ -208,6 +208,7 @@ pub enum ExpressionKind {
PrefixExp(PrefixOp, Box<Expression>),
TupleLiteral(Vec<Expression>),
Value(QualifiedName),
SelfValue,
NamedStruct { name: QualifiedName, fields: Vec<(Rc<String>, Expression)> },
Call { f: Box<Expression>, arguments: Vec<InvocationArgument> },
Index { indexee: Box<Expression>, indexers: Vec<Expression> },

View File

@ -71,7 +71,12 @@ pub fn walk_expression<V: ASTVisitor>(v: &mut V, expr: &Expression) {
if let Recursion::Continue = v.expression(expr) {
match &expr.kind {
NatLiteral(_) | FloatLiteral(_) | StringLiteral { .. } | BoolLiteral(_) | Value(_) => (),
NatLiteral(_)
| FloatLiteral(_)
| StringLiteral { .. }
| BoolLiteral(_)
| Value(_)
| SelfValue => (),
BinExp(_, lhs, rhs) => {
walk_expression(v, lhs);
walk_expression(v, rhs);

View File

@ -45,6 +45,7 @@ fn render_expression(expr: &Expression, indent: usize, buf: &mut String) {
buf.push_str("(Expr ");
match &expr.kind {
SelfValue => write!(buf, "(SelfValue)").unwrap(),
NatLiteral(n) => buf.push_str(&format!("(NatLiteral {})", n)),
FloatLiteral(f) => buf.push_str(&format!("(FloatLiteral {})", f)),
StringLiteral { s, prefix } => buf.push_str(&format!("(StringLiteral prefix: {:?} {})", prefix, s)),

View File

@ -617,6 +617,7 @@ fn primary_expr_no_struct(input: Span) -> ParseResult<ExpressionKind> {
float_literal,
number_literal,
string_literal,
self_expr,
)),
)(input)
}
@ -631,6 +632,10 @@ fn named_struct(input: Span) -> ParseResult<ExpressionKind> {
)(input)
}
fn self_expr(input: Span) -> ParseResult<ExpressionKind> {
context("self-expression", map(kw("self"), |_| ExpressionKind::SelfValue))(input)
}
//TODO support anonymous structs and Elm-style update syntax for structs
fn record_block(input: Span) -> ParseResult<Vec<(Rc<String>, Expression)>> {
let record_entry =

View File

@ -124,6 +124,7 @@ impl<'a, 'b> Reducer<'a, 'b> {
use crate::ast::ExpressionKind::*;
match &expr.kind {
SelfValue => panic!(),
NatLiteral(n) => Expression::Literal(Literal::Nat(*n)),
FloatLiteral(f) => Expression::Literal(Literal::Float(*f)),
//TODO implement handling string literal prefixes