diff --git a/grammar.js b/grammar.js index b76ee03..da00537 100644 --- a/grammar.js +++ b/grammar.js @@ -15,13 +15,14 @@ const make_attr_delimited = (token_suffix) => { const make_attrs_delimited = (delim_open, delim_close, token_suffix) => { return ($) => seq( delim_open, - optional($._space), + optional($._space_or_newline), optional( seq( alias($[`_attr_delimited_${token_suffix}`], $.attr), - repeat(seq($._space, alias($[`_attr_delimited_${token_suffix}`], $.attr))), + repeat(seq($._space_or_newline, alias($[`_attr_delimited_${token_suffix}`], $.attr))), ) ), + optional($._space_or_newline), delim_close ) }; @@ -295,6 +296,7 @@ module.exports = grammar({ optional($._text_nested) ), + _space_or_newline: $ => /[ \t\n]+/, _space: $ => token(prec(-1, /[ \t]+/)) }, diff --git a/src/grammar.json b/src/grammar.json index 418e9bb..dc86071 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -402,7 +402,7 @@ "members": [ { "type": "SYMBOL", - "name": "_space" + "name": "_space_or_newline" }, { "type": "BLANK" @@ -431,7 +431,7 @@ "members": [ { "type": "SYMBOL", - "name": "_space" + "name": "_space_or_newline" }, { "type": "ALIAS", @@ -452,6 +452,18 @@ } ] }, + { + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "_space_or_newline" + }, + { + "type": "BLANK" + } + ] + }, { "type": "STRING", "value": ")" @@ -470,7 +482,7 @@ "members": [ { "type": "SYMBOL", - "name": "_space" + "name": "_space_or_newline" }, { "type": "BLANK" @@ -499,7 +511,7 @@ "members": [ { "type": "SYMBOL", - "name": "_space" + "name": "_space_or_newline" }, { "type": "ALIAS", @@ -520,6 +532,18 @@ } ] }, + { + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "_space_or_newline" + }, + { + "type": "BLANK" + } + ] + }, { "type": "STRING", "value": "]" @@ -538,7 +562,7 @@ "members": [ { "type": "SYMBOL", - "name": "_space" + "name": "_space_or_newline" }, { "type": "BLANK" @@ -567,7 +591,7 @@ "members": [ { "type": "SYMBOL", - "name": "_space" + "name": "_space_or_newline" }, { "type": "ALIAS", @@ -588,6 +612,18 @@ } ] }, + { + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "_space_or_newline" + }, + { + "type": "BLANK" + } + ] + }, { "type": "STRING", "value": "}" @@ -1524,6 +1560,10 @@ } ] }, + "_space_or_newline": { + "type": "PATTERN", + "value": "[ \\t\\n]+" + }, "_space": { "type": "TOKEN", "content": { diff --git a/test/corpus/attributes.txt b/test/corpus/attributes.txt index 00b5f74..56c9f71 100644 --- a/test/corpus/attributes.txt +++ b/test/corpus/attributes.txt @@ -75,9 +75,9 @@ span[title=make_title] (attrs (attr (attr_name) (attr_assignment) (attr_value))))) -========================== -Multiline quoted attribute -========================== +==================================== +String attributes - multiline quoted +==================================== span title="example example example @@ -99,3 +99,22 @@ span title="example example (attr_name) (attr_assignment) (attr_value))))) + +======================================= +String attributes - delimited multiline +======================================= + +a[ + href="/" +] + +----- + +(source_file + (element + (tag_name) + (attrs + (attr + (attr_name) + (attr_assignment) + (attr_value)))))