1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Copyright (c) 2024, Lukas Scheller lukasscheller@icloud.com
//! The syntax tree: Untyped nodes, and typed views.
//!
//! The result of parsing a file, or building a VHDL element is a tree of [`SyntaxNode`]s and
//! [`SyntaxElement`]s. Every node and every token has the same rust type, they are told apart at
//! runtime by their [`NodeKind`] or [`TokenKind`].
//! This enables generic tree traversal, rewriting, and pretty-printing.
//!
//! On top of the untyped tree sit generated `*Syntax` types, one per production of the VHDL grammar.
//! They are simply views of the untyped tree with typed accessors with cheap cloning and concurrent
//! read characteristics.
//!
//! ```
//! use vhdl_syntax::parser;
//! use vhdl_syntax::syntax::visitor::WalkEvent;
//! use vhdl_syntax::syntax::{AstNode, EntityDeclarationSyntax, NodeKind};
//!
//! let (design, _) = parser::parse("\
//! entity foo is
//! end foo;
//! ");
//!
//! // Untyped: walk the tree and look at kinds.
//! let entity = design
//! .walk()
//! .find_map(|event| match event {
//! WalkEvent::Enter(node) if node.kind() == NodeKind::EntityDeclaration => Some(node),
//! _ => None,
//! })
//! .unwrap();
//!
//! // Typed: the same node, addressed by name.
//! let entity = EntityDeclarationSyntax::cast(entity).unwrap();
//! let name = entity
//! .entity_declaration_preamble()
//! .unwrap()
//! .identifier_token()
//! .unwrap();
//! assert_eq!(name.text(), "foo");
//! ```
//!
//! # Why is every accessor optional?
//!
//! Because the parser never fails, a tree may be missing anything: For example, `entity foo` parses, but the resulting
//! syntax node has no epilogue.
pub
pub
use crateLayout;
pub use crate;
use crateRewriteAction;
use cratePreorder;
pub use crateTokenKind;
pub use *;