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.5.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.5.0-cp310-abi3-win_arm64.whl (17.3 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_gh_actions_expressions-0.5.0-cp310-abi3-win_amd64.whl (18.3 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_gh_actions_expressions-0.5.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.5.0-cp310-abi3-musllinux_1_2_aarch64.whl (29.4 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tree_sitter_gh_actions_expressions-0.5.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (30.3 kB view details)

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

tree_sitter_gh_actions_expressions-0.5.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (28.1 kB view details)

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

tree_sitter_gh_actions_expressions-0.5.0-cp310-abi3-macosx_11_0_arm64.whl (16.7 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

tree_sitter_gh_actions_expressions-0.5.0-cp310-abi3-macosx_10_9_x86_64.whl (16.3 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

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

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.5.0.tar.gz
Algorithm Hash digest
SHA256 fd4d5e1c89415c522950d3c392709d68481e3a069a3370cff9a2dc0e0dc88573
MD5 658ba4eafe8c7ffa07ec12cd1434487b
BLAKE2b-256 01d1fa217230ddbea27c6afac41b298bca0c67c39d79b9d3c204d2ae6e214a9b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.5.0-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 99f44392a0ddcf26fd89b10cf5d94b604957f3b7c26607e7fcf4bb2071b0232c
MD5 e93ac624366b266e80b400bfe79ffb21
BLAKE2b-256 2382e2e948c2340c1282a7b5511d8909cba75a5d8a1bbf3c5bff0608a2d54abe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.5.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 7c61bef7bff2686748b60a001cbbb6b8bd64983ce9d0125741f12f7674ae252d
MD5 745003cd6718f0c090156fbf77a6fa19
BLAKE2b-256 4b7b9d4f0f9469893be689471015cb0f8105ccf58826e6fe3a0ae961170b2688

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.5.0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 35e01c43aa74818b039bd242179cb4862a93aea4e68d5ff953bd5cdaf7b0205d
MD5 90f0f746b3322e213bb4ef6937d05d67
BLAKE2b-256 a15e7b628b484be03c521dc54951453de4a32e213c4606f130696c10f7cb0ba5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.5.0-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 d26d9e82e1c25de55667b7173c37bfc670470a27dc53ca09bdb85b40a3163530
MD5 1be8b2bc31fc8ed58a7c41ea0848d58e
BLAKE2b-256 c2b754ee8db0d0f9420b901def2b40d6606542e172d7aab758f1c600e3cf53c6

See more details on using hashes here.

File details

Details for the file tree_sitter_gh_actions_expressions-0.5.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.5.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ba0f79523098528b02e63565f8be7efd00a9136dc73cbfa7caf43c9516170c48
MD5 a7b8bf54e69f3f8c9fea71fc75759cbc
BLAKE2b-256 f2e70ea6c075e0f4c932fa91f920b343e251ded60cb7a02074e9418bf985a155

See more details on using hashes here.

File details

Details for the file tree_sitter_gh_actions_expressions-0.5.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.5.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 7b63f00e0d3ba86145d6c7da28957b34e30194c3704a7cb50ab7e8c2e44bedfc
MD5 52ba5e85fefc430e3c7bd1a0e045ba9d
BLAKE2b-256 89b8584c84b6882c6b51990b12c8e2b231b8b9316ca9bb235d8f9b843e5b6636

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.5.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7da1e7dc73651b33fc4346cc673e3214211f1fe80d8c84b27101d997fe94c17d
MD5 b6bfd708642aa77e292e22add276f9ce
BLAKE2b-256 6636bc0e1f2422ac98d940c4bd3765109145fdb78bddf0fd8e72672bccbbb344

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_gh_actions_expressions-0.5.0-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 bb417f335eb521e3a370533e5315816f87141f9727635033bab8fbc4073e3bd5
MD5 2348ec238d7f4f8eb90a207b38502af0
BLAKE2b-256 aeb029be8e4985b29cdc47144c6b4d5a6fcbf6abd5eb21c8620672adfe13acd9

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