Skip to content

Commit c63d6ec

Browse files
committed
[vhdl-syntax] refactor leading and trailing trivia into single leading trivia
1 parent 80e0970 commit c63d6ec

35 files changed

Lines changed: 268 additions & 282 deletions

Cargo.lock

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ast_syntax_gen/src/syntax_definitions/design_units.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ ContextItem: !Choice
3939
DesignFile: !Sequence
4040
- node: DesignUnit
4141
repeated: true
42+
- token: Eof
4243

4344
DesignUnit: !Sequence
4445
- node: ContextClause

ast_syntax_gen/src/token.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ pub enum TokenKind {
7272
///
7373
/// Produced, for example, when there is an unknown char or illegal bit string
7474
Unknown,
75+
76+
Eof
7577
}
7678

7779
impl TokenKind {

vhdl_syntax/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ serde = { version = "1.0.228", optional = true, features = ["derive"]}
1717
assert_matches = "1.5.0"
1818
pretty_assertions = "1.4.1"
1919
insta = { version = "1.36", features = ["redactions"] }
20+
similar = { version = "2.7.0", features = ["bytes"] }
2021

2122
[features]
2223
serde = ["dep:serde"]

vhdl_syntax/examples/doc_extraction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ end bar;
4141
if let Some(token) = entity.raw().first_token() {
4242
// The trivia is where all auxiliary information concerning a token is stored,
4343
// for example, comments, whitespaces or newlines.
44-
let comment = extract_doc_from_trivia(token.all_leading_trivia());
44+
let comment = extract_doc_from_trivia(token.leading_trivia());
4545
// If the entity has a name token, add the extracted documentation to the map
4646
if let Some(ident) = entity
4747
.entity_declaration_preamble()
@@ -62,7 +62,7 @@ end bar;
6262
/// Note that this is a toy example that simply checks for line comments that with a `-` (i.e.,
6363
/// a doc comment is written using the `--- doc comment` syntax. A real-world example needs to
6464
/// include more sophisticated processing.
65-
fn extract_doc_from_trivia(trivia: Trivia) -> String {
65+
fn extract_doc_from_trivia(trivia: &Trivia) -> String {
6666
trivia
6767
.iter()
6868
.filter_map(|piece| match piece {

vhdl_syntax/src/fmt/latin1.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ impl ToLatin1 for Token {
6969
let mut buf = Latin1String::new();
7070
buf.append(&mut self.leading_trivia().to_latin1());
7171
buf.extend(self.text());
72-
buf.append(&mut self.trailing_trivia().to_latin1());
7372
buf
7473
}
7574
}

vhdl_syntax/src/fmt/utf8.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ impl fmt::Display for Token {
6868
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
6969
write!(f, "{}", self.leading_trivia())?;
7070
write!(f, "{}", self.text())?;
71-
write!(f, "{}", self.trailing_trivia())?;
7271
Ok(())
7372
}
7473
}

vhdl_syntax/src/parser/productions/attributes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl Parser {
7070
pub fn entity_designator(&mut self) {
7171
self.start_node(EntityDesignator);
7272
self.entity_tag();
73-
if self.peek_token() == Some(LeftSquare) {
73+
if self.peek_token() == LeftSquare {
7474
self.signature();
7575
}
7676
self.end_node();

vhdl_syntax/src/parser/productions/concurrent_statement.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl Parser {
6969
self.start_node(ConcurrentStatements);
7070
loop {
7171
match self.peek_token() {
72-
Some(Keyword(Kw::End | Kw::Elsif | Kw::Else | Kw::When)) | None => {
72+
Keyword(Kw::End | Kw::Elsif | Kw::Else | Kw::When) | Eof => {
7373
break;
7474
}
7575
_ => self.concurrent_statement(),
@@ -99,7 +99,7 @@ impl Parser {
9999
self.end_node();
100100
}
101101

102-
fn peek_concurrent_statement_kind(&mut self) -> Option<TokenKind> {
102+
fn peek_concurrent_statement_kind(&mut self) -> TokenKind {
103103
// Has label?
104104
let mut peek_idx = 0usize;
105105
if self.next_is(Identifier) && self.next_nth_is(Colon, 1) {
@@ -114,8 +114,8 @@ impl Parser {
114114

115115
pub fn instantiated_unit(&mut self) {
116116
match self.peek_token() {
117-
Some(Keyword(Kw::Entity)) => self.entity_instantiated_unit(),
118-
Some(Keyword(Kw::Configuration)) => self.configuration_instantiated_unit(),
117+
Keyword(Kw::Entity) => self.entity_instantiated_unit(),
118+
Keyword(Kw::Configuration) => self.configuration_instantiated_unit(),
119119
_ => self.component_instantiated_unit(),
120120
}
121121
}
@@ -140,24 +140,24 @@ impl Parser {
140140

141141
pub(crate) fn concurrent_statement(&mut self) {
142142
match self.peek_concurrent_statement_kind() {
143-
Some(Keyword(Kw::Block)) => self.block_statement(),
144-
Some(Keyword(Kw::Process)) => self.process_statement(),
145-
Some(Keyword(Kw::Component | Kw::Configuration | Kw::Entity)) => {
143+
Keyword(Kw::Block) => self.block_statement(),
144+
Keyword(Kw::Process) => self.process_statement(),
145+
Keyword(Kw::Component | Kw::Configuration | Kw::Entity) => {
146146
self.component_instantiation_statement()
147147
}
148-
Some(Keyword(Kw::For)) => self.for_generate_statement(),
149-
Some(Keyword(Kw::If)) => self.if_generate_statement(),
150-
Some(Keyword(Kw::Case)) => self.case_generate_statement(),
151-
Some(Keyword(Kw::Assert)) => self.concurrent_assertion_statement(),
152-
Some(Keyword(Kw::With)) => self.concurrent_selected_signal_assignment(),
153-
Some(Identifier | LtLt | StringLiteral | CharacterLiteral) => {
148+
Keyword(Kw::For) => self.for_generate_statement(),
149+
Keyword(Kw::If) => self.if_generate_statement(),
150+
Keyword(Kw::Case) => self.case_generate_statement(),
151+
Keyword(Kw::Assert) => self.concurrent_assertion_statement(),
152+
Keyword(Kw::With) => self.concurrent_selected_signal_assignment(),
153+
Identifier | LtLt | StringLiteral | CharacterLiteral => {
154154
let checkpoint = self.checkpoint();
155155
self.opt_label();
156156
self.opt_token(Keyword(Kw::Postponed));
157157
let checkpoint2 = self.checkpoint();
158158
self.name();
159159
match self.peek_token() {
160-
Some(LTE) => {
160+
LTE => {
161161
self.start_node_at(checkpoint2, NameTarget);
162162
self.end_node();
163163
self.skip();
@@ -174,7 +174,7 @@ impl Parser {
174174
self.start_node_at(checkpoint, ConcurrentSimpleSignalAssignment);
175175
}
176176
}
177-
Some(Keyword(Kw::Port | Kw::Generic)) => {
177+
Keyword(Kw::Port | Kw::Generic) => {
178178
self.start_node_at(checkpoint2, ComponentInstantiatedUnit);
179179
self.end_node();
180180
self.start_node_at(checkpoint, ComponentInstantiationStatement);

vhdl_syntax/src/parser/productions/configuration_declarations.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl Parser {
101101

102102
fn configuration_item_known_keyword(&mut self, item_checkpoint: Checkpoint) {
103103
match self.peek_token() {
104-
Some(tok @ Keyword(Kw::All | Kw::Others)) => {
104+
tok @ Keyword(Kw::All | Kw::Others) => {
105105
self.start_node_at(item_checkpoint, NodeKind::ComponentConfiguration);
106106
self.start_node_at(item_checkpoint, NodeKind::ComponentConfigurationPreamble);
107107
self.start_node(NodeKind::ComponentSpecification);
@@ -119,7 +119,7 @@ impl Parser {
119119
self.component_configuration_known_spec();
120120
self.end_node();
121121
}
122-
Some(Identifier) => {
122+
Identifier => {
123123
if self.next_nth_is(Comma, 1) {
124124
self.start_node_at(item_checkpoint, NodeKind::ComponentConfiguration);
125125
self.start_node_at(item_checkpoint, NodeKind::ComponentConfigurationPreamble);
@@ -137,7 +137,7 @@ impl Parser {
137137
let checkpoint = self.checkpoint();
138138
self.name();
139139
match self.peek_token() {
140-
Some(Colon) => {
140+
Colon => {
141141
self.start_node_at(item_checkpoint, NodeKind::ComponentConfiguration);
142142
self.start_node_at(
143143
item_checkpoint,

0 commit comments

Comments
 (0)