ikatyang / tree-sitter-vue

Vue grammar for tree-sitter
https://ikatyang.github.io/tree-sitter-vue/
MIT License
77 stars 25 forks source link

prettify format and comments in html scanner #1

Open milahu opened 3 years ago

milahu commented 3 years ago

link to original source minimize line diffs

```diff --- scanner.cc.orig +++ scanner.cc @@ -1,3 +1,5 @@ +// based on https://github.com/tree-sitter/tree-sitter-html + #include #include #include @@ -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 commented 3 years ago

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

```diff --- actual +++ expected @@ -1,27 +1,27 @@ (component - (element