]> git.lizzy.rs Git - rust.git/commitdiff
more orthogonal interface
authorAleksey Kladov <aleksey.kladov@gmail.com>
Sun, 12 Dec 2021 15:38:49 +0000 (18:38 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Sun, 12 Dec 2021 15:38:49 +0000 (18:38 +0300)
crates/parser/src/tokens.rs
crates/syntax/src/parsing.rs

index 4f10956070f7b3a764d0536afd34679a2e471a60..e1aea6acfcf87cd9e8a5b2fe0daa04a02bc0f9d9 100644 (file)
@@ -25,20 +25,23 @@ pub struct Tokens {
 }
 
 impl Tokens {
-    pub fn push(&mut self, was_joint: bool, kind: SyntaxKind) {
-        self.push_impl(was_joint, kind, SyntaxKind::EOF)
+    pub fn push(&mut self, kind: SyntaxKind) {
+        self.push_impl(kind, SyntaxKind::EOF)
+    }
+    pub fn was_joint(&mut self, yes: bool) {
+        let idx = self.len();
+        if yes && idx > 0 {
+            self.set_joint(idx - 1);
+        }
     }
     pub fn push_ident(&mut self, contextual_kw: SyntaxKind) {
-        self.push_impl(false, SyntaxKind::IDENT, contextual_kw)
+        self.push_impl(SyntaxKind::IDENT, contextual_kw)
     }
-    fn push_impl(&mut self, was_joint: bool, kind: SyntaxKind, contextual_kw: SyntaxKind) {
+    fn push_impl(&mut self, kind: SyntaxKind, contextual_kw: SyntaxKind) {
         let idx = self.len();
         if idx % (bits::BITS as usize) == 0 {
             self.joint.push(0);
         }
-        if was_joint && idx > 0 {
-            self.set_joint(idx - 1);
-        }
         self.kind.push(kind);
         self.contextual_kw.push(contextual_kw);
     }
index 652668e80b20d7cb401218ed9a8e3c3bf4beb04f..5cafe70dd7d6f10fa2c309e4fe54e994ce037941 100644 (file)
@@ -68,7 +68,8 @@ pub(crate) fn to_parser_tokens(text: &str, lexer_tokens: &[lexer::Token]) -> ::p
                 SyntaxKind::from_contextual_keyword(token_text).unwrap_or(SyntaxKind::IDENT);
             res.push_ident(contextual_kw);
         } else {
-            res.push(was_joint, t.kind);
+            res.was_joint(was_joint);
+            res.push(t.kind);
             was_joint = true;
         }
         off += usize::from(t.len);