Skip to content

Commit

Permalink
Use Python package for tree-sitter-zeek
Browse files Browse the repository at this point in the history
tree-sitter-zeek now provides a Python package we can directly depend
on. With this we can avoid building and shipping the generated
tree-sitter bindings. By using the "official upstream API" we can also
simplify the way we parse input.
  • Loading branch information
bbannier committed Jun 19, 2024
1 parent 046475d commit 8c6a6fe
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 69 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
build
dist
*.egg-info
zeekscript/zeek-language.so
zeekscript/zeek-language.exp
zeekscript/zeek-language.lib
__pycache__
.idea/
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

4 changes: 3 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ repos:
hooks:
- id: pylint
additional_dependencies:
- setuptools
- "setuptools"
- "tree-sitter>=0.21.3"
- "tree-sitter-zeek"

- repo: https://github.com/psf/black
rev: 23.10.1
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ keywords = [
"parsing",
]

requires-python = ">=3.8"
requires-python = ">=3.9"

dependencies = [
"tree-sitter>=0.21.3",
"tree-sitter-zeek",
]

[project.optional-dependencies]
Expand Down
1 change: 0 additions & 1 deletion tree-sitter-zeek
Submodule tree-sitter-zeek deleted from b1fdab
3 changes: 1 addition & 2 deletions zeekscript/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"""Wrapper around more low-level tests."""
__version__ = "1.2.9"
__all__ = ["cli", "error", "formatter", "node", "output", "parser", "script"]
__all__ = ["cli", "error", "formatter", "node", "output", "script"]

from .cli import *
from .error import *
from .formatter import *
from .node import *
from .output import *
from .parser import *
from .script import *
56 changes: 0 additions & 56 deletions zeekscript/parser.py

This file was deleted.

7 changes: 5 additions & 2 deletions zeekscript/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import pathlib
import sys

import tree_sitter
import tree_sitter_zeek

from .error import FileError, ParserError
from .formatter import Formatter
from .node import Node
from .output import OutputStream
from .parser import Parser


class Script:
Expand Down Expand Up @@ -55,7 +57,8 @@ def parse(self):
except OSError as err:
raise FileError(str(err)) from err

self.ts_tree = Parser().parse(self.source)
parser = tree_sitter.Parser(tree_sitter.Language(tree_sitter_zeek.language()))
self.ts_tree = parser.parse(self.source)

if self.ts_tree is None or self.ts_tree.root_node is None:
# This is a hard parse error and we need to bail. Smaller errors get
Expand Down

0 comments on commit 8c6a6fe

Please sign in to comment.