Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prettify format and comments in html scanner #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

milahu
Copy link

@milahu milahu commented Nov 30, 2020

link to original source
minimize line diffs

--- scanner.cc.orig
+++ scanner.cc
@@ -1,3 +1,5 @@
+// based on https://github.com/tree-sitter/tree-sitter-html
+
 #include <tree_sitter/parser.h>
 #include <algorithm>
 #include <vector>
@@ -12,6 +14,12 @@
 using std::string;
 
 enum TokenType {
+
+  // vue
+  TEXT_FRAGMENT,
+  INTERPOLATION_TEXT,
+  TEMPLATE_START_TAG_NAME,
+
   START_TAG_NAME,
   SCRIPT_START_TAG_NAME,
   STYLE_START_TAG_NAME,
@@ -189,6 +197,12 @@
     Tag tag = Tag::for_name(tag_name);
     tags.push_back(tag);
     switch (tag.type) {
+
+      // vue
+      case TEMPLATE:
+        lexer->result_symbol = TEMPLATE_START_TAG_NAME;
+        break;
+
       case SCRIPT:
         lexer->result_symbol = SCRIPT_START_TAG_NAME;
         break;

mark changes with // vue comments

@milahu
Copy link
Author

milahu commented Nov 30, 2020

today i learned:

externals in grammar.js
and
TokenType in src/tree_sitter_html/scanner.cc enum
must be manually kept in sync

section-3-creating-parsers.md#external-scanners

otherwise node names are confused

--- actual
+++ expected
@@ -1,27 +1,27 @@
 (component
-  (element              <template>
+  (template_element     <template>
     (start_tag          <template>
       (tag_name))       <template>
     (text)              whitespace
-    (template_element   <span>
+    (element            <span>
       (start_tag        <span>
         (tag_name))     <span>
       (text)            "Message: "
       (interpolation    { msg }
         (raw_text))     { msg }
       (end_tag          </span>
         (tag_name)))    </span>
     (text)              whitespace
-    (template_element   <span v-once>
+    (element            <span v-once>
       (start_tag        <span v-once>
         (tag_name)      <span v-once>
         (directive_attribute  <span v-once>
           (directive_name)))  <span v-once>
       (text)            "This will never change: "
       (interpolation    { msg }
         (raw_text))     { msg }
       (end_tag          </span>
         (tag_name)))    </span>
     (text)              whitespace
     (end_tag            </template>
       (tag_name))))     </template>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant