Skip to main content

Github Actions expressions grammar for tree-sitter

Project description

tree-sitter-gh-actions-expressions

CI discord matrix crates npm pypi

Tree-sitter grammar for Github Actions expressions

[!IMPORTANT] ABI version: 15

Parser requirements

  • gitignore (optional): for hashFiles() function
  • json (optional): for fromJSON() function
  • yaml: injection to its block_mapping_pair node. Check the yaml injection section for more information

Usage in Editors

Neovim

  • gh-actions.nvim: plugin that integrates this grammar to your Neovim configuration

Helix

WIP

Emacs

WIP

In General

You can get the built files from the release branch. If you have specific instructions for your editor, PR's are welcome.

Injection for yaml parser

Use the following query:

((block_mapping_pair
  key: (flow_node) @_key
  value: [
    (block_node
      (block_scalar) @_value)
    (flow_node
      [
        (plain_scalar
          (string_scalar) @_value)
        (double_quote_scalar) @_value
      ])
  ]
  (#lua-match? @_value "${{")) @injection.content
  (#is-gh-actions-file? "") ; NOTE: NEW PREDICATE
  (#set! injection.language "gh_actions_expressions")
  (#set! injection.include-children))

((block_mapping_pair
  key: (flow_node) @_key
  (#eq? @_key "if")
  value: (flow_node
    (plain_scalar
      (string_scalar) @_value)
    (#not-lua-match? @_value "${{"))) @injection.content
  (#is-gh-actions-file? "") ; NOTE: NEW PREDICATE
  (#set! injection.language "gh_actions_expressions")
  (#set! injection.include-children))

is-gh-actions-file predicate

To avoid injecting this grammar to files other than github actions, is recommended to create a predicate named is-gh-actions-file.

[!NOTE] The creation of this directive varies for each editor

This predicate will be the responsible to allow injection to files that matches the name pattern .github/workflows/*.ya?ml.

Implementations

gh-actions.nvim

Troubleshooting

AST errors within bash injections when using run key

AST error within bash injection

To avoid these errors, is recommended to surround the expression within a raw_string node, string with single quotes ', i.e.:

jobs:
  dry-run:
    name: dry-run
    runs-on: ubuntu-latest
    steps:
      - name: dry-run
        run: ./script.sh '${{ inputs.mode }}' --dry-run

Correct bash AST by using raw_string

What if I need it within a variable expansion?

AST error within variable expansion

Because variable expansion is done by using $ prefix, the ${{ and }} nodes will cause an AST error. To avoid this declare an auxiliary bash variable or an environment variable:

jobs:
  dry-run:
    name: dry-run
    runs-on: ubuntu-latest
    steps:
      - name: dry-run
        run: |
          auxiliary_var='${{ inputs.mode }}'
          ./script.sh "$MY_VAR and $MODE" --dry-run
          ./script.sh "$MY_VAR and $auxiliary_var" --dry-run
        env:
          MODE: ${{ inputs.mode }}

Correct bash AST by using auxiliary variables

References

Thanks

Thanks to @disrupted for creating tree-sitter-github-actions grammar, which is the base I used to create this grammar.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tree_sitter_gh_actions_expressions-0.4.1.tar.gz (22.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

tree_sitter_gh_actions_expressions-0.4.1-cp310-abi3-win_arm64.whl (17.2 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_gh_actions_expressions-0.4.1-cp310-abi3-win_amd64.whl (18.2 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_gh_actions_expressions-0.4.1-cp310-abi3-musllinux_1_2_x86_64.whl (27.8 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

tree_sitter_gh_actions_expressions-0.4.1-cp310-abi3-musllinux_1_2_aarch64.whl (29.3 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tree_sitter_gh_actions_expressions-0.4.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (30.2 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

tree_sitter_gh_actions_expressions-0.4.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (28.0 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

tree_sitter_gh_actions_expressions-0.4.1-cp310-abi3-macosx_11_0_arm64.whl (16.6 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

tree_sitter_gh_actions_expressions-0.4.1-cp310-abi3-macosx_10_9_x86_64.whl (16.2 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

Details for the file tree_sitter_gh_actions_expressions-0.4.1.tar.gz.

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.4.1.tar.gz
Algorithm Hash digest
SHA256 9bae5c466dcd547ccfe1dbec02df5ad31a8be49235c480caa50961137d92734a
MD5 5ab200553a3555995ce897bfd9753a28
BLAKE2b-256 a4389b2eecdaf7ac53c0a3434e1134a0668d1d5a4d8c5ee6c539c2b14310c6ae

See more details on using hashes here.

File details

Details for the file tree_sitter_gh_actions_expressions-0.4.1-cp310-abi3-win_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.4.1-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 1b113d8b4f1c26e35809adecd1479c401b59f6394fced795f0d33d1fb519b560
MD5 48f1fb16761929dd1e1361988d922724
BLAKE2b-256 74ef8b072508462672e446c73be554b0ec0664cf5a9e5de10e7f91a324dd7d3c

See more details on using hashes here.

File details

Details for the file tree_sitter_gh_actions_expressions-0.4.1-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.4.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 4f6359937e9db3a7692e97e9f75c2cbdada050a856b4ffc1fb3276213bb918ae
MD5 44c947e49abef5e9e0177d00bb3f9e16
BLAKE2b-256 8408ecdf4559a310fa2320c1b625a4adb50d460b5fcf174a90fbefcbb4362a89

See more details on using hashes here.

File details

Details for the file tree_sitter_gh_actions_expressions-0.4.1-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.4.1-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1dcaf7feda4c28d86488559b8d28ecdfeea43f2e0d4f78fe2a3ff12fb892f1d3
MD5 e2d1e8afa3806737f97915fccc5436cd
BLAKE2b-256 c6998f712a3321e608fea4ce757cbf1cbc72f826f16228b1c59bce0a5dc773b2

See more details on using hashes here.

File details

Details for the file tree_sitter_gh_actions_expressions-0.4.1-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.4.1-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 fb07f57ee9b17a41ddf1710e3fb64596d4482826fd996eac2986277dc2490b0d
MD5 8c93ec873728fce8d20a95e2f073187e
BLAKE2b-256 d7dbe8d21150e63ecdcfb17a1235276215bf0dedbd385eff1d5c38ad56513c6a

See more details on using hashes here.

File details

Details for the file tree_sitter_gh_actions_expressions-0.4.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.4.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ec4672b412e137748e91c702b47a461d1f2b388c31e7c1a95c80f501a520d512
MD5 be9af0b90ff8807476582b988f405f96
BLAKE2b-256 77a5978dbe36a0f0f62258344fbc65a94a57e2ccbc17df817ea00903b5e29293

See more details on using hashes here.

File details

Details for the file tree_sitter_gh_actions_expressions-0.4.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.4.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 c7af4b47783dbcf374ddd91e6d9df2520697ecbb90190b2498a252e38a77481a
MD5 e806b7ad7272758c7bfc1bc2eb6941e3
BLAKE2b-256 bdd6d90de2c3f668b2e02e98b719ee89f732d5ba2948514db0e10f4553fadb4e

See more details on using hashes here.

File details

Details for the file tree_sitter_gh_actions_expressions-0.4.1-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.4.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 02aa6ae0c906f05efcb70c289fba6066e68a79ed6480d0c0733b4772fd6ba986
MD5 3d7724c22fd6039167132af5e4281f80
BLAKE2b-256 5da6f1818532635890c0b8cdeded492ce60844d7fab89a12c56c0376c0349798

See more details on using hashes here.

File details

Details for the file tree_sitter_gh_actions_expressions-0.4.1-cp310-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.4.1-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 c420b3076d60d0d678374254df84d57f246e7c73861531a2af4276e31b48a1ab
MD5 b1aa6d6c088418b3c3dedddf6f73994b
BLAKE2b-256 c84e8e23c081035f5bba6ddf206b1af4a120bbb5dfd0fa082ab03b6e7dddee9a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page