Skip to content

Commit 0946e5a

Browse files
committed
Removed unique terminal distinction
1 parent aa17c86 commit 0946e5a

File tree

2 files changed

+21
-27
lines changed

2 files changed

+21
-27
lines changed

crates/codegen-v2/cst/src/structured_cst/model.rs

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ use serde::Serialize;
1818

1919
#[derive(Default, Serialize)]
2020
pub struct StructuredCstModel {
21-
/// Terminal nodes and whether they are unique or their value depends on the
22-
/// content.
23-
pub terminals: BTreeMap<model::Identifier, bool>,
21+
/// Terminal nodes.
22+
pub terminals: BTreeSet<model::Identifier>,
2423

2524
/// Nonterminal nodes that are a fixed size group of potentially different nodes
2625
/// ie a struct
@@ -44,7 +43,6 @@ pub struct Sequence {
4443
pub enum NodeType {
4544
Nonterminal(model::Identifier),
4645
Terminal(model::Identifier),
47-
UniqueTerminal(model::Identifier),
4846
}
4947

5048
#[derive(Clone, Serialize)]
@@ -68,23 +66,21 @@ pub struct Collection {
6866
impl NodeType {
6967
pub fn as_identifier(&self) -> &model::Identifier {
7068
match self {
71-
NodeType::Nonterminal(identifier)
72-
| NodeType::Terminal(identifier)
73-
| NodeType::UniqueTerminal(identifier) => identifier,
69+
NodeType::Nonterminal(identifier) | NodeType::Terminal(identifier) => identifier,
7470
}
7571
}
7672

7773
pub fn is_terminal(&self) -> bool {
78-
matches!(self, Self::Terminal(_) | Self::UniqueTerminal(_))
74+
matches!(self, Self::Terminal(_))
7975
}
8076
}
8177

8278
impl PartialEq<model::Identifier> for NodeType {
8379
fn eq(&self, other: &model::Identifier) -> bool {
8480
match self {
85-
NodeType::Nonterminal(identifier)
86-
| NodeType::Terminal(identifier)
87-
| NodeType::UniqueTerminal(identifier) => identifier == other,
81+
NodeType::Nonterminal(identifier) | NodeType::Terminal(identifier) => {
82+
identifier == other
83+
}
8884
}
8985
}
9086
}
@@ -94,16 +90,14 @@ impl Serialize for NodeType {
9490
where
9591
S: serde::Serializer,
9692
{
97-
let mut map = serializer.serialize_map(Some(4))?;
98-
let (identifier, kind, is_terminal, is_unique) = match self {
99-
NodeType::Nonterminal(identifier) => (identifier, "Nonterminal", false, false),
100-
NodeType::Terminal(identifier) => (identifier, "Terminal", true, false),
101-
NodeType::UniqueTerminal(identifier) => (identifier, "UniqueTerminal", true, true),
93+
let mut map = serializer.serialize_map(Some(3))?;
94+
let (identifier, kind, is_terminal) = match self {
95+
NodeType::Nonterminal(identifier) => (identifier, "Nonterminal", false),
96+
NodeType::Terminal(identifier) => (identifier, "Terminal", true),
10297
};
10398
map.serialize_entry("name", identifier)?;
10499
map.serialize_entry("kind", kind)?;
105100
map.serialize_entry("is_terminal", &is_terminal)?;
106-
map.serialize_entry("is_unique", &is_unique)?;
107101
map.end()
108102
}
109103
}
@@ -132,7 +126,7 @@ impl StructuredCstModel {
132126
}
133127

134128
struct StructuredCstModelBuilder {
135-
pub terminals: BTreeMap<model::Identifier, bool>,
129+
pub terminals: BTreeSet<model::Identifier>,
136130
pub sequences: BTreeMap<model::Identifier, Sequence>,
137131
pub choices: BTreeMap<model::Identifier, Choice>,
138132
pub collections: BTreeMap<model::Identifier, Collection>,
@@ -141,7 +135,7 @@ struct StructuredCstModelBuilder {
141135
impl StructuredCstModelBuilder {
142136
fn create(language: &model::Language) -> Self {
143137
let mut builder = Self {
144-
terminals: BTreeMap::new(),
138+
terminals: BTreeSet::new(),
145139
sequences: BTreeMap::new(),
146140
choices: BTreeMap::new(),
147141
collections: BTreeMap::new(),
@@ -167,13 +161,13 @@ impl StructuredCstModelBuilder {
167161
// These items are nonterminals.
168162
}
169163
model::Item::Trivia { item } => {
170-
self.terminals.insert(item.name.clone(), false);
164+
self.terminals.insert(item.name.clone());
171165
}
172166
model::Item::Keyword { item } => {
173-
self.terminals.insert(item.name.clone(), item.is_unique());
167+
self.terminals.insert(item.name.clone());
174168
}
175169
model::Item::Token { item } => {
176-
self.terminals.insert(item.name.clone(), item.is_unique());
170+
self.terminals.insert(item.name.clone());
177171
}
178172
model::Item::Fragment { .. } => {
179173
// These items are inlined.
@@ -217,10 +211,10 @@ impl StructuredCstModelBuilder {
217211
}
218212

219213
fn find_node_type(&self, identifier: &model::Identifier) -> NodeType {
220-
match self.terminals.get(identifier) {
221-
None => NodeType::Nonterminal(identifier.clone()),
222-
Some(false) => NodeType::Terminal(identifier.clone()),
223-
Some(true) => NodeType::UniqueTerminal(identifier.clone()),
214+
if self.terminals.contains(identifier) {
215+
NodeType::Terminal(identifier.clone())
216+
} else {
217+
NodeType::Nonterminal(identifier.clone())
224218
}
225219
}
226220

crates/solidity-v2/outputs/cargo/cst/src/structured_cst/nodes.rs.jinja2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ use std::rc::Rc;
8585
//
8686
// Note: _source is unused on the constructor methods, but kept for uniformity with other constructors
8787
// and because it may be needed in the future
88-
{% for parent_type, unique in target.terminals %}
88+
{% for parent_type in target.terminals %}
8989
#[derive(Debug)]
9090
pub struct {{ parent_type }} {
9191
pub range: Range<usize>,

0 commit comments

Comments
 (0)