Skip to content

Commit

Permalink
Remove Unit and parse empty subexpression
Browse files Browse the repository at this point in the history
Signed-off-by: innocentzero <[email protected]>
  • Loading branch information
InnocentZero committed Dec 23, 2024
1 parent 9fce24c commit 42a8e44
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
10 changes: 6 additions & 4 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ pub enum AstNode {
// Empty values
Null,

// Unit / Null
Unit,

// Operators
Equal,
NotEqual,
Expand Down Expand Up @@ -385,8 +382,13 @@ impl Parser {
} else if self.is_lparen() {
self.lparen();
if self.is_rparen() {
self.compiler.blocks.push(Block::new(vec![]));
self.rparen();
self.create_node(AstNode::Unit, span_start, span_start + 2)
self.create_node(
AstNode::Block(BlockId(self.compiler.blocks.len() - 1)),
span_start,
span_start + 2,
)
} else {
let output = self.expression();
self.rparen();
Expand Down
7 changes: 4 additions & 3 deletions src/snapshots/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ snapshot_kind: text
17: Int (87 to 88) "3"
18: Null (92 to 96)
19: String (100 to 101) "_"
20: Unit (105 to 107)
20: Block(BlockId(1)) (105 to 107)
21: Match { target: NodeId(4), match_arms: [(NodeId(5), NodeId(6)), (NodeId(7), NodeId(16)), (NodeId(17), NodeId(18)), (NodeId(19), NodeId(20))] } (21 to 110)
22: Let { variable_name: NodeId(3), ty: None, initializer: NodeId(21), is_mutable: false } (11 to 110)
23: Block(BlockId(1)) (0 to 111)
23: Block(BlockId(2)) (0 to 111)
==== SCOPE ====
0: Frame Scope, node_id: NodeId(23)
variables: [ foo: NodeId(3), x: NodeId(0) ]
1: Frame Scope, node_id: NodeId(15)
variables: [ w: NodeId(8) ]
2: Frame Scope, node_id: NodeId(20) (empty)
==== TYPES ====
0: int
1: int
Expand All @@ -55,7 +56,7 @@ snapshot_kind: text
17: int
18: nothing
19: string
20: nothing
20: ()
21: oneof<closure, nothing, string>
22: ()
23: ()
Expand Down
3 changes: 0 additions & 3 deletions src/typechecker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,6 @@ impl<'a> Typechecker<'a> {
AstNode::String => {
self.set_node_type_id(node_id, STRING_TYPE);
}
AstNode::Unit => {
self.set_node_type_id(node_id, NOTHING_TYPE);
}
AstNode::Params(ref params) => {
for param in params {
self.typecheck_node(*param);
Expand Down

0 comments on commit 42a8e44

Please sign in to comment.