diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..b0a45b0 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @bbannier diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..6d5c932 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,14 @@ +version: 2 +updates: + - package-ecosystem: "cargo" # See documentation for possible values + directory: "/" + schedule: + interval: "weekly" + - package-ecosystem: "npm" # See documentation for possible values + directory: "/vscode" + schedule: + interval: "weekly" + - package-ecosystem: "github-actions" # See documentation for possible values + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 32f36e1..e9bfd77 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,59 +1,26 @@ -name: Build and tests +name: Check on: pull_request: push: branches: [main] - tags: - schedule: - - cron: '0 0 * * *' jobs: - tests: - name: "Build and run parser tests" - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, macos-latest] - fail-fast: false + test: + runs-on: ubuntu-latest steps: - - name: Checkout parser sources - uses: actions/checkout@v2 - - - name: Checkout Zeek sources - uses: actions/checkout@v2 - with: - repository: zeek/zeek - path: test/zeek-src - - - uses: actions/setup-node@v2 - with: - node-version: '14' - - - run: npm install - - - name: Add Node.js to PATH - run: echo "$PWD/node_modules/.bin" >> $GITHUB_PATH - - - name: Setup tree-sitter - # "tree-sitter init-config" adds $HOME/github as a default - # directory to look for languages in, so we create a symlink - # that directs it to our local clone. - run: | - ln -s $(cd .. && pwd) $HOME/github - tree-sitter init-config - - - name: Generate parser - run: tree-sitter generate - - - name: Test Zeek grammar - run: cd test && ./parse-zeek-tree.sh ./zeek-src/scripts - - - name: Upload test artifacts - uses: actions/upload-artifact@v2 - if: failure() + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: - name: parser-errors - path: | - *.zeek - *.err + node-version: latest + - run: | + npm ci + - run: | + npm test + + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + - uses: pre-commit/action@v3.0.1 diff --git a/.gitignore b/.gitignore index e00b967..cf96d6b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1 @@ Cargo.toml -binding.gyp -bindings -src diff --git a/.gitmodules b/.gitmodules index 53461fb..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "src"] - path = src - url = https://github.com/ckreibich/tree-sitter-zeek-src diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..ced75c2 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,16 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v4.0.0-alpha.8 + hooks: + - id: prettier + +exclude: ^(src|bindings) diff --git a/README.md b/README.md new file mode 100644 index 0000000..ce86962 --- /dev/null +++ b/README.md @@ -0,0 +1,41 @@ +# tree-sitter-zeek + +[![Tests](https://github.com/zeek/tree-sitter-zeek/actions/workflows/test.yaml/badge.svg)](https://github.com/zeek/tree-sitter-zeek/actions/workflows/test.yaml) + +A [Zeek](https://zeek.org) grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter). + +## Background + +This grammar parses scripts written in the [Zeek scripting +language](https://docs.zeek.org/en/master/script-reference/index.html). + +The goal of this grammar is to facilitate tooling around Zeek +scripts. For that reason, its structure resembles Zeek's grammar but differs in +a number of ways. For example, it tracks newlines explicitly and relies more +strongly on precedence and associativity to resolve ambiguities. Like Zeek's +parser, this one currently doesn't name symbols deeply: for example, the grammar +features an `expr` rule that covers any kind of expression, but the choices +aren't currently broken down into, say, `addition_expr`, `or_expr`, and +similars. + +## Usage + +To use the generated parser directly (e.g. via any of tree-sitter's +[language bindings](https://tree-sitter.github.io/tree-sitter/#language-bindings)), +clone this repository recursively. We maintain a separate +[git repository](https://github.com/zeek/tree-sitter-zeek-src) +to track generated sources. You do not need the tree-sitter CLI +to use those sources in your tooling, but you'll likely want it +anyway to explore the parser. For example, `tree-sitter parse