Skip to content

Commit 3d9e5d3

Browse files
committed
feat: ListBlock token to distinguish blocks as list items from blocks in general
1 parent c8257de commit 3d9e5d3

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

crates/ltk_ritobin/src/parse/cst/tree.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub enum Kind {
88
ErrorTree,
99
File,
1010
TypeExpr, TypeArgList, TypeArg,
11-
Block, BlockKey, Class, ListItem,
11+
Block, BlockKey, Class, ListItem, ListBlock,
1212

1313
Entry, EntryKey, EntryValue, EntryTerminator,
1414
Literal,
@@ -32,6 +32,7 @@ impl Display for Kind {
3232
Self::BlockKey => "key",
3333
Self::Class => "bin class",
3434
Self::ListItem => "list item",
35+
Self::ListBlock => "list item (block)",
3536
Self::Comment => "comment",
3637
})
3738
}

crates/ltk_ritobin/src/parse/impls.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::parse::{
22
cst::Kind as TreeKind,
33
error::ErrorKind,
4-
parser::{MarkClosed, Parser},
4+
parser::{MarkClosed, MarkOpened, Parser},
55
tokenizer::TokenKind,
66
};
77

@@ -24,16 +24,16 @@ pub fn stmt_or_list_item(p: &mut Parser) -> (MarkClosed, TreeKind) {
2424
(Name | HexLit, LCurly, _) => {
2525
let m = p.open();
2626
p.advance();
27-
block(p);
27+
let block = block(p);
28+
p.close(block, TreeKind::Block);
2829
res = (p.close(m, TreeKind::Class), TreeKind::Class);
2930
}
3031
(Name | String | HexLit, Colon | Eq, _) => {
3132
res = (stmt(p), TreeKind::Entry);
3233
}
3334
(LCurly, _, _) => {
34-
let m = p.open();
35-
block(p);
36-
res = (p.close(m, TreeKind::ListItem), TreeKind::ListItem);
35+
let m = block(p);
36+
res = (p.close(m, TreeKind::ListBlock), TreeKind::ListBlock);
3737
p.eat(Comma);
3838
}
3939
(Name | HexLit | String | Number | True | False, _, _) => {
@@ -108,7 +108,8 @@ pub fn entry_value(p: &mut Parser) -> bool {
108108
p.scope(TreeKind::Class, |p| {
109109
p.advance();
110110
if p.at(LCurly) {
111-
block(p);
111+
let block = block(p);
112+
p.close(block, TreeKind::Block);
112113
}
113114
});
114115
});
@@ -120,7 +121,8 @@ pub fn entry_value(p: &mut Parser) -> bool {
120121
p.scope(TreeKind::Literal, |p| p.advance());
121122
}
122123
(LCurly, _) => {
123-
block(p);
124+
let block = block(p);
125+
p.close(block, TreeKind::Block);
124126
}
125127
(Newline, _) => {
126128
p.advance_with_error(ErrorKind::Unexpected { token: Newline }, None);
@@ -165,7 +167,8 @@ pub fn expr_type_arg(p: &mut Parser) {
165167
}
166168
}
167169

168-
pub fn block(p: &mut Parser) {
170+
#[must_use]
171+
pub fn block(p: &mut Parser) -> MarkOpened {
169172
assert!(p.at(LCurly));
170173
let m = p.open();
171174
p.expect(LCurly);
@@ -177,6 +180,5 @@ pub fn block(p: &mut Parser) {
177180
}
178181
}
179182
p.expect(RCurly);
180-
181-
p.close(m, TreeKind::Block);
183+
m
182184
}

0 commit comments

Comments
 (0)