aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/algo/walk.rs1
-rw-r--r--src/ast.rs2
-rw-r--r--src/lib.rs2
-rw-r--r--src/parser_impl/event.rs2
-rw-r--r--src/parser_impl/mod.rs8
-rw-r--r--src/syntax_kinds/generated.rs41
-rw-r--r--src/syntax_kinds/generated.rs.tera10
-rw-r--r--src/yellow/builder.rs10
8 files changed, 62 insertions, 14 deletions
diff --git a/src/algo/walk.rs b/src/algo/walk.rs
index a50ec2a09..ad0f2d8fb 100644
--- a/src/algo/walk.rs
+++ b/src/algo/walk.rs
@@ -6,7 +6,6 @@ pub fn preorder<'a>(root: SyntaxNodeRef<'a>) -> impl Iterator<Item = SyntaxNodeR
6 WalkEvent::Exit(_) => None, 6 WalkEvent::Exit(_) => None,
7 }) 7 })
8} 8}
9
10#[derive(Debug, Copy, Clone)] 9#[derive(Debug, Copy, Clone)]
11pub enum WalkEvent<'a> { 10pub enum WalkEvent<'a> {
12 Enter(SyntaxNodeRef<'a>), 11 Enter(SyntaxNodeRef<'a>),
diff --git a/src/ast.rs b/src/ast.rs
index 48e1d23ac..caf5fb7ef 100644
--- a/src/ast.rs
+++ b/src/ast.rs
@@ -9,7 +9,7 @@ pub struct File<R: TreeRoot = Arc<SyntaxRoot>> {
9impl File<Arc<SyntaxRoot>> { 9impl File<Arc<SyntaxRoot>> {
10 pub fn parse(text: &str) -> Self { 10 pub fn parse(text: &str) -> Self {
11 File { 11 File {
12 syntax: ::parse(text.to_owned()), 12 syntax: ::parse(text),
13 } 13 }
14 } 14 }
15} 15}
diff --git a/src/lib.rs b/src/lib.rs
index 8f25de9a4..611b87492 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -45,7 +45,7 @@ pub use {
45 yellow::{SyntaxNode, SyntaxNodeRef, SyntaxRoot, TreeRoot}, 45 yellow::{SyntaxNode, SyntaxNodeRef, SyntaxRoot, TreeRoot},
46}; 46};
47 47
48pub fn parse(text: String) -> SyntaxNode { 48pub fn parse(text: &str) -> SyntaxNode {
49 let tokens = tokenize(&text); 49 let tokens = tokenize(&text);
50 parser_impl::parse::<yellow::GreenBuilder>(text, &tokens) 50 parser_impl::parse::<yellow::GreenBuilder>(text, &tokens)
51} 51}
diff --git a/src/parser_impl/event.rs b/src/parser_impl/event.rs
index eb5d0a4be..66a0b6fc0 100644
--- a/src/parser_impl/event.rs
+++ b/src/parser_impl/event.rs
@@ -76,7 +76,7 @@ pub(crate) enum Event {
76 }, 76 },
77} 77}
78 78
79pub(super) fn process(builder: &mut impl Sink, tokens: &[Token], events: Vec<Event>) { 79pub(super) fn process<'a>(builder: &mut impl Sink<'a>, tokens: &[Token], events: Vec<Event>) {
80 let mut idx = 0; 80 let mut idx = 0;
81 81
82 let mut holes = Vec::new(); 82 let mut holes = Vec::new();
diff --git a/src/parser_impl/mod.rs b/src/parser_impl/mod.rs
index b58094be3..2791c8da5 100644
--- a/src/parser_impl/mod.rs
+++ b/src/parser_impl/mod.rs
@@ -14,10 +14,10 @@ use {
14 14
15use SyntaxKind::{self, EOF, TOMBSTONE}; 15use SyntaxKind::{self, EOF, TOMBSTONE};
16 16
17pub(crate) trait Sink { 17pub(crate) trait Sink<'a> {
18 type Tree; 18 type Tree;
19 19
20 fn new(text: String) -> Self; 20 fn new(text: &'a str) -> Self;
21 21
22 fn leaf(&mut self, kind: SyntaxKind, len: TextUnit); 22 fn leaf(&mut self, kind: SyntaxKind, len: TextUnit);
23 fn start_internal(&mut self, kind: SyntaxKind); 23 fn start_internal(&mut self, kind: SyntaxKind);
@@ -27,9 +27,9 @@ pub(crate) trait Sink {
27} 27}
28 28
29/// Parse a sequence of tokens into the representative node tree 29/// Parse a sequence of tokens into the representative node tree
30pub(crate) fn parse<S: Sink>(text: String, tokens: &[Token]) -> S::Tree { 30pub(crate) fn parse<'a, S: Sink<'a>>(text: &'a str, tokens: &[Token]) -> S::Tree {
31 let events = { 31 let events = {
32 let input = input::ParserInput::new(&text, tokens); 32 let input = input::ParserInput::new(text, tokens);
33 let parser_impl = ParserImpl::new(&input); 33 let parser_impl = ParserImpl::new(&input);
34 let mut parser_api = Parser(parser_impl); 34 let mut parser_api = Parser(parser_impl);
35 grammar::file(&mut parser_api); 35 grammar::file(&mut parser_api);
diff --git a/src/syntax_kinds/generated.rs b/src/syntax_kinds/generated.rs
index 435be781c..cbcd0c4e1 100644
--- a/src/syntax_kinds/generated.rs
+++ b/src/syntax_kinds/generated.rs
@@ -169,6 +169,47 @@ pub enum SyntaxKind {
169use self::SyntaxKind::*; 169use self::SyntaxKind::*;
170 170
171impl SyntaxKind { 171impl SyntaxKind {
172 pub fn is_keyword(self) -> bool {
173 match self {
174 | USE_KW
175 | FN_KW
176 | STRUCT_KW
177 | ENUM_KW
178 | TRAIT_KW
179 | IMPL_KW
180 | TRUE_KW
181 | FALSE_KW
182 | AS_KW
183 | EXTERN_KW
184 | CRATE_KW
185 | MOD_KW
186 | PUB_KW
187 | SELF_KW
188 | SUPER_KW
189 | IN_KW
190 | WHERE_KW
191 | FOR_KW
192 | LOOP_KW
193 | WHILE_KW
194 | IF_KW
195 | ELSE_KW
196 | MATCH_KW
197 | CONST_KW
198 | STATIC_KW
199 | MUT_KW
200 | UNSAFE_KW
201 | TYPE_KW
202 | REF_KW
203 | LET_KW
204 | MOVE_KW
205 | AUTO_KW
206 | DEFAULT_KW
207 | UNION_KW
208 => true,
209 _ => false
210 }
211 }
212
172 pub(crate) fn info(self) -> &'static SyntaxInfo { 213 pub(crate) fn info(self) -> &'static SyntaxInfo {
173 match self { 214 match self {
174 SEMI => &SyntaxInfo { name: "SEMI" }, 215 SEMI => &SyntaxInfo { name: "SEMI" },
diff --git a/src/syntax_kinds/generated.rs.tera b/src/syntax_kinds/generated.rs.tera
index d719c8312..4e2ee56c3 100644
--- a/src/syntax_kinds/generated.rs.tera
+++ b/src/syntax_kinds/generated.rs.tera
@@ -24,6 +24,16 @@ pub enum SyntaxKind {
24use self::SyntaxKind::*; 24use self::SyntaxKind::*;
25 25
26impl SyntaxKind { 26impl SyntaxKind {
27 pub fn is_keyword(self) -> bool {
28 match self {
29{%- for kw in concat(a=keywords, b=contextual_keywords) %}
30 | {{kw | upper}}_KW
31{%- endfor %}
32 => true,
33 _ => false
34 }
35 }
36
27 pub(crate) fn info(self) -> &'static SyntaxInfo { 37 pub(crate) fn info(self) -> &'static SyntaxInfo {
28 match self { 38 match self {
29{%- for t in concat(a=single_byte_tokens, b=multi_byte_tokens) %} 39{%- for t in concat(a=single_byte_tokens, b=multi_byte_tokens) %}
diff --git a/src/yellow/builder.rs b/src/yellow/builder.rs
index b68ba789e..dbe646cd7 100644
--- a/src/yellow/builder.rs
+++ b/src/yellow/builder.rs
@@ -4,20 +4,18 @@ use {
4 SyntaxKind, TextRange, TextUnit, 4 SyntaxKind, TextRange, TextUnit,
5}; 5};
6 6
7pub(crate) struct GreenBuilder { 7pub(crate) struct GreenBuilder<'a> {
8 text: String, 8 text: &'a str,
9 stack: Vec<GreenNodeBuilder>, 9 stack: Vec<GreenNodeBuilder>,
10 pos: TextUnit, 10 pos: TextUnit,
11 root: Option<GreenNode>, 11 root: Option<GreenNode>,
12 errors: Vec<SyntaxError>, 12 errors: Vec<SyntaxError>,
13} 13}
14 14
15impl GreenBuilder {} 15impl<'a> Sink<'a> for GreenBuilder<'a> {
16
17impl Sink for GreenBuilder {
18 type Tree = SyntaxNode; 16 type Tree = SyntaxNode;
19 17
20 fn new(text: String) -> Self { 18 fn new(text: &'a str) -> Self {
21 GreenBuilder { 19 GreenBuilder {
22 text, 20 text,
23 stack: Vec::new(), 21 stack: Vec::new(),