chezmoi/dot_config/helix/runtime/grammars/sources/awk/grammar.js

399 lines
10 KiB
JavaScript
Raw Normal View History

Add .config/helix/.chezmoiignore Add .config/helix/.gitignore Add .config/helix/runtime/grammars/.gitkeep Add .config/helix/runtime/grammars/astro.so Add .config/helix/runtime/grammars/awk.so Add .config/helix/runtime/grammars/bash.so Add .config/helix/runtime/grammars/bass.so Add .config/helix/runtime/grammars/beancount.so Add .config/helix/runtime/grammars/bibtex.so Add .config/helix/runtime/grammars/bicep.so Add .config/helix/runtime/grammars/blueprint.so Add .config/helix/runtime/grammars/c-sharp.so Add .config/helix/runtime/grammars/c.so Add .config/helix/runtime/grammars/capnp.so Add .config/helix/runtime/grammars/clojure.so Add .config/helix/runtime/grammars/cmake.so Add .config/helix/runtime/grammars/comment.so Add .config/helix/runtime/grammars/cpon.so Add .config/helix/runtime/grammars/cpp.so Add .config/helix/runtime/grammars/css.so Add .config/helix/runtime/grammars/cue.so Add .config/helix/runtime/grammars/d.so Add .config/helix/runtime/grammars/dart.so Add .config/helix/runtime/grammars/devicetree.so Add .config/helix/runtime/grammars/dhall.so Add .config/helix/runtime/grammars/diff.so Add .config/helix/runtime/grammars/dockerfile.so Add .config/helix/runtime/grammars/dot.so Add .config/helix/runtime/grammars/dtd.so Add .config/helix/runtime/grammars/edoc.so Add .config/helix/runtime/grammars/eex.so Add .config/helix/runtime/grammars/elixir.so Add .config/helix/runtime/grammars/elm.so Add .config/helix/runtime/grammars/elvish.so Add .config/helix/runtime/grammars/embedded-template.so Add .config/helix/runtime/grammars/erlang.so Add .config/helix/runtime/grammars/esdl.so Add .config/helix/runtime/grammars/fish.so Add .config/helix/runtime/grammars/forth.so Add .config/helix/runtime/grammars/fortran.so Add .config/helix/runtime/grammars/fsharp.so Add .config/helix/runtime/grammars/gdscript.so Add .config/helix/runtime/grammars/git-commit.so Add .config/helix/runtime/grammars/git-config.so Add .config/helix/runtime/grammars/git-rebase.so Add .config/helix/runtime/grammars/gitattributes.so Add .config/helix/runtime/grammars/gitignore.so Add .config/helix/runtime/grammars/gleam.so Add .config/helix/runtime/grammars/glsl.so Add .config/helix/runtime/grammars/go.so Add .config/helix/runtime/grammars/godot-resource.so Add .config/helix/runtime/grammars/gomod.so Add .config/helix/runtime/grammars/gotmpl.so Add .config/helix/runtime/grammars/gowork.so Add .config/helix/runtime/grammars/graphql.so Add .config/helix/runtime/grammars/hare.so Add .config/helix/runtime/grammars/haskell-persistent.so Add .config/helix/runtime/grammars/haskell.so Add .config/helix/runtime/grammars/hcl.so Add .config/helix/runtime/grammars/heex.so Add .config/helix/runtime/grammars/hosts.so Add .config/helix/runtime/grammars/html.so Add .config/helix/runtime/grammars/hurl.so Add .config/helix/runtime/grammars/iex.so Add .config/helix/runtime/grammars/ini.so Add .config/helix/runtime/grammars/java.so Add .config/helix/runtime/grammars/javascript.so Add .config/helix/runtime/grammars/jinja2.so Add .config/helix/runtime/grammars/jsdoc.so Add .config/helix/runtime/grammars/json.so Add .config/helix/runtime/grammars/jsonnet.so Add .config/helix/runtime/grammars/julia.so Add .config/helix/runtime/grammars/just.so Add .config/helix/runtime/grammars/kdl.so Add .config/helix/runtime/grammars/kotlin.so Add .config/helix/runtime/grammars/latex.so Add .config/helix/runtime/grammars/lean.so Add .config/helix/runtime/grammars/ledger.so Add .config/helix/runtime/grammars/llvm-mir.so Add .config/helix/runtime/grammars/llvm.so Add .config/helix/runtime/grammars/lua.so Add .config/helix/runtime/grammars/make.so Add .config/helix/runtime/grammars/markdoc.so Add .config/helix/runtime/grammars/markdown.so Add .config/helix/runtime/grammars/markdown_inline.so Add .config/helix/runtime/grammars/matlab.so Add .config/helix/runtime/grammars/mermaid.so Add .config/helix/runtime/grammars/meson.so Add .config/helix/runtime/grammars/nasm.so Add .config/helix/runtime/grammars/nickel.so Add .config/helix/runtime/grammars/nim.so Add .config/helix/runtime/grammars/nix.so Add .config/helix/runtime/grammars/nu.so Add .config/helix/runtime/grammars/ocaml-interface.so Add .config/helix/runtime/grammars/ocaml.so Add .config/helix/runtime/grammars/odin.so Add .config/helix/runtime/grammars/opencl.so Add .config/helix/runtime/grammars/openscad.so Add .config/helix/runtime/grammars/org.so Add .config/helix/runtime/grammars/pascal.so Add .config/helix/runtime/grammars/passwd.so Add .config/helix/runtime/grammars/pem.so Add .config/helix/runtime/grammars/perl.so Add .config/helix/runtime/grammars/php.so Add .config/helix/runtime/grammars/po.so Add .config/helix/runtime/grammars/pod.so Add .config/helix/runtime/grammars/ponylang.so Add .config/helix/runtime/grammars/prisma.so Add .config/helix/runtime/grammars/protobuf.so Add .config/helix/runtime/grammars/prql.so Add .config/helix/runtime/grammars/python.so Add .config/helix/runtime/grammars/qmljs.so Add .config/helix/runtime/grammars/r.so Add .config/helix/runtime/grammars/regex.so Add .config/helix/runtime/grammars/rego.so Add .config/helix/runtime/grammars/rescript.so Add .config/helix/runtime/grammars/robot.so Add .config/helix/runtime/grammars/rst.so Add .config/helix/runtime/grammars/ruby.so Add .config/helix/runtime/grammars/rust.so Add .config/helix/runtime/grammars/scala.so Add .config/helix/runtime/grammars/scheme.so Add .config/helix/runtime/grammars/scss.so Add .config/helix/runtime/grammars/slint.so Add .config/helix/runtime/grammars/smithy.so Add .config/helix/runtime/grammars/sml.so Add .config/helix/runtime/grammars/solidity.so Add .config/helix/runtime/grammars/sources/astro/Cargo.toml Add .config/helix/runtime/grammars/sources/astro/README.md Add .config/helix/runtime/grammars/sources/astro/binding.gyp Add .config/helix/runtime/grammars/sources/astro/bindings/node/binding.cc Add .config/helix/runtime/grammars/sources/astro/bindings/node/index.js Add .config/helix/runtime/grammars/sources/astro/bindings/rust/build.rs Add .config/helix/runtime/grammars/sources/astro/bindings/rust/lib.rs Add .config/helix/runtime/grammars/sources/astro/.gitignore Add .config/helix/runtime/grammars/sources/astro/flake.lock Add .config/helix/runtime/grammars/sources/astro/flake.nix Add .config/helix/runtime/grammars/sources/astro/grammar.js Add .config/helix/runtime/grammars/sources/astro/package-lock.json Add .config/helix/runtime/grammars/sources/astro/package.json Add .config/helix/runtime/grammars/sources/astro/queries/highlights.scm Add .config/helix/runtime/grammars/sources/astro/queries/injections.scm Add .config/helix/runtime/grammars/sources/astro/src/grammar.json Add .config/helix/runtime/grammars/sources/astro/src/node-types.json Add .config/helix/runtime/grammars/sources/astro/src/parser.c Add .config/helix/runtime/grammars/sources/astro/src/scanner.cc Add .config/helix/runtime/grammars/sources/astro/src/tag.h Add .config/helix/runtime/grammars/sources/astro/src/tree_sitter/parser.h Add .config/helix/runtime/grammars/sources/astro/test.astro Add .config/helix/runtime/grammars/sources/astro/test2.astro Add .config/helix/runtime/grammars/sources/astro/test3.astro Add .config/helix/runtime/grammars/sources/astro/test4.astro Add .config/helix/runtime/grammars/sources/astro/test5.astro Add .config/helix/runtime/grammars/sources/astro/test6.astro Add .config/helix/runtime/grammars/sources/awk/Cargo.toml Add .config/helix/runtime/grammars/sources/awk/LICENSE Add .config/helix/runtime/grammars/sources/awk/README.md Add .config/helix/runtime/grammars/sources/awk/binding.gyp Add .config/helix/runtime/grammars/sources/awk/bindings/node/binding.cc Add .config/helix/runtime/grammars/sources/awk/bindings/node/index.js Add .config/helix/runtime/grammars/sources/awk/bindings/rust/build.rs Add .config/helix/runtime/grammars/sources/awk/bindings/rust/lib.rs Add .config/helix/runtime/grammars/sources/awk/.github/workflows/tests.yml Add .config/helix/runtime/grammars/sources/awk/.gitignore Add .config/helix/runtime/grammars/sources/awk/.npmignore Add .config/helix/runtime/grammars/sources/awk/.prettierrc Add .config/helix/runtime/grammars/sources/awk/.vscode/launch.json Add .config/helix/runtime/grammars/sources/awk/examples/example.awk Add .config/helix/runtime/grammars/sources/awk/grammar.d.ts Add .config/helix/runtime/grammars/sources/awk/grammar.js Add .config/helix/runtime/grammars/sources/awk/jsconfig.json Add .config/helix/runtime/grammars/sources/awk/package.json Add .config/helix/runtime/grammars/sources/awk/queries/highlights.scm Add .config/helix/runtime/grammars/sources/awk/scripts/update_highlights_version.sh Add .config/helix/runtime/grammars/sources/awk/scripts/generate_types.js Add .config/helix/runtime/grammars/sources/awk/scripts/generate_types_watch.js Add .config/helix/runtime/grammars/sources/awk/src/grammar.json Add .config/helix/runtime/grammars/sources/awk/src/node-types.json Add .config/helix/runtime/grammars/sources/awk/src/parser.c Add .config/helix/runtime/grammars/sources/awk/src/scanner.c Add .config/helix/runtime/grammars/sources/awk/src/tree_sitter/parser.h Add .config/helix/runtime/grammars/sources/awk/test/corpus/crlf.txt Add .config/helix/runtime/grammars/sources/awk/test/corpus/expression.txt Add .config/helix/runtime/grammars/sources/awk/test/corpus/function.txt Add .config/helix/runtime/grammars/sources/awk/test/corpus/pattern.txt Add .config/helix/runtime/grammars/sources/awk/test/corpus/program.txt Add .config/helix/runtime/grammars/sources/awk/test/corpus/statement.txt Add .config/helix/runtime/grammars/sources/awk/yarn.lock Add .config/helix/runtime/grammars/sources/bash/Cargo.toml Add .config/helix/runtime/grammars/sources/bash/LICENSE Add .config/helix/runtime/grammars/sources/bash/.gitattributes Add .config/helix/runtime/grammars/sources/bash/.github/workflows/ci.yml Add .config/helix/runtime/grammars/sources/bash/.gitignore Add .config/helix/runtime/grammars/sources/bash/.gitmodules Add .config/helix/runtime/grammars/sources/bash/.npmignore Add .config/helix/runtime/grammars/sources/bash/.travis.yml Remove .config/helix/runtime
2023-08-23 21:33:06 +02:00
module.exports = grammar({
name: 'awk',
extras: $ => [$.comment, /[\s\t]/, '\\\n', '\\\r\n'],
externals: $ => [$.concatenating_space, $._if_else_separator, $._ambiguous_comment, $._no_space],
precedences: $ => [
[
$.getline_file,
$.getline_input,
$.grouping,
$.field_ref,
$.func_call,
$.update_exp,
'binary_exponent',
'binary_times',
'binary_plus',
$.string_concat,
$.unary_exp,
$.piped_io_exp,
'binary_relation',
'binary_match',
'binary_in',
'binary_and',
'binary_or',
$.ternary_exp,
$.exp_list,
$.range_pattern,
$._statement,
],
[$.func_call, $._exp],
[$.update_exp, $._exp],
[$.if_statement, $._statement_separated],
[$.else_clause, $._statement_separated],
[$.print_statement, $.printf_statement, $.grouping],
[$._print_args, $.grouping, $.piped_io_exp, 'binary_relation'],
[$.for_in_statement, $._exp],
[$._exp, $.string_concat, $.assignment_exp],
],
conflicts: $ => [],
word: $ => $.identifier,
rules: {
program: $ => repeat(choice($.rule, $.func_def, $.directive)),
rule: $ =>
prec.right(choice(seq($.pattern, optional($.block)), seq(optional($.pattern), $.block))),
pattern: $ => prec.right(choice($._exp, $.range_pattern, $._special_pattern)),
range_pattern: $ => seq(field('start', $._exp), ',', field('stop', $._exp)),
_special_pattern: $ => choice('BEGIN', 'END', 'BEGINFILE', 'ENDFILE'),
directive: $ => seq(choice('@include', '@load', '@namespace'), $.string),
_statement: $ =>
prec.left(
choice(
seq($._statement_separated, $._statement),
$._statement_separated,
$._control_statement,
$._io_statement,
$._exp
)
),
_statement_separated: $ => prec.right(seq($._statement, choice(';', '\n', '\r\n'))),
_control_statement: $ =>
choice(
$.if_statement,
$.while_statement,
$.do_while_statement,
$.for_statement,
$.for_in_statement,
$.break_statement,
$.continue_statement,
$.delete_statement,
$.exit_statement,
$.return_statement,
$.switch_statement
),
if_statement: $ =>
prec.right(
seq(
'if',
field('condition', seq('(', $._exp, ')')),
choice($.block, $._statement, ';'),
optional(seq($._if_else_separator, $.else_clause))
)
),
else_clause: $ => seq('else', choice($.block, $._statement)),
while_statement: $ =>
prec.right(
seq('while', field('condition', seq('(', $._exp, ')')), choice($.block, $._statement))
),
do_while_statement: $ =>
prec.right(
seq('do', choice($.block, $._statement), 'while', field('condition', seq('(', $._exp, ')')))
),
for_statement: $ =>
prec.right(
seq(
'for',
'(',
field('initializer', optional($._exp)),
';',
field('condition', optional($._exp)),
';',
field('advancement', optional($._exp)),
')',
choice($.block, $._statement)
)
),
for_in_statement: $ =>
prec.right(
seq(
'for',
'(',
field('left', choice($.identifier, $.ns_qualified_name)),
'in',
field('right', choice($.identifier, $.array_ref, $.ns_qualified_name)),
')',
choice($.block, $._statement)
)
),
break_statement: $ => 'break',
continue_statement: $ => 'continue',
delete_statement: $ => seq('delete', choice($.identifier, $.array_ref, $.ns_qualified_name)),
exit_statement: $ => prec.right(seq('exit', optional($._exp))),
return_statement: $ => prec.right(seq('return', optional($._exp))),
switch_statement: $ => seq('switch', '(', $._exp, ')', $.switch_body),
switch_body: $ => seq('{', repeat(choice($.switch_case, $.switch_default)), '}'),
switch_case: $ =>
seq('case', field('value', choice($._primitive, $.regex)), ':', optional($._statement)),
switch_default: $ => seq('default', ':', $._statement),
_io_statement: $ =>
choice(
$.next_statement,
$.nextfile_statement,
$.print_statement,
$.printf_statement,
$.redirected_io_statement,
$.piped_io_statement
),
// Although it's referenced as statement in manual it acts as an expression
_getline_exp: $ => choice($.getline_input, $.getline_file),
getline_input: $ =>
prec.right(seq('getline', optional(choice($.identifier, $.ns_qualified_name)))),
getline_file: $ =>
seq(
'getline',
optional(choice($.identifier, $.ns_qualified_name)),
'<',
field('filename', $._exp)
),
next_statement: $ => 'next',
nextfile_statement: $ => 'nextfile',
_print_args: $ => prec.right(choice($._exp, $.exp_list)),
print_statement: $ =>
prec.right(
seq('print', optional(choice($._print_args, seq(token.immediate('('), $._print_args, ')'))))
),
printf_statement: $ => seq('printf', choice($._print_args, seq('(', $._print_args, ')'))),
redirected_io_statement: $ =>
prec.right(
seq(
choice($.print_statement, $.printf_statement),
choice('>', '>>'),
field('filename', $._exp)
)
),
piped_io_statement: $ =>
prec.right(
seq(
choice($.print_statement, $.printf_statement),
choice('|', '|&'),
field('command', $._exp)
)
),
block: $ => seq('{', repeat($._block_content), '}'),
_block_content: $ => prec.left(choice($.block, $._statement)),
_exp: $ =>
choice(
$.identifier,
$.ns_qualified_name,
$.ternary_exp,
$.binary_exp,
$.unary_exp,
$.update_exp,
$.assignment_exp,
$.field_ref,
$.func_call,
$.indirect_func_call,
$._primitive,
$.array_ref,
$.regex,
$.regex_constant,
$.grouping,
$.piped_io_exp,
$.string_concat,
$._getline_exp
),
ternary_exp: $ =>
prec.right(
seq(
field('condition', $._exp),
'?',
field('consequence', $._exp),
':',
field('alternative', $._exp)
)
),
binary_exp: $ =>
choice(
...[
['^', 'binary_exponent'],
['**', 'binary_exponent'],
['*', 'binary_times'],
['/', 'binary_times'],
['%', 'binary_times'],
['+', 'binary_plus'],
['-', 'binary_plus'],
['<', 'binary_relation'],
['>', 'binary_relation'],
['<=', 'binary_relation'],
['>=', 'binary_relation'],
['==', 'binary_relation'],
['!=', 'binary_relation'],
['~', 'binary_match'],
['!~', 'binary_match'],
['in', 'binary_in'],
['&&', 'binary_and'],
['||', 'binary_or'],
].map(([op, precedence]) =>
prec.left(
precedence,
seq(field('left', $._exp), field('operator', op), field('right', $._exp))
)
)
),
unary_exp: $ =>
choice(...['!', '+', '-'].map(op => seq(field('operator', op), field('argument', $._exp)))),
update_exp: $ => {
const refs = choice($.identifier, $.field_ref, $.array_ref, $.ns_qualified_name);
return prec.left(
choice(
seq(field('argument', refs), field('operator', choice('++', '--'))),
seq(field('operator', choice('++', '--')), field('argument', refs))
)
);
},
assignment_exp: $ =>
prec.right(
seq(
field('left', choice($.identifier, $.array_ref, $.field_ref, $.ns_qualified_name)),
choice('=', '+=', '-=', '*=', '/=', '%=', '^='),
field('right', $._exp)
)
),
piped_io_exp: $ => seq(field('command', $._exp), choice('|', '|&'), $.getline_input),
string_concat: $ => {
const applicable_exp = choice(
$.identifier,
$.ns_qualified_name,
$.ternary_exp,
$.binary_exp,
$.unary_exp,
$.field_ref,
$.func_call,
$._primitive,
$.array_ref,
$.grouping,
$.string_concat
);
return prec.left(
seq(field('left', applicable_exp), $.concatenating_space, field('right', applicable_exp))
);
},
field_ref: $ => seq('$', $._exp),
array_ref: $ =>
seq(
choice($.identifier, $.array_ref, $.ns_qualified_name),
'[',
field('index', choice($._exp, $.exp_list)),
']'
),
exp_list: $ => seq(repeat1(seq($._exp, ',')), $._exp),
regex: $ =>
seq(
'/',
field('pattern', $.regex_pattern),
token.immediate('/'),
optional(field('flags', $.regex_flags))
),
regex_pattern: $ => {
const char = /[^/\\\[\n\r]/;
const char_escaped = seq('\\', /./);
const char_list = seq('[', repeat1(choice(char_escaped, /[^\]]/)), ']');
return token.immediate(repeat(choice(char, char_escaped, char_list)));
},
regex_flags: $ => token.immediate(/[a-z]+/),
regex_constant: $ => seq('@', $.regex),
grouping: $ => seq('(', $._exp, ')'),
_primitive: $ => choice($.number, $.string),
identifier: $ => /[a-zA-Z_][a-zA-Z0-9_]*/,
namespace: $ => alias($.identifier, 'namespace'),
ns_qualified_name: $ => seq($.namespace, token.immediate('::'), $._no_space, $.identifier),
number: $ => /[\d.]+/,
string: $ => seq('"', repeat(choice(/[^"\\]+/, $.escape_sequence, $._ambiguous_comment)), '"'),
escape_sequence: $ =>
token.immediate(seq('\\', choice('"', /[\\abfnrtv]/, /x[0-9a-fA-F]{1,2}/, /[0-7]{1,3}/))),
func_def: $ =>
seq(
choice('function', 'func'),
field('name', choice($.identifier, $.ns_qualified_name)),
'(',
optional($.param_list),
')',
$.block
),
param_list: $ => seq($.identifier, repeat(seq(',', $.identifier))),
func_call: $ =>
seq(
field('name', choice($.identifier, $.ns_qualified_name)),
token.immediate('('),
optional($.args),
')'
),
indirect_func_call: $ => seq('@', $.func_call),
args: $ => seq($._exp, repeat(seq(',', $._exp))),
comment: $ => seq('#', /.*/),
},
});