summaryrefslogtreecommitdiff
path: root/src/parse
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-01-28 20:02:42 +0100
committerLaurenz <laurmaedje@gmail.com>2022-01-28 20:02:42 +0100
commit76b1d4a93f6d045901f17db46d82a97c9f407703 (patch)
treef851460a038a4c543e3900352ec1a2903b6c9849 /src/parse
parent2d97d406aced1f1ab7d3bc459e31bb0eff92b892 (diff)
Parse `show` and `wrap` expressions
Diffstat (limited to 'src/parse')
-rw-r--r--src/parse/incremental.rs5
-rw-r--r--src/parse/mod.rs33
-rw-r--r--src/parse/tokens.rs3
3 files changed, 40 insertions, 1 deletions
diff --git a/src/parse/incremental.rs b/src/parse/incremental.rs
index 4c82f158..2edb84ba 100644
--- a/src/parse/incremental.rs
+++ b/src/parse/incremental.rs
@@ -466,10 +466,13 @@ impl NodeKind {
// how far the expression would go.
Self::Let
| Self::Set
+ | Self::Show
+ | Self::Wrap
| Self::If
| Self::Else
| Self::For
| Self::In
+ | Self::As
| Self::While
| Self::Break
| Self::Continue
@@ -542,6 +545,8 @@ impl NodeKind {
| Self::IfExpr
| Self::LetExpr
| Self::SetExpr
+ | Self::ShowExpr
+ | Self::WrapExpr
| Self::ImportExpr
| Self::IncludeExpr => SuccessionRule::AtomicPrimary,
diff --git a/src/parse/mod.rs b/src/parse/mod.rs
index a9752645..72d38b46 100644
--- a/src/parse/mod.rs
+++ b/src/parse/mod.rs
@@ -208,6 +208,8 @@ fn markup_node(p: &mut Parser, at_start: &mut bool) {
NodeKind::Ident(_)
| NodeKind::Let
| NodeKind::Set
+ | NodeKind::Show
+ | NodeKind::Wrap
| NodeKind::If
| NodeKind::While
| NodeKind::For
@@ -275,7 +277,14 @@ fn enum_node(p: &mut Parser, at_start: bool) {
/// Parse an expression within markup mode.
fn markup_expr(p: &mut Parser) {
if let Some(token) = p.peek() {
- let stmt = matches!(token, NodeKind::Let | NodeKind::Set | NodeKind::Import);
+ let stmt = matches!(
+ token,
+ NodeKind::Let
+ | NodeKind::Set
+ | NodeKind::Show
+ | NodeKind::Wrap
+ | NodeKind::Import
+ );
let group = if stmt { Group::Stmt } else { Group::Expr };
p.start_group(group);
@@ -388,6 +397,8 @@ fn primary(p: &mut Parser, atomic: bool) -> ParseResult {
// Keywords.
Some(NodeKind::Let) => let_expr(p),
Some(NodeKind::Set) => set_expr(p),
+ Some(NodeKind::Show) => show_expr(p),
+ Some(NodeKind::Wrap) => wrap_expr(p),
Some(NodeKind::If) => if_expr(p),
Some(NodeKind::While) => while_expr(p),
Some(NodeKind::For) => for_expr(p),
@@ -714,6 +725,26 @@ fn set_expr(p: &mut Parser) -> ParseResult {
})
}
+/// Parse a show expression.
+fn show_expr(p: &mut Parser) -> ParseResult {
+ p.perform(NodeKind::ShowExpr, |p| {
+ p.eat_assert(&NodeKind::Show);
+ expr(p)?;
+ p.eat_expect(&NodeKind::As)?;
+ expr(p)
+ })
+}
+
+/// Parse a wrap expression.
+fn wrap_expr(p: &mut Parser) -> ParseResult {
+ p.perform(NodeKind::WrapExpr, |p| {
+ p.eat_assert(&NodeKind::Wrap);
+ ident(p)?;
+ p.eat_expect(&NodeKind::In)?;
+ expr(p)
+ })
+}
+
/// Parse an if expresion.
fn if_expr(p: &mut Parser) -> ParseResult {
p.perform(NodeKind::IfExpr, |p| {
diff --git a/src/parse/tokens.rs b/src/parse/tokens.rs
index 840a68e1..eef7a72d 100644
--- a/src/parse/tokens.rs
+++ b/src/parse/tokens.rs
@@ -540,10 +540,13 @@ fn keyword(ident: &str) -> Option<NodeKind> {
"with" => NodeKind::With,
"let" => NodeKind::Let,
"set" => NodeKind::Set,
+ "show" => NodeKind::Show,
+ "wrap" => NodeKind::Wrap,
"if" => NodeKind::If,
"else" => NodeKind::Else,
"for" => NodeKind::For,
"in" => NodeKind::In,
+ "as" => NodeKind::As,
"while" => NodeKind::While,
"break" => NodeKind::Break,
"continue" => NodeKind::Continue,