mirror of
https://github.com/pnx/tree-sitter-dotenv
synced 2026-06-16 01:54:56 +02:00
Initial Commit
This commit is contained in:
commit
948e93ffac
40 changed files with 2760 additions and 0 deletions
54
grammar.js
Normal file
54
grammar.js
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/// <reference types="tree-sitter-cli/dsl" />
|
||||
// @ts-check
|
||||
|
||||
module.exports = grammar({
|
||||
name: "dotenv",
|
||||
|
||||
extras: $ => [
|
||||
/\s/
|
||||
],
|
||||
|
||||
externals: $ => [
|
||||
$._empty_value,
|
||||
],
|
||||
|
||||
rules: {
|
||||
document: $ => repeat(choice(
|
||||
$.comment,
|
||||
$.assignment,
|
||||
)),
|
||||
|
||||
assignment: $ => seq(
|
||||
field("key", $.identifier),
|
||||
"=",
|
||||
field("value", $._value),
|
||||
),
|
||||
|
||||
comment: _ => seq('#', /.*/),
|
||||
|
||||
identifier: _ => token(/[A-Za-z_][A-Za-z0-9_]*/),
|
||||
|
||||
_value: $ => choice(
|
||||
$.string,
|
||||
$.string_interpolation,
|
||||
$.value,
|
||||
alias($._empty_value, $.value),
|
||||
),
|
||||
|
||||
string: $ => seq(
|
||||
"'",
|
||||
$.string_content,
|
||||
"'",
|
||||
),
|
||||
|
||||
string_interpolation: $ => seq(
|
||||
'"',
|
||||
alias($.string_interpolation_content, $.string_content),
|
||||
'"',
|
||||
),
|
||||
|
||||
string_content: _ => token(/[^']*/),
|
||||
string_interpolation_content: _ => token(/[^"]*/),
|
||||
value: _ => token(prec(-1, /[^\#\=\s]+/)),
|
||||
},
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue