mirror of
https://github.com/pnx/tree-sitter-dotenv
synced 2026-08-15 12:58:12 +02:00
fix: parse multi-word unquoted string values
This commit is contained in:
parent
38ed78c2ed
commit
b0e11dc786
5 changed files with 509 additions and 404 deletions
|
|
@ -62,9 +62,12 @@ module.exports = grammar({
|
||||||
|
|
||||||
string: $ => choice(
|
string: $ => choice(
|
||||||
$._string,
|
$._string,
|
||||||
$._literal_string
|
$._literal_string,
|
||||||
|
$._unquoted_string,
|
||||||
),
|
),
|
||||||
|
|
||||||
|
_unquoted_string: $ => alias(/[^\#\s\"\'\$]+(?:[ \t]+[^\#\s\"\'\$]+)+/, $.string_content),
|
||||||
|
|
||||||
_literal_string: $ => seq(
|
_literal_string: $ => seq(
|
||||||
"'",
|
"'",
|
||||||
optional(alias(/[^']+/, $.string_content)),
|
optional(alias(/[^']+/, $.string_content)),
|
||||||
|
|
|
||||||
13
src/grammar.json
generated
13
src/grammar.json
generated
|
|
@ -212,9 +212,22 @@
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "_literal_string"
|
"name": "_literal_string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "_unquoted_string"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"_unquoted_string": {
|
||||||
|
"type": "ALIAS",
|
||||||
|
"content": {
|
||||||
|
"type": "PATTERN",
|
||||||
|
"value": "[^\\#\\s\\\"\\'\\$]+(?:[ \\t]+[^\\#\\s\\\"\\'\\$]+)+"
|
||||||
|
},
|
||||||
|
"named": true,
|
||||||
|
"value": "string_content"
|
||||||
|
},
|
||||||
"_literal_string": {
|
"_literal_string": {
|
||||||
"type": "SEQ",
|
"type": "SEQ",
|
||||||
"members": [
|
"members": [
|
||||||
|
|
|
||||||
861
src/parser.c
generated
861
src/parser.c
generated
File diff suppressed because it is too large
Load diff
|
|
@ -13,6 +13,8 @@ EMPTY_WITH_COMMENT_WHITESPACE = # comment
|
||||||
|
|
||||||
STRING_VALUE_WITH_COMMENT = 'string content' # comment
|
STRING_VALUE_WITH_COMMENT = 'string content' # comment
|
||||||
STRING_VALUE_WITH_COMMENT = "string" # comment
|
STRING_VALUE_WITH_COMMENT = "string" # comment
|
||||||
|
STRING_MULTIWORD_WITH_COMMENT = one two three # comment
|
||||||
|
SINGLE_WORD_WITH_COMMENT = singleword # comment
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -36,5 +38,13 @@ STRING_VALUE_WITH_COMMENT = "string" # comment
|
||||||
key: (identifier)
|
key: (identifier)
|
||||||
value: (string
|
value: (string
|
||||||
(string_content)))
|
(string_content)))
|
||||||
|
(comment)
|
||||||
|
(assignment
|
||||||
|
key: (identifier)
|
||||||
|
value: (string
|
||||||
|
(string_content)))
|
||||||
|
(comment)
|
||||||
|
(assignment
|
||||||
|
key: (identifier)
|
||||||
|
value: (value))
|
||||||
(comment))
|
(comment))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,11 @@
|
||||||
String values
|
String values
|
||||||
================================================================================
|
================================================================================
|
||||||
|
|
||||||
|
key = multi word non quoted string
|
||||||
|
key = hyphenated-value another.value
|
||||||
|
key = value with trailing spaces
|
||||||
|
key = singleword
|
||||||
|
|
||||||
key = "quoted string"
|
key = "quoted string"
|
||||||
key = ""
|
key = ""
|
||||||
|
|
||||||
|
|
@ -11,6 +16,21 @@ key = ''
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
(document
|
(document
|
||||||
|
(assignment
|
||||||
|
(identifier)
|
||||||
|
(string
|
||||||
|
(string_content)))
|
||||||
|
(assignment
|
||||||
|
(identifier)
|
||||||
|
(string
|
||||||
|
(string_content)))
|
||||||
|
(assignment
|
||||||
|
(identifier)
|
||||||
|
(string
|
||||||
|
(string_content)))
|
||||||
|
(assignment
|
||||||
|
(identifier)
|
||||||
|
(value))
|
||||||
(assignment
|
(assignment
|
||||||
(identifier)
|
(identifier)
|
||||||
(string
|
(string
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue