Self
This commit is contained in:
parent
0a471ed71c
commit
d3866a1908
@ -208,6 +208,7 @@ pub enum ExpressionKind {
|
|||||||
PrefixExp(PrefixOp, Box<Expression>),
|
PrefixExp(PrefixOp, Box<Expression>),
|
||||||
TupleLiteral(Vec<Expression>),
|
TupleLiteral(Vec<Expression>),
|
||||||
Value(QualifiedName),
|
Value(QualifiedName),
|
||||||
|
SelfValue,
|
||||||
NamedStruct { name: QualifiedName, fields: Vec<(Rc<String>, Expression)> },
|
NamedStruct { name: QualifiedName, fields: Vec<(Rc<String>, Expression)> },
|
||||||
Call { f: Box<Expression>, arguments: Vec<InvocationArgument> },
|
Call { f: Box<Expression>, arguments: Vec<InvocationArgument> },
|
||||||
Index { indexee: Box<Expression>, indexers: Vec<Expression> },
|
Index { indexee: Box<Expression>, indexers: Vec<Expression> },
|
||||||
|
@ -71,7 +71,12 @@ pub fn walk_expression<V: ASTVisitor>(v: &mut V, expr: &Expression) {
|
|||||||
|
|
||||||
if let Recursion::Continue = v.expression(expr) {
|
if let Recursion::Continue = v.expression(expr) {
|
||||||
match &expr.kind {
|
match &expr.kind {
|
||||||
NatLiteral(_) | FloatLiteral(_) | StringLiteral { .. } | BoolLiteral(_) | Value(_) => (),
|
NatLiteral(_)
|
||||||
|
| FloatLiteral(_)
|
||||||
|
| StringLiteral { .. }
|
||||||
|
| BoolLiteral(_)
|
||||||
|
| Value(_)
|
||||||
|
| SelfValue => (),
|
||||||
BinExp(_, lhs, rhs) => {
|
BinExp(_, lhs, rhs) => {
|
||||||
walk_expression(v, lhs);
|
walk_expression(v, lhs);
|
||||||
walk_expression(v, rhs);
|
walk_expression(v, rhs);
|
||||||
|
@ -45,6 +45,7 @@ fn render_expression(expr: &Expression, indent: usize, buf: &mut String) {
|
|||||||
|
|
||||||
buf.push_str("(Expr ");
|
buf.push_str("(Expr ");
|
||||||
match &expr.kind {
|
match &expr.kind {
|
||||||
|
SelfValue => write!(buf, "(SelfValue)").unwrap(),
|
||||||
NatLiteral(n) => buf.push_str(&format!("(NatLiteral {})", n)),
|
NatLiteral(n) => buf.push_str(&format!("(NatLiteral {})", n)),
|
||||||
FloatLiteral(f) => buf.push_str(&format!("(FloatLiteral {})", f)),
|
FloatLiteral(f) => buf.push_str(&format!("(FloatLiteral {})", f)),
|
||||||
StringLiteral { s, prefix } => buf.push_str(&format!("(StringLiteral prefix: {:?} {})", prefix, s)),
|
StringLiteral { s, prefix } => buf.push_str(&format!("(StringLiteral prefix: {:?} {})", prefix, s)),
|
||||||
|
@ -617,6 +617,7 @@ fn primary_expr_no_struct(input: Span) -> ParseResult<ExpressionKind> {
|
|||||||
float_literal,
|
float_literal,
|
||||||
number_literal,
|
number_literal,
|
||||||
string_literal,
|
string_literal,
|
||||||
|
self_expr,
|
||||||
)),
|
)),
|
||||||
)(input)
|
)(input)
|
||||||
}
|
}
|
||||||
@ -631,6 +632,10 @@ fn named_struct(input: Span) -> ParseResult<ExpressionKind> {
|
|||||||
)(input)
|
)(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
|
//TODO support anonymous structs and Elm-style update syntax for structs
|
||||||
fn record_block(input: Span) -> ParseResult<Vec<(Rc<String>, Expression)>> {
|
fn record_block(input: Span) -> ParseResult<Vec<(Rc<String>, Expression)>> {
|
||||||
let record_entry =
|
let record_entry =
|
||||||
|
@ -124,6 +124,7 @@ impl<'a, 'b> Reducer<'a, 'b> {
|
|||||||
use crate::ast::ExpressionKind::*;
|
use crate::ast::ExpressionKind::*;
|
||||||
|
|
||||||
match &expr.kind {
|
match &expr.kind {
|
||||||
|
SelfValue => panic!(),
|
||||||
NatLiteral(n) => Expression::Literal(Literal::Nat(*n)),
|
NatLiteral(n) => Expression::Literal(Literal::Nat(*n)),
|
||||||
FloatLiteral(f) => Expression::Literal(Literal::Float(*f)),
|
FloatLiteral(f) => Expression::Literal(Literal::Float(*f)),
|
||||||
//TODO implement handling string literal prefixes
|
//TODO implement handling string literal prefixes
|
||||||
|
Loading…
Reference in New Issue
Block a user