mirror of https://github.com/pyodide/pyodide.git
Add tree-sitter-java, tree-sitter-go, tree-sitter-python (#5102)
This is a follow-on to PR #5099 which added tree-sitter to the packages. This change adds tree-sitter-java, tree-sitter-go, tree-sitter-python packages and respective unit tests. Java, Go, and Python are popular languages, so its useful to add these grammars so a user can parse source code in those languages.
This commit is contained in:
parent
5fdd87b4cf
commit
858e0e4424
|
@ -41,3 +41,4 @@ pytest-pyodide
|
|||
tools/symlinks
|
||||
xbuildenv/
|
||||
.pyodide-xbuildenv*
|
||||
DS_Store
|
||||
|
|
|
@ -87,6 +87,9 @@ myst:
|
|||
- Added `iminuit` 2.29.1 {pr}`4767`, {pr}`5072`
|
||||
- Added `arro3-core`, `arro3-io`, and `arro3-compute` 0.3.0, 0.4.0, 0.4.1 {pr}`5020`, {pr}`5095`, {pr}`5104`
|
||||
- Added `tree-sitter` 0.23.0 {pr}`5099`
|
||||
- Added `tree-sitter-go` 0.23.1 {pr}`5102`
|
||||
- Added `tree-sitter-java` 0.23.2 {pr}`5102`
|
||||
- Added `tree-sitter-python` 0.23.2 {pr}`5102`
|
||||
|
||||
## Version 0.26.3
|
||||
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package:
|
||||
name: tree-sitter-go
|
||||
version: 0.23.1
|
||||
top-level:
|
||||
- tree_sitter_go
|
||||
source:
|
||||
# Have to use github source to work around broken sdist
|
||||
# https://github.com/tree-sitter/tree-sitter-go/pull/151
|
||||
url: https://github.com/tree-sitter/tree-sitter-go/archive/refs/tags/v0.23.1.tar.gz
|
||||
sha256: 4173bafc4c59be78642a0faf1bed8cb3854458aa59c506e8f51001a9f28da09b
|
||||
requirements:
|
||||
run:
|
||||
- tree-sitter
|
||||
host:
|
||||
- tree-sitter
|
||||
about:
|
||||
home: https://github.com/tree-sitter/tree-sitter-go
|
||||
PyPI: https://pypi.org/project/tree-sitter-go
|
||||
summary: Go grammar for tree-sitter
|
||||
license: MIT
|
||||
extra:
|
||||
recipe-maintainers:
|
||||
- ericwb
|
|
@ -0,0 +1,41 @@
|
|||
from pytest_pyodide import run_in_pyodide
|
||||
|
||||
|
||||
@run_in_pyodide(packages=["tree-sitter-go"])
|
||||
def test_tree_sitter_go(selenium):
|
||||
import textwrap
|
||||
|
||||
import tree_sitter_go
|
||||
from tree_sitter import Language, Parser
|
||||
|
||||
GO_LANGUAGE = Language(tree_sitter_go.language())
|
||||
parser = Parser(GO_LANGUAGE)
|
||||
|
||||
code = bytes(
|
||||
textwrap.dedent(
|
||||
"""
|
||||
func foo() {
|
||||
if bar {
|
||||
baz()
|
||||
}
|
||||
}
|
||||
"""
|
||||
),
|
||||
"utf-8",
|
||||
)
|
||||
tree = parser.parse(code)
|
||||
root_node = tree.root_node
|
||||
|
||||
assert str(root_node) == (
|
||||
"(source_file "
|
||||
"(function_declaration "
|
||||
"name: (identifier) "
|
||||
"parameters: (parameter_list) "
|
||||
"body: (block "
|
||||
"(if_statement "
|
||||
"condition: (identifier) "
|
||||
"consequence: (block "
|
||||
"(expression_statement (call_expression "
|
||||
"function: (identifier) "
|
||||
"arguments: (argument_list))))))))"
|
||||
)
|
|
@ -0,0 +1,23 @@
|
|||
package:
|
||||
name: tree-sitter-java
|
||||
version: 0.23.2
|
||||
top-level:
|
||||
- tree_sitter_java
|
||||
source:
|
||||
# Have to use github url to work around broken sdist:
|
||||
# https://github.com/tree-sitter/tree-sitter-java/pull/188
|
||||
url: https://github.com/tree-sitter/tree-sitter-java/archive/refs/tags/v0.23.2.tar.gz
|
||||
sha256: 062fe5746deb4e362ccb987228e7b41bfc017eb2b91a0413a7447719abaa07b2
|
||||
requirements:
|
||||
run:
|
||||
- tree-sitter
|
||||
host:
|
||||
- tree-sitter
|
||||
about:
|
||||
home: https://github.com/tree-sitter/tree-sitter-java
|
||||
PyPI: https://pypi.org/project/tree-sitter-java
|
||||
summary: Java grammar for tree-sitter
|
||||
license: MIT
|
||||
extra:
|
||||
recipe-maintainers:
|
||||
- ericwb
|
|
@ -0,0 +1,42 @@
|
|||
from pytest_pyodide import run_in_pyodide
|
||||
|
||||
|
||||
@run_in_pyodide(packages=["tree-sitter-java"])
|
||||
def test_tree_sitter_java(selenium):
|
||||
import textwrap
|
||||
|
||||
import tree_sitter_java
|
||||
from tree_sitter import Language, Parser
|
||||
|
||||
JAV_LANGUAGE = Language(tree_sitter_java.language())
|
||||
parser = Parser(JAV_LANGUAGE)
|
||||
|
||||
code = bytes(
|
||||
textwrap.dedent(
|
||||
"""
|
||||
void foo() {
|
||||
if (bar) {
|
||||
baz();
|
||||
}
|
||||
}
|
||||
"""
|
||||
),
|
||||
"utf-8",
|
||||
)
|
||||
tree = parser.parse(code)
|
||||
root_node = tree.root_node
|
||||
|
||||
assert str(root_node) == (
|
||||
"(program "
|
||||
"(method_declaration "
|
||||
"type: (void_type) "
|
||||
"name: (identifier) "
|
||||
"parameters: (formal_parameters) "
|
||||
"body: (block "
|
||||
"(if_statement "
|
||||
"condition: (parenthesized_expression (identifier)) "
|
||||
"consequence: (block "
|
||||
"(expression_statement (method_invocation "
|
||||
"name: (identifier) "
|
||||
"arguments: (argument_list))))))))"
|
||||
)
|
|
@ -0,0 +1,23 @@
|
|||
package:
|
||||
name: tree-sitter-python
|
||||
version: 0.23.2
|
||||
top-level:
|
||||
- tree_sitter_python
|
||||
source:
|
||||
# Have to use github url to work around broken sdist:
|
||||
# https://github.com/tree-sitter/tree-sitter-python/pull/285
|
||||
url: https://github.com/tree-sitter/tree-sitter-python/archive/refs/tags/v0.23.2.tar.gz
|
||||
sha256: b38e5b1f5237377b506109978af76422975bda5859165835e3c7b5afee987383
|
||||
requirements:
|
||||
run:
|
||||
- tree-sitter
|
||||
host:
|
||||
- tree-sitter
|
||||
about:
|
||||
home: https://github.com/tree-sitter/tree-sitter-python
|
||||
PyPI: https://pypi.org/project/tree-sitter-python
|
||||
summary: Python grammar for tree-sitter
|
||||
license: MIT
|
||||
extra:
|
||||
recipe-maintainers:
|
||||
- ericwb
|
|
@ -0,0 +1,39 @@
|
|||
from pytest_pyodide import run_in_pyodide
|
||||
|
||||
|
||||
@run_in_pyodide(packages=["tree-sitter-python"])
|
||||
def test_tree_sitter_python(selenium):
|
||||
import textwrap
|
||||
|
||||
import tree_sitter_python
|
||||
from tree_sitter import Language, Parser
|
||||
|
||||
PY_LANGUAGE = Language(tree_sitter_python.language())
|
||||
parser = Parser(PY_LANGUAGE)
|
||||
|
||||
code = bytes(
|
||||
textwrap.dedent(
|
||||
"""
|
||||
def foo():
|
||||
if bar:
|
||||
baz()
|
||||
"""
|
||||
),
|
||||
"utf-8",
|
||||
)
|
||||
tree = parser.parse(code)
|
||||
root_node = tree.root_node
|
||||
|
||||
assert str(root_node) == (
|
||||
"(module "
|
||||
"(function_definition "
|
||||
"name: (identifier) "
|
||||
"parameters: (parameters) "
|
||||
"body: (block "
|
||||
"(if_statement "
|
||||
"condition: (identifier) "
|
||||
"consequence: (block "
|
||||
"(expression_statement (call "
|
||||
"function: (identifier) "
|
||||
"arguments: (argument_list))))))))"
|
||||
)
|
Loading…
Reference in New Issue