diff --git a/grammar.js b/grammar.js index da00537..8742b0a 100644 --- a/grammar.js +++ b/grammar.js @@ -119,10 +119,14 @@ module.exports = grammar({ tag_name: $ => /(\w+|\w[\w:-]+\w)/, _attr_shortcut: $ => choice( $.shortcut_class, - $.shortcut_id + $.shortcut_id, + $.shortcut_custom ), shortcut_class: $ => seq('.', $.css_identifier), shortcut_id: $ => seq('#', $.css_identifier), + // In real slim, custom shortcuts only parsed if prefix is + // configured, otherwise parsed as inline text + shortcut_custom: $ => token(prec(-1, /[^ \t\na-zA-Z0-9_-]+[a-zA-Z0-9_-]*/)), nested: $ => $._block, @@ -169,7 +173,7 @@ module.exports = grammar({ optional($._text_nested) ), - _element_rest_text: $ => token(prec(-1, /[^ \t][^\n]*/)), + _element_rest_text: $ => token(prec(-2, /[^ \t][^\n]*/)), // From css grammar https://github.com/tree-sitter/tree-sitter-css/blob/master/grammar.js // Originally: /\A(#{keys}+)((?:\p{Word}|-|\/\d+|:(\w|-)+)*)/ diff --git a/src/grammar.json b/src/grammar.json index dc86071..951037a 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -320,6 +320,10 @@ { "type": "SYMBOL", "name": "shortcut_id" + }, + { + "type": "SYMBOL", + "name": "shortcut_custom" } ] }, @@ -349,6 +353,17 @@ } ] }, + "shortcut_custom": { + "type": "TOKEN", + "content": { + "type": "PREC", + "value": -1, + "content": { + "type": "PATTERN", + "value": "[^ \\t\\na-zA-Z0-9_-]+[a-zA-Z0-9_-]*" + } + } + }, "nested": { "type": "SYMBOL", "name": "_block" @@ -959,7 +974,7 @@ "type": "TOKEN", "content": { "type": "PREC", - "value": -1, + "value": -2, "content": { "type": "PATTERN", "value": "[^ \\t][^\\n]*" diff --git a/src/node-types.json b/src/node-types.json index ccb3bf9..75e1101 100644 --- a/src/node-types.json +++ b/src/node-types.json @@ -56,6 +56,10 @@ "type": "shortcut_class", "named": true }, + { + "type": "shortcut_custom", + "named": true + }, { "type": "shortcut_id", "named": true @@ -656,6 +660,10 @@ "type": "scss", "named": false }, + { + "type": "shortcut_custom", + "named": true + }, { "type": "strict", "named": false diff --git a/test/corpus/inline.txt b/test/corpus/inline.txt index d6241d2..1e801ad 100644 --- a/test/corpus/inline.txt +++ b/test/corpus/inline.txt @@ -67,6 +67,21 @@ p = make_text(style: "standard") --- +(source_file + (element + (tag_name) + (nested_inline + (ruby_block_output + (ruby))))) + +========================= +Inline output - immediate +========================= + +p=make_text + +--- + (source_file (element (tag_name) diff --git a/test/corpus/tags.txt b/test/corpus/tags.txt index 34f6803..0a3dd38 100644 --- a/test/corpus/tags.txt +++ b/test/corpus/tags.txt @@ -44,3 +44,20 @@ Tag with space before traling space modifier (shortcut_class (css_identifier))) (element_text))) + +============================= +Extension attribute shortcuts +============================= + +span.example@@example*example + +--- + +(source_file + (element + (tag_name) + (attr_shortcuts + (shortcut_class + (css_identifier)) + (shortcut_custom) + (shortcut_custom))))