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.0.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.0-cp310-abi3-win_arm64.whl (17.2 kB view details)

Uploaded CPython 3.10+Windows ARM64

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

Uploaded CPython 3.10+Windows x86-64

tree_sitter_gh_actions_expressions-0.4.0-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.0-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.0-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.0-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.0-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.0-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.0.tar.gz.

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.4.0.tar.gz
Algorithm Hash digest
SHA256 da2674ac2a18419a671930bc439af2ea7a5dd29a64506e7af687ff0906f91721
MD5 378e5f37cb8717b38ac7b4aceba2807d
BLAKE2b-256 0378826ebf4099da6acbd1d2dfe04b2d8205db555358f195fab8aa24fa476d92

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.4.0-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 0f5df84f309e019b225e4ed01f2d21c2f9930684ef3bb6a20e52897a19bd5075
MD5 407b9de6fad60498700a16c160feb3a3
BLAKE2b-256 c6269d4963674c5daf3d6919d47677ea2c3db58b3669437f4c104606c8c6a365

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.4.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 4f735949893550d830cae166f2b4b4fd68381e826450f6ebce89726e8e462939
MD5 5076989d22fca84b3aa115f2bd06882e
BLAKE2b-256 668348360a187e39c61f19a2c46a0ca386d3f0487974559757751b00fbd12281

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.4.0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 49f8e24e7992ece5c0a6b4157a9123de0c603c1783965bb45afebbd9ae5c53d1
MD5 a3cdef355dd00d3974f98cc471b580bb
BLAKE2b-256 366ea9a46cee2019eee4155914b683528c2d07bab3904c47f587bf9b442e6332

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.4.0-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 50a1983700da501bd57c0d05f80d60ee446c91f3c44d5ac1f3a45c00cb0f40b4
MD5 31ca87fb4c8534bee1e8efb0a94b6a1c
BLAKE2b-256 01539bcf6040620d579c28c31544ccef7d65469ac4ad6fb3f1ba7557e1276bb0

See more details on using hashes here.

File details

Details for the file tree_sitter_gh_actions_expressions-0.4.0-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.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 5d9b6e800e869eff492c5b38404de0fa723dd05a8180d147fc92540bdbd6e179
MD5 75db8d8c74318a13d11205591c09b5fc
BLAKE2b-256 edf7a1392b73e8070ab4e69961fd38633b303fc423bcfc14d74fd7b3ca7531d4

See more details on using hashes here.

File details

Details for the file tree_sitter_gh_actions_expressions-0.4.0-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.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 51c64ef6a97c821b1a06a055f0c66cab3d50ce72da533ccf7abd5a5ccb6c639d
MD5 86457a7549ebee62db75f970a64fdfbf
BLAKE2b-256 ca42b14ee540c2a91d10fa698c2f7836657909d747bdac0ab9a24b9b9b9087ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.4.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9eb81fe38e8b7a45af991919ae4566da1857feddbf40da80767b42ed7dbffc71
MD5 d320672a49edc5b81c078c8463ad601a
BLAKE2b-256 79c49b3dfc21779cbfd565996c79e442e2086640d72fb143c9c552cbba11c497

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.4.0-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 610bcca3e141d3eca8934a1a9a3dcf20709c380a3b2debfb101197dbc0589683
MD5 94aef3172b77305b4a7f90a0154c7516
BLAKE2b-256 49230b13c0eed8567e276ef5afcf1f268a32a1168ba5e6037894a640b7aefcae

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