1
0
Fork 0
mirror of https://github.com/pnx/tree-sitter-dotenv synced 2026-11-02 15:36:46 +01:00

Compare commits

..

No commits in common. "main" and "v1.1.2" have entirely different histories.
main ... v1.1.2

13 changed files with 608 additions and 1191 deletions

View file

@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.13) cmake_minimum_required(VERSION 3.13)
project(tree-sitter-dotenv project(tree-sitter-dotenv
VERSION "1.1.3" VERSION "1.1.2"
DESCRIPTION "Dotenv grammar for tree-sitter" DESCRIPTION "Dotenv grammar for tree-sitter"
HOMEPAGE_URL "https://github.com/pnx/tree-sitter-dotenv" HOMEPAGE_URL "https://github.com/pnx/tree-sitter-dotenv"
LANGUAGES C) LANGUAGES C)

View file

@ -1,7 +1,7 @@
[package] [package]
name = "tree-sitter-dotenv" name = "tree-sitter-dotenv"
description = "Dotenv grammar for tree-sitter" description = "Dotenv grammar for tree-sitter"
version = "1.1.3" version = "1.1.2"
license = "MIT" license = "MIT"
readme = "README.md" readme = "README.md"
keywords = ["incremental", "parsing", "tree-sitter", "dotenv"] keywords = ["incremental", "parsing", "tree-sitter", "dotenv"]
@ -23,4 +23,4 @@ tree-sitter-language = "0.1"
cc = "1.0.87" cc = "1.0.87"
[dev-dependencies] [dev-dependencies]
tree-sitter = "0.27.0" tree-sitter = "0.26.5"

2
Makefile generated
View file

@ -2,7 +2,7 @@ ifeq ($(OS),Windows_NT)
$(error Windows is not supported) $(error Windows is not supported)
endif endif
VERSION := 1.1.3 VERSION := 1.1.2
LANGUAGE_NAME := tree-sitter-dotenv LANGUAGE_NAME := tree-sitter-dotenv

View file

@ -45,12 +45,10 @@ module.exports = grammar({
comment: _ => /\#[^\n]*/, comment: _ => /\#[^\n]*/,
identifier: _ => /[A-Za-z_][A-Za-z0-9_]*/, identifier: _ => /[A-Za-z_][A-Za-z0-9_]*/,
variable: $ => choice( variable: $ => seq('$', choice(
seq('$', $.identifier), $.identifier,
$._braced_variable, seq('{', $.identifier, '}')
), )),
_braced_variable: $ => seq('$', '{', $.identifier, '}'),
_value: $ => choice( _value: $ => choice(
$.string, $.string,
@ -68,35 +66,7 @@ module.exports = grammar({
$._unquoted_string, $._unquoted_string,
), ),
_unquoted_string: $ => choice( _unquoted_string: $ => alias(/[^\#\s\"\'\$]+(?:[ \t]+[^\#\s\"\'\$]+)+/, $.string_content),
alias($._unquoted_content, $.string_content),
seq(
choice(
alias($.value, $.string_content),
alias($.boolean, $.string_content),
alias($.decimal, $.string_content),
alias($.hexadecimal, $.string_content),
alias($.float, $.string_content),
alias($._unquoted_content, $.string_content),
),
alias($._braced_variable, $.variable),
optional(choice(
alias($.value, $.string_content),
alias($._unquoted_content, $.string_content),
)),
),
),
_unquoted_content: _ => token(choice(
/[^\#\s\"\'\$]+(?:[ \t]+[^\#\s\"\'\$]+)+/,
seq(
/[^\#\s\"\'\$]+(?:[ \t]+[^\#\s\"\'\$]+)*/,
repeat1(seq(
/\$[A-Za-z_][A-Za-z0-9_]*/,
optional(/(?:[ \t]*[^\#\s\"\'\$]+)+/),
)),
),
)),
_literal_string: $ => seq( _literal_string: $ => seq(
"'", "'",

12
package-lock.json generated
View file

@ -1,12 +1,12 @@
{ {
"name": "tree-sitter-dotenv", "name": "tree-sitter-dotenv",
"version": "1.1.2", "version": "1.1.1",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "tree-sitter-dotenv", "name": "tree-sitter-dotenv",
"version": "1.1.2", "version": "1.1.1",
"hasInstallScript": true, "hasInstallScript": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
@ -15,7 +15,7 @@
}, },
"devDependencies": { "devDependencies": {
"prebuildify": "^6.0.1", "prebuildify": "^6.0.1",
"tree-sitter-cli": "^0.27.1" "tree-sitter-cli": "^0.26.12"
}, },
"peerDependencies": { "peerDependencies": {
"tree-sitter": "^0.21.1" "tree-sitter": "^0.21.1"
@ -338,9 +338,9 @@
} }
}, },
"node_modules/tree-sitter-cli": { "node_modules/tree-sitter-cli": {
"version": "0.27.1", "version": "0.26.12",
"resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.27.1.tgz", "resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.26.12.tgz",
"integrity": "sha512-WFPEjxwscCjZP9uYj0rxT2TyGBkDcXUkGTthrMpxZFGvzXEYsbC3J0633Ps8dd2mMsdsbU8oVwmQ148lLHI7Xw==", "integrity": "sha512-rIdMAm6nv75MVFoZ7UTaLVB1OG5h3ZSlCZEp5pne4gOUTalJIkL0A1NlYBg0oEl/d7gvIyc2Y5Jz8m5Xj+NOEw==",
"dev": true, "dev": true,
"hasInstallScript": true, "hasInstallScript": true,
"license": "MIT", "license": "MIT",

View file

@ -1,6 +1,6 @@
{ {
"name": "tree-sitter-dotenv", "name": "tree-sitter-dotenv",
"version": "1.1.3", "version": "1.1.2",
"description": "Dotenv grammar for tree-sitter", "description": "Dotenv grammar for tree-sitter",
"repository": "github:pnx/tree-sitter-dotenv", "repository": "github:pnx/tree-sitter-dotenv",
"license": "MIT", "license": "MIT",
@ -27,7 +27,7 @@
}, },
"devDependencies": { "devDependencies": {
"prebuildify": "^6.0.1", "prebuildify": "^6.0.1",
"tree-sitter-cli": "^0.27.1" "tree-sitter-cli": "^0.26.12"
}, },
"peerDependencies": { "peerDependencies": {
"tree-sitter": "^0.21.1" "tree-sitter": "^0.21.1"

View file

@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
[project] [project]
name = "tree-sitter-dotenv" name = "tree-sitter-dotenv"
description = "Dotenv grammar for tree-sitter" description = "Dotenv grammar for tree-sitter"
version = "1.1.3" version = "1.1.2"
keywords = ["incremental", "parsing", "tree-sitter", "dotenv"] keywords = ["incremental", "parsing", "tree-sitter", "dotenv"]
classifiers = [ classifiers = [
"Intended Audience :: Developers", "Intended Audience :: Developers",

222
src/grammar.json generated
View file

@ -143,28 +143,6 @@
"value": "[A-Za-z_][A-Za-z0-9_]*" "value": "[A-Za-z_][A-Za-z0-9_]*"
}, },
"variable": { "variable": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "$"
},
{
"type": "SYMBOL",
"name": "identifier"
}
]
},
{
"type": "SYMBOL",
"name": "_braced_variable"
}
]
},
"_braced_variable": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
@ -172,16 +150,30 @@
"value": "$" "value": "$"
}, },
{ {
"type": "STRING", "type": "CHOICE",
"value": "{" "members": [
}, {
{ "type": "SYMBOL",
"type": "SYMBOL", "name": "identifier"
"name": "identifier" },
}, {
{ "type": "SEQ",
"type": "STRING", "members": [
"value": "}" {
"type": "STRING",
"value": "{"
},
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "STRING",
"value": "}"
}
]
}
]
} }
] ]
}, },
@ -228,167 +220,13 @@
] ]
}, },
"_unquoted_string": { "_unquoted_string": {
"type": "CHOICE", "type": "ALIAS",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_unquoted_content"
},
"named": true,
"value": "string_content"
},
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "value"
},
"named": true,
"value": "string_content"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "boolean"
},
"named": true,
"value": "string_content"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "decimal"
},
"named": true,
"value": "string_content"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "hexadecimal"
},
"named": true,
"value": "string_content"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "float"
},
"named": true,
"value": "string_content"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_unquoted_content"
},
"named": true,
"value": "string_content"
}
]
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_braced_variable"
},
"named": true,
"value": "variable"
},
{
"type": "CHOICE",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "value"
},
"named": true,
"value": "string_content"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_unquoted_content"
},
"named": true,
"value": "string_content"
}
]
},
{
"type": "BLANK"
}
]
}
]
}
]
},
"_unquoted_content": {
"type": "TOKEN",
"content": { "content": {
"type": "CHOICE", "type": "PATTERN",
"members": [ "value": "[^\\#\\s\\\"\\'\\$]+(?:[ \\t]+[^\\#\\s\\\"\\'\\$]+)+"
{ },
"type": "PATTERN", "named": true,
"value": "[^\\#\\s\\\"\\'\\$]+(?:[ \\t]+[^\\#\\s\\\"\\'\\$]+)+" "value": "string_content"
},
{
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "[^\\#\\s\\\"\\'\\$]+(?:[ \\t]+[^\\#\\s\\\"\\'\\$]+)*"
},
{
"type": "REPEAT1",
"content": {
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "\\$[A-Za-z_][A-Za-z0-9_]*"
},
{
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "(?:[ \\t]*[^\\#\\s\\\"\\'\\$]+)+"
},
{
"type": "BLANK"
}
]
}
]
}
}
]
}
]
}
}, },
"_literal_string": { "_literal_string": {
"type": "SEQ", "type": "SEQ",

1226
src/parser.c generated

File diff suppressed because it is too large Load diff

View file

@ -50,12 +50,18 @@ extern "C" {
/// memory allocated for the array's contents. /// memory allocated for the array's contents.
#define array_clear(self) ((self)->size = 0) #define array_clear(self) ((self)->size = 0)
#ifdef __cplusplus
#define _array__cast(self, expr) (decltype((self)->contents))(expr)
#else
#define _array__cast(self, expr) (expr)
#endif
/// Reserve `new_capacity` elements of space in the array. If `new_capacity` is /// Reserve `new_capacity` elements of space in the array. If `new_capacity` is
/// less than the array's current capacity, this function has no effect. /// less than the array's current capacity, this function has no effect.
#define array_reserve(self, new_capacity) \ #define array_reserve(self, new_capacity) \
((self)->contents = _array__reserve( \ ((self)->contents = _array__cast(self, _array__reserve( \
(void *)(self)->contents, &(self)->capacity, \ (void *)(self)->contents, &(self)->capacity, \
array_elem_size(self), new_capacity) \ array_elem_size(self), new_capacity)) \
) )
/// Free any memory allocated for this array. Note that this does not free any /// Free any memory allocated for this array. Note that this does not free any
@ -71,10 +77,10 @@ extern "C" {
/// Push a new `element` onto the end of the array. /// Push a new `element` onto the end of the array.
#define array_push(self, element) \ #define array_push(self, element) \
do { \ do { \
(self)->contents = _array__grow( \ (self)->contents = _array__cast(self, _array__grow( \
(void *)(self)->contents, (self)->size, &(self)->capacity, \ (void *)(self)->contents, (self)->size, &(self)->capacity, \
1, array_elem_size(self) \ 1, array_elem_size(self) \
); \ )); \
(self)->contents[(self)->size++] = (element); \ (self)->contents[(self)->size++] = (element); \
} while(0) } while(0)
@ -83,10 +89,10 @@ extern "C" {
#define array_grow_by(self, count) \ #define array_grow_by(self, count) \
do { \ do { \
if ((count) == 0) break; \ if ((count) == 0) break; \
(self)->contents = _array__grow( \ (self)->contents = _array__cast(self, _array__grow( \
(self)->contents, (self)->size, &(self)->capacity, \ (self)->contents, (self)->size, &(self)->capacity, \
count, array_elem_size(self) \ count, array_elem_size(self) \
); \ )); \
memset((self)->contents + (self)->size, 0, (count) * array_elem_size(self)); \ memset((self)->contents + (self)->size, 0, (count) * array_elem_size(self)); \
(self)->size += (count); \ (self)->size += (count); \
} while (0) } while (0)
@ -98,26 +104,26 @@ extern "C" {
/// Append `count` elements to the end of the array, reading their values from the /// Append `count` elements to the end of the array, reading their values from the
/// `contents` pointer. /// `contents` pointer.
#define array_extend(self, count, other_contents) \ #define array_extend(self, count, other_contents) \
(self)->contents = _array__splice( \ ((self)->contents = _array__cast(self, _array__splice( \
(void*)(self)->contents, &(self)->size, &(self)->capacity, \ (void*)(self)->contents, &(self)->size, &(self)->capacity, \
array_elem_size(self), (self)->size, 0, count, other_contents \ array_elem_size(self), (self)->size, 0, count, other_contents \
) )))
/// Remove `old_count` elements from the array starting at the given `index`. At /// Remove `old_count` elements from the array starting at the given `index`. At
/// the same index, insert `new_count` new elements, reading their values from the /// the same index, insert `new_count` new elements, reading their values from the
/// `new_contents` pointer. /// `new_contents` pointer.
#define array_splice(self, _index, old_count, new_count, new_contents) \ #define array_splice(self, _index, old_count, new_count, new_contents) \
(self)->contents = _array__splice( \ ((self)->contents = _array__cast(self, _array__splice( \
(void *)(self)->contents, &(self)->size, &(self)->capacity, \ (void *)(self)->contents, &(self)->size, &(self)->capacity, \
array_elem_size(self), _index, old_count, new_count, new_contents \ array_elem_size(self), _index, old_count, new_count, new_contents \
) )))
/// Insert one `element` into the array at the given `index`. /// Insert one `element` into the array at the given `index`.
#define array_insert(self, _index, element) \ #define array_insert(self, _index, element) \
(self)->contents = _array__splice( \ ((self)->contents = _array__cast(self, _array__splice( \
(void *)(self)->contents, &(self)->size, &(self)->capacity, \ (void *)(self)->contents, &(self)->size, &(self)->capacity, \
array_elem_size(self), _index, 0, 1, &(element) \ array_elem_size(self), _index, 0, 1, &(element) \
) )))
/// Remove one element from the array at the given `index`. /// Remove one element from the array at the given `index`.
#define array_erase(self, _index) \ #define array_erase(self, _index) \
@ -128,17 +134,17 @@ extern "C" {
/// Assign the contents of one array to another, reallocating if necessary. /// Assign the contents of one array to another, reallocating if necessary.
#define array_assign(self, other) \ #define array_assign(self, other) \
(self)->contents = _array__assign( \ ((self)->contents = _array__cast(self, _array__assign( \
(void *)(self)->contents, &(self)->size, &(self)->capacity, \ (void *)(self)->contents, &(self)->size, &(self)->capacity, \
(const void *)(other)->contents, (other)->size, array_elem_size(self) \ (const void *)(other)->contents, (other)->size, array_elem_size(self) \
) )))
/// Swap one array with another /// Swap one array with another
#define array_swap(self, other) \ #define array_swap(self, other) \
do { \ do { \
void *_array_swap_tmp = (void *)(self)->contents; \ void *_array_swap_tmp = (void *)(self)->contents; \
(self)->contents = (other)->contents; \ (self)->contents = (other)->contents; \
(other)->contents = _array_swap_tmp; \ (other)->contents = _array__cast(other, _array_swap_tmp); \
_array__swap(&(self)->size, &(self)->capacity, \ _array__swap(&(self)->size, &(self)->capacity, \
&(other)->size, &(other)->capacity); \ &(other)->size, &(other)->capacity); \
} while (0) } while (0)

View file

@ -1,161 +0,0 @@
================================================================================
Boolean prefixes become string content
================================================================================
PLAIN_TRUE=true
TRUE_PREFIX=true${APP_NAME}
PLAIN_FALSE=false
FALSE_PREFIX=false${APP_NAME}
--------------------------------------------------------------------------------
(document
(assignment
(identifier)
(boolean))
(assignment
(identifier)
(string
(string_content)
(variable (identifier))))
(assignment
(identifier)
(boolean))
(assignment
(identifier)
(string
(string_content)
(variable (identifier)))))
================================================================================
Numeric prefixes become string content
================================================================================
PLAIN_INTEGER=123
INTEGER_PREFIX=123${APP_NAME}
PLAIN_NEGATIVE=-123
NEGATIVE_PREFIX=-123${APP_NAME}
PLAIN_HEX=0xFF
HEX_PREFIX=0xFF${APP_NAME}
PLAIN_FLOAT=1.5
FLOAT_PREFIX=1.5${APP_NAME}
PLAIN_NEGATIVE_FLOAT=-1.5
NEGATIVE_FLOAT_PREFIX=-1.5${APP_NAME}
--------------------------------------------------------------------------------
(document
(assignment
(identifier)
(number (integer (decimal))))
(assignment
(identifier)
(string
(string_content)
(variable (identifier))))
(assignment
(identifier)
(number (integer (decimal))))
(assignment
(identifier)
(string
(string_content)
(variable (identifier))))
(assignment
(identifier)
(number (integer (hexadecimal))))
(assignment
(identifier)
(string
(string_content)
(variable (identifier))))
(assignment
(identifier)
(number (float)))
(assignment
(identifier)
(string
(string_content)
(variable (identifier))))
(assignment
(identifier)
(number (float)))
(assignment
(identifier)
(string
(string_content)
(variable (identifier)))))
================================================================================
Scalar prefixes with suffixes and comments
================================================================================
BOOL=true${APP_NAME}-suffix # comment
NUMBER=123${APP_NAME} suffix words
--------------------------------------------------------------------------------
(document
(assignment
(identifier)
(string
(string_content)
(variable (identifier))
(string_content)))
(comment)
(assignment
(identifier)
(string
(string_content)
(variable (identifier))
(string_content))))
================================================================================
Bare boolean-prefixed references are literal strings
================================================================================
BOOL=true$APP_NAME
BOOL=false$APP_NAME
--------------------------------------------------------------------------------
(document
(assignment (identifier) (string (string_content)))
(assignment (identifier) (string (string_content))))
================================================================================
Bare decimal-prefixed references are literal strings
================================================================================
NUMBER=123$APP_NAME
NUMBER=-123$APP_NAME
--------------------------------------------------------------------------------
(document
(assignment (identifier) (string (string_content)))
(assignment (identifier) (string (string_content))))
================================================================================
Bare hexadecimal-prefixed references are literal strings
================================================================================
HEX=0xFF$APP_NAME
--------------------------------------------------------------------------------
(document
(assignment (identifier) (string (string_content))))
================================================================================
Bare float-prefixed references are literal strings
================================================================================
FLOAT=1.5$APP_NAME
FLOAT=-1.5$APP_NAME
--------------------------------------------------------------------------------
(document
(assignment (identifier) (string (string_content)))
(assignment (identifier) (string (string_content))))

View file

@ -42,85 +42,3 @@ MULTIPLE = "variable is: ${VARIABLE}, and $ANOTHER !!!"
(variable (variable
(identifier)) (identifier))
(string_content)))) (string_content))))
================================================================================
Unquoted braced variables with prefixes
================================================================================
BASIC = prefix${VARIABLE}
VITE_APP_NAME=xxx${APP_NAME}
SUFFIX = prefix${VARIABLE}-suffix
MULTIWORD = prefix words${VARIABLE} suffix words # comment
--------------------------------------------------------------------------------
(document
(assignment
key: (identifier)
value: (string
(string_content)
(variable
(identifier))))
(assignment
key: (identifier)
value: (string
(string_content)
(variable
(identifier))))
(assignment
key: (identifier)
value: (string
(string_content)
(variable
(identifier))
(string_content)))
(assignment
key: (identifier)
value: (string
(string_content)
(variable
(identifier))
(string_content)))
(comment))
================================================================================
Unquoted bare references with prefixes are literal strings
================================================================================
VITE_APP_NAME=xxx$APP_NAME
NAME=XXX$APP_NAME
SUFFIX=xxx$APP_NAME-suffix
MULTIPLE=xxx$APP_NAME$OTHER
MULTIWORD=prefix words$APP_NAME suffix words # comment
--------------------------------------------------------------------------------
(document
(assignment (identifier) (string (string_content)))
(assignment (identifier) (string (string_content)))
(assignment (identifier) (string (string_content)))
(assignment (identifier) (string (string_content)))
(assignment (identifier) (string (string_content)))
(comment))
================================================================================
Literal bare references alongside braced interpolation
================================================================================
PREFIX=xxx$LITERAL${APP_NAME}
SUFFIX=xxx${APP_NAME}suffix$LITERAL
--------------------------------------------------------------------------------
(document
(assignment
(identifier)
(string
(string_content)
(variable (identifier))))
(assignment
(identifier)
(string
(string_content)
(variable (identifier))
(string_content))))

View file

@ -15,7 +15,7 @@
} }
], ],
"metadata": { "metadata": {
"version": "1.1.3", "version": "1.1.2",
"license": "MIT", "license": "MIT",
"description": "Dotenv grammar for tree-sitter", "description": "Dotenv grammar for tree-sitter",
"authors": [ "authors": [