Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package ast-grep for openSUSE:Factory checked in at 2024-08-10 19:08:12 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/ast-grep (Old) and /work/SRC/openSUSE:Factory/.ast-grep.new.7232 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "ast-grep" Sat Aug 10 19:08:12 2024 rev:36 rq:1193093 version:0.26.1+0 Changes: -------- --- /work/SRC/openSUSE:Factory/ast-grep/ast-grep.changes 2024-08-08 10:58:05.190850864 +0200 +++ /work/SRC/openSUSE:Factory/.ast-grep.new.7232/ast-grep.changes 2024-08-10 19:13:57.989145640 +0200 @@ -1,0 +2,9 @@ +Sat Aug 10 04:37:33 UTC 2024 - Michael Vetter <mvetter@suse.com> + +- Update to 0.26.1: + * feat: support dynamic language in pyo3 #1143 + * test: add test for load dynamic lang in python 236f4ab + * feat: add py_lang registration function 43e74e7 + * feat: add pytype for register language 8b660cf + +------------------------------------------------------------------- Old: ---- ast-grep-0.26.0+0.tar.zst New: ---- ast-grep-0.26.1+0.tar.zst ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ ast-grep.spec ++++++ --- /var/tmp/diff_new_pack.ej11Tj/_old 2024-08-10 19:13:59.997229032 +0200 +++ /var/tmp/diff_new_pack.ej11Tj/_new 2024-08-10 19:13:59.997229032 +0200 @@ -17,7 +17,7 @@ Name: ast-grep -Version: 0.26.0+0 +Version: 0.26.1+0 Release: 0 Summary: A CLI tool for code structural search, lint and rewriting License: MIT ++++++ _service ++++++ --- /var/tmp/diff_new_pack.ej11Tj/_old 2024-08-10 19:14:00.037230693 +0200 +++ /var/tmp/diff_new_pack.ej11Tj/_new 2024-08-10 19:14:00.041230859 +0200 @@ -3,7 +3,7 @@ <param name="url">https://github.com/ast-grep/ast-grep.git</param> <param name="versionformat">@PARENT_TAG@+@TAG_OFFSET@</param> <param name="scm">git</param> - <param name="revision">0.26.0</param> + <param name="revision">0.26.1</param> <param name="match-tag">*</param> <param name="versionrewrite-pattern">v(\d+\.\d+\.\d+)</param> <param name="versionrewrite-replacement">\1</param> ++++++ ast-grep-0.26.0+0.tar.zst -> ast-grep-0.26.1+0.tar.zst ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ast-grep-0.26.0+0/CHANGELOG.md new/ast-grep-0.26.1+0/CHANGELOG.md --- old/ast-grep-0.26.0+0/CHANGELOG.md 2024-08-08 04:44:39.000000000 +0200 +++ new/ast-grep-0.26.1+0/CHANGELOG.md 2024-08-10 00:13:30.000000000 +0200 @@ -4,8 +4,17 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). +#### [0.26.1](https://github.com/ast-grep/ast-grep/compare/0.26.0...0.26.1) + +- feat: support dynamic language in pyo3 [`#1143`](https://github.com/ast-grep/ast-grep/issues/1143) +- test: add test for load dynamic lang in python [`236f4ab`](https://github.com/ast-grep/ast-grep/commit/236f4ab4d3faef4438c0516e406f3ca4...) +- feat: add py_lang registration function [`43e74e7`](https://github.com/ast-grep/ast-grep/commit/43e74e73cd458ef4635d24221206bda6...) +- feat: add pytype for register language [`8b660cf`](https://github.com/ast-grep/ast-grep/commit/8b660cf816de3afcfcd124951924521a...) + #### [0.26.0](https://github.com/ast-grep/ast-grep/compare/0.25.7...0.26.0) +> 7 August 2024 + - feat: Additional impls for language types [`#1379`](https://github.com/ast-grep/ast-grep/pull/1379) - feat: append note to error message if available [`#1384`](https://github.com/ast-grep/ast-grep/issues/1384) - fix: LSP should skip files outside the workspace root [`#1382`](https://github.com/ast-grep/ast-grep/issues/1382) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ast-grep-0.26.0+0/Cargo.lock new/ast-grep-0.26.1+0/Cargo.lock --- old/ast-grep-0.26.0+0/Cargo.lock 2024-08-08 04:44:39.000000000 +0200 +++ new/ast-grep-0.26.1+0/Cargo.lock 2024-08-10 00:13:30.000000000 +0200 @@ -113,7 +113,7 @@ [[package]] name = "ast-grep" -version = "0.26.0" +version = "0.26.1" dependencies = [ "ansi_term", "anyhow", @@ -144,7 +144,7 @@ [[package]] name = "ast-grep-config" -version = "0.26.0" +version = "0.26.1" dependencies = [ "anyhow", "ast-grep-core", @@ -160,7 +160,7 @@ [[package]] name = "ast-grep-core" -version = "0.26.0" +version = "0.26.1" dependencies = [ "bit-set", "regex", @@ -171,7 +171,7 @@ [[package]] name = "ast-grep-dynamic" -version = "0.26.0" +version = "0.26.1" dependencies = [ "ast-grep-core", "ignore", @@ -183,7 +183,7 @@ [[package]] name = "ast-grep-language" -version = "0.26.0" +version = "0.26.1" dependencies = [ "ast-grep-core", "ignore", @@ -215,7 +215,7 @@ [[package]] name = "ast-grep-lsp" -version = "0.26.0" +version = "0.26.1" dependencies = [ "ast-grep-config", "ast-grep-core", @@ -229,7 +229,7 @@ [[package]] name = "ast-grep-napi" -version = "0.26.0" +version = "0.26.1" dependencies = [ "ast-grep-config", "ast-grep-core", @@ -248,14 +248,16 @@ [[package]] name = "ast-grep-py" -version = "0.26.0" +version = "0.26.1" dependencies = [ "anyhow", "ast-grep-config", "ast-grep-core", + "ast-grep-dynamic", "ast-grep-language", "pyo3", "pythonize", + "serde", ] [[package]] @@ -314,7 +316,7 @@ [[package]] name = "benches" -version = "0.26.0" +version = "0.26.1" dependencies = [ "ast-grep-config", "ast-grep-core", diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ast-grep-0.26.0+0/Cargo.toml new/ast-grep-0.26.1+0/Cargo.toml --- old/ast-grep-0.26.0+0/Cargo.toml 2024-08-08 04:44:39.000000000 +0200 +++ new/ast-grep-0.26.1+0/Cargo.toml 2024-08-10 00:13:30.000000000 +0200 @@ -11,7 +11,7 @@ lto = true [workspace.package] -version = "0.26.0" +version = "0.26.1" authors = ["Herrington Darkholme <2883231+HerringtonDarkholme@users.noreply.github.com>"] edition = "2021" license = "MIT" @@ -22,11 +22,11 @@ readme = "README.md" [workspace.dependencies] -ast-grep-core = { path = "crates/core", version = "0.26.0" } -ast-grep-config = { path = "crates/config", version = "0.26.0" } -ast-grep-dynamic = { path = "crates/dynamic", version = "0.26.0" } -ast-grep-language = { path = "crates/language", version = "0.26.0" } -ast-grep-lsp = { path = "crates/lsp", version = "0.26.0" } +ast-grep-core = { path = "crates/core", version = "0.26.1" } +ast-grep-config = { path = "crates/config", version = "0.26.1" } +ast-grep-dynamic = { path = "crates/dynamic", version = "0.26.1" } +ast-grep-language = { path = "crates/language", version = "0.26.1" } +ast-grep-lsp = { path = "crates/lsp", version = "0.26.1" } bit-set = { version = "0.8.0" } ignore = { version = "0.4.22" } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ast-grep-0.26.0+0/crates/napi/npm/darwin-arm64/package.json new/ast-grep-0.26.1+0/crates/napi/npm/darwin-arm64/package.json --- old/ast-grep-0.26.0+0/crates/napi/npm/darwin-arm64/package.json 2024-08-08 04:44:39.000000000 +0200 +++ new/ast-grep-0.26.1+0/crates/napi/npm/darwin-arm64/package.json 2024-08-10 00:13:30.000000000 +0200 @@ -1,6 +1,6 @@ { "name": "@ast-grep/napi-darwin-arm64", - "version": "0.26.0", + "version": "0.26.1", "os": [ "darwin" ], diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ast-grep-0.26.0+0/crates/napi/npm/darwin-x64/package.json new/ast-grep-0.26.1+0/crates/napi/npm/darwin-x64/package.json --- old/ast-grep-0.26.0+0/crates/napi/npm/darwin-x64/package.json 2024-08-08 04:44:39.000000000 +0200 +++ new/ast-grep-0.26.1+0/crates/napi/npm/darwin-x64/package.json 2024-08-10 00:13:30.000000000 +0200 @@ -1,6 +1,6 @@ { "name": "@ast-grep/napi-darwin-x64", - "version": "0.26.0", + "version": "0.26.1", "os": [ "darwin" ], diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ast-grep-0.26.0+0/crates/napi/npm/linux-arm64-gnu/package.json new/ast-grep-0.26.1+0/crates/napi/npm/linux-arm64-gnu/package.json --- old/ast-grep-0.26.0+0/crates/napi/npm/linux-arm64-gnu/package.json 2024-08-08 04:44:39.000000000 +0200 +++ new/ast-grep-0.26.1+0/crates/napi/npm/linux-arm64-gnu/package.json 2024-08-10 00:13:30.000000000 +0200 @@ -1,6 +1,6 @@ { "name": "@ast-grep/napi-linux-arm64-gnu", - "version": "0.26.0", + "version": "0.26.1", "os": [ "linux" ], diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ast-grep-0.26.0+0/crates/napi/npm/linux-arm64-musl/package.json new/ast-grep-0.26.1+0/crates/napi/npm/linux-arm64-musl/package.json --- old/ast-grep-0.26.0+0/crates/napi/npm/linux-arm64-musl/package.json 2024-08-08 04:44:39.000000000 +0200 +++ new/ast-grep-0.26.1+0/crates/napi/npm/linux-arm64-musl/package.json 2024-08-10 00:13:30.000000000 +0200 @@ -1,6 +1,6 @@ { "name": "@ast-grep/napi-linux-arm64-musl", - "version": "0.26.0", + "version": "0.26.1", "os": [ "linux" ], diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ast-grep-0.26.0+0/crates/napi/npm/linux-x64-gnu/package.json new/ast-grep-0.26.1+0/crates/napi/npm/linux-x64-gnu/package.json --- old/ast-grep-0.26.0+0/crates/napi/npm/linux-x64-gnu/package.json 2024-08-08 04:44:39.000000000 +0200 +++ new/ast-grep-0.26.1+0/crates/napi/npm/linux-x64-gnu/package.json 2024-08-10 00:13:30.000000000 +0200 @@ -1,6 +1,6 @@ { "name": "@ast-grep/napi-linux-x64-gnu", - "version": "0.26.0", + "version": "0.26.1", "os": [ "linux" ], diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ast-grep-0.26.0+0/crates/napi/npm/linux-x64-musl/package.json new/ast-grep-0.26.1+0/crates/napi/npm/linux-x64-musl/package.json --- old/ast-grep-0.26.0+0/crates/napi/npm/linux-x64-musl/package.json 2024-08-08 04:44:39.000000000 +0200 +++ new/ast-grep-0.26.1+0/crates/napi/npm/linux-x64-musl/package.json 2024-08-10 00:13:30.000000000 +0200 @@ -1,6 +1,6 @@ { "name": "@ast-grep/napi-linux-x64-musl", - "version": "0.26.0", + "version": "0.26.1", "os": [ "linux" ], diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ast-grep-0.26.0+0/crates/napi/npm/win32-arm64-msvc/package.json new/ast-grep-0.26.1+0/crates/napi/npm/win32-arm64-msvc/package.json --- old/ast-grep-0.26.0+0/crates/napi/npm/win32-arm64-msvc/package.json 2024-08-08 04:44:39.000000000 +0200 +++ new/ast-grep-0.26.1+0/crates/napi/npm/win32-arm64-msvc/package.json 2024-08-10 00:13:30.000000000 +0200 @@ -1,6 +1,6 @@ { "name": "@ast-grep/napi-win32-arm64-msvc", - "version": "0.26.0", + "version": "0.26.1", "os": [ "win32" ], diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ast-grep-0.26.0+0/crates/napi/npm/win32-ia32-msvc/package.json new/ast-grep-0.26.1+0/crates/napi/npm/win32-ia32-msvc/package.json --- old/ast-grep-0.26.0+0/crates/napi/npm/win32-ia32-msvc/package.json 2024-08-08 04:44:39.000000000 +0200 +++ new/ast-grep-0.26.1+0/crates/napi/npm/win32-ia32-msvc/package.json 2024-08-10 00:13:30.000000000 +0200 @@ -1,6 +1,6 @@ { "name": "@ast-grep/napi-win32-ia32-msvc", - "version": "0.26.0", + "version": "0.26.1", "os": [ "win32" ], diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ast-grep-0.26.0+0/crates/napi/npm/win32-x64-msvc/package.json new/ast-grep-0.26.1+0/crates/napi/npm/win32-x64-msvc/package.json --- old/ast-grep-0.26.0+0/crates/napi/npm/win32-x64-msvc/package.json 2024-08-08 04:44:39.000000000 +0200 +++ new/ast-grep-0.26.1+0/crates/napi/npm/win32-x64-msvc/package.json 2024-08-10 00:13:30.000000000 +0200 @@ -1,6 +1,6 @@ { "name": "@ast-grep/napi-win32-x64-msvc", - "version": "0.26.0", + "version": "0.26.1", "os": [ "win32" ], diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ast-grep-0.26.0+0/crates/napi/package.json new/ast-grep-0.26.1+0/crates/napi/package.json --- old/ast-grep-0.26.0+0/crates/napi/package.json 2024-08-08 04:44:39.000000000 +0200 +++ new/ast-grep-0.26.1+0/crates/napi/package.json 2024-08-10 00:13:30.000000000 +0200 @@ -1,6 +1,6 @@ { "name": "@ast-grep/napi", - "version": "0.26.0", + "version": "0.26.1", "description": "Search and Rewrite code at large scale using precise AST pattern", "homepage": "https://ast-grep.github.io", "main": "index.js", diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ast-grep-0.26.0+0/crates/pyo3/Cargo.toml new/ast-grep-0.26.1+0/crates/pyo3/Cargo.toml --- old/ast-grep-0.26.0+0/crates/pyo3/Cargo.toml 2024-08-08 04:44:39.000000000 +0200 +++ new/ast-grep-0.26.1+0/crates/pyo3/Cargo.toml 2024-08-10 00:13:30.000000000 +0200 @@ -19,9 +19,11 @@ ast-grep-core.workspace = true ast-grep-config.workspace = true ast-grep-language.workspace = true +ast-grep-dynamic.workspace = true anyhow.workspace = true pyo3 = { version = "0.21.2", optional = true, features = ["anyhow"] } pythonize = { version = "0.21.1", optional = true } +serde.workspace = true # uncomment default features when developing pyo3 [features] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ast-grep-0.26.0+0/crates/pyo3/ast_grep_py/__init__.py new/ast-grep-0.26.1+0/crates/pyo3/ast_grep_py/__init__.py --- old/ast-grep-0.26.0+0/crates/pyo3/ast_grep_py/__init__.py 2024-08-08 04:44:39.000000000 +0200 +++ new/ast-grep-0.26.1+0/crates/pyo3/ast_grep_py/__init__.py 2024-08-10 00:13:30.000000000 +0200 @@ -1,7 +1,7 @@ from __future__ import annotations -from typing import List, TypedDict, Literal, Dict, Union, Mapping -from .ast_grep_py import SgNode, SgRoot, Pos, Range, Edit +from typing import List, TypedDict, Literal, Dict, Union, Mapping, Optional +from .ast_grep_py import SgNode, SgRoot, Pos, Range, Edit, register_dynamic_language Strictness = Union[Literal["cst"], Literal["smart"], Literal["ast"], Literal["relaxed"], Literal["signature"]] @@ -55,6 +55,12 @@ utils: Dict[str, Rule] transform: Dict[str, Mapping] +class CustomLang(TypedDict, total=False): + library_path: str + language_symbol: Optional[str] + meta_var_char: Optional[str] + expando_char: Optional[str] + __all__ = [ "Rule", "Config", @@ -66,4 +72,5 @@ "Pos", "Range", "Edit", + "register_dynamic_language", ] \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ast-grep-0.26.0+0/crates/pyo3/ast_grep_py/ast_grep_py.pyi new/ast-grep-0.26.1+0/crates/pyo3/ast_grep_py/ast_grep_py.pyi --- old/ast-grep-0.26.0+0/crates/pyo3/ast_grep_py/ast_grep_py.pyi 2024-08-08 04:44:39.000000000 +0200 +++ new/ast-grep-0.26.1+0/crates/pyo3/ast_grep_py/ast_grep_py.pyi 2024-08-10 00:13:30.000000000 +0200 @@ -1,6 +1,6 @@ -from typing import List, Optional, overload, Unpack +from typing import List, Optional, overload, Unpack, Dict -from . import Rule, Config +from . import Rule, Config, CustomLang class Pos: line: int @@ -65,4 +65,6 @@ # Edit def replace(self, new_text: str) -> Edit: ... - def commit_edits(self, edits: List[Edit]) -> str: ... \ No newline at end of file + def commit_edits(self, edits: List[Edit]) -> str: ... + +def register_dynamic_language(langs: Dict[str, CustomLang]): ... \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ast-grep-0.26.0+0/crates/pyo3/pyproject.toml new/ast-grep-0.26.1+0/crates/pyo3/pyproject.toml --- old/ast-grep-0.26.0+0/crates/pyo3/pyproject.toml 2024-08-08 04:44:39.000000000 +0200 +++ new/ast-grep-0.26.1+0/crates/pyo3/pyproject.toml 2024-08-10 00:13:30.000000000 +0200 @@ -5,7 +5,7 @@ [project] name = "ast-grep-py" requires-python = ">=3.8" -version = "0.26.0" +version = "0.26.1" description = "Structural Search and Rewrite code at large scale using precise AST pattern." authors = [{ name = "Herrington Darkholme", email = "2883231+HerringtonDarkholme@users.noreply.github.com" }] maintainers = [{ name = "Herrington Darkholme", email = "2883231+HerringtonDarkholme@users.noreply.github.com" }] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ast-grep-0.26.0+0/crates/pyo3/src/lib.rs new/ast-grep-0.26.1+0/crates/pyo3/src/lib.rs --- old/ast-grep-0.26.0+0/crates/pyo3/src/lib.rs 2024-08-08 04:44:39.000000000 +0200 +++ new/ast-grep-0.26.1+0/crates/pyo3/src/lib.rs 2024-08-10 00:13:30.000000000 +0200 @@ -1,13 +1,15 @@ #![cfg(not(test))] #![cfg(feature = "python")] +mod py_lang; mod py_node; mod range; mod unicode_position; +use py_lang::register_dynamic_language; use py_node::{Edit, SgNode}; use range::{Pos, Range}; use ast_grep_core::{AstGrep, Language, NodeMatch, StrDoc}; -use ast_grep_language::SupportLang; +use py_lang::PyLang; use pyo3::prelude::*; use unicode_position::UnicodePosition; @@ -20,12 +22,13 @@ m.add_class::<Range>()?; m.add_class::<Pos>()?; m.add_class::<Edit>()?; + m.add_function(wrap_pyfunction!(register_dynamic_language, m)?)?; Ok(()) } #[pyclass] struct SgRoot { - inner: AstGrep<StrDoc<SupportLang>>, + inner: AstGrep<StrDoc<PyLang>>, filename: String, pub(crate) position: UnicodePosition, } @@ -35,7 +38,7 @@ #[new] fn new(src: &str, lang: &str) -> Self { let position = UnicodePosition::new(src); - let lang: SupportLang = lang.parse().unwrap(); + let lang: PyLang = lang.parse().unwrap(); let inner = lang.ast_grep(src); Self { inner, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ast-grep-0.26.0+0/crates/pyo3/src/py_lang.rs new/ast-grep-0.26.1+0/crates/pyo3/src/py_lang.rs --- old/ast-grep-0.26.0+0/crates/pyo3/src/py_lang.rs 1970-01-01 01:00:00.000000000 +0100 +++ new/ast-grep-0.26.1+0/crates/pyo3/src/py_lang.rs 2024-08-10 00:13:30.000000000 +0200 @@ -0,0 +1,125 @@ +use ast_grep_core::language::TSLanguage; +use ast_grep_dynamic::{DynamicLang, Registration}; +use ast_grep_language::{Language, SupportLang}; +use serde::{Deserialize, Serialize}; + +use pyo3::prelude::*; +use pyo3::types::PyDict; +use pythonize::depythonize_bound; + +use std::borrow::Cow; +use std::collections::HashMap; +use std::fmt::{Debug, Display, Formatter}; +use std::path::{Path, PathBuf}; +use std::str::FromStr; + +#[derive(Serialize, Deserialize, Clone)] +pub struct CustomLang { + library_path: PathBuf, + /// the dylib symbol to load ts-language, default is `tree_sitter_{name}` + language_symbol: Option<String>, + meta_var_char: Option<char>, + expando_char: Option<char>, + // extensions: Vec<String>, +} + +#[pyfunction] +pub fn register_dynamic_language(dict: Bound<PyDict>) -> PyResult<()> { + let langs = depythonize_bound(dict.into_any())?; + let base = std::env::current_dir()?; + register(base, langs); + Ok(()) +} + +fn register(base: PathBuf, langs: HashMap<String, CustomLang>) { + let registrations = langs + .into_iter() + .map(|(name, custom)| to_registration(name, custom, &base)) + .collect(); + // TODO, add error handling + unsafe { DynamicLang::register(registrations).expect("TODO") } +} + +fn to_registration(name: String, custom_lang: CustomLang, base: &Path) -> Registration { + let path = base.join(custom_lang.library_path); + let sym = custom_lang + .language_symbol + .unwrap_or_else(|| format!("tree_sitter_{name}")); + Registration { + lang_name: name, + lib_path: path, + symbol: sym, + meta_var_char: custom_lang.meta_var_char, + expando_char: custom_lang.expando_char, + // extensions: custom_lang.extensions, + extensions: vec![], + } +} + +#[derive(Copy, Clone, PartialEq, Eq, Hash)] +pub enum PyLang { + // inlined support lang expando char + Builtin(SupportLang), + Custom(DynamicLang), +} +#[derive(Debug)] +pub enum PyLangErr { + LanguageNotSupported(String), +} + +impl Display for PyLangErr { + fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> { + use PyLangErr::*; + match self { + LanguageNotSupported(lang) => write!(f, "{} is not supported!", lang), + } + } +} + +impl std::error::Error for PyLangErr {} + +impl FromStr for PyLang { + type Err = PyLangErr; + fn from_str(s: &str) -> Result<Self, Self::Err> { + if let Ok(b) = SupportLang::from_str(s) { + Ok(PyLang::Builtin(b)) + } else if let Ok(c) = DynamicLang::from_str(s) { + Ok(PyLang::Custom(c)) + } else { + Err(PyLangErr::LanguageNotSupported(s.into())) + } + } +} + +use PyLang::*; +impl Language for PyLang { + fn get_ts_language(&self) -> TSLanguage { + match self { + Builtin(b) => b.get_ts_language(), + Custom(c) => c.get_ts_language(), + } + } + + fn pre_process_pattern<'q>(&self, query: &'q str) -> Cow<'q, str> { + match self { + Builtin(b) => b.pre_process_pattern(query), + Custom(c) => c.pre_process_pattern(query), + } + } + + #[inline] + fn meta_var_char(&self) -> char { + match self { + Builtin(b) => b.meta_var_char(), + Custom(c) => c.meta_var_char(), + } + } + + #[inline] + fn expando_char(&self) -> char { + match self { + Builtin(b) => b.expando_char(), + Custom(c) => c.expando_char(), + } + } +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ast-grep-0.26.0+0/crates/pyo3/src/py_node.rs new/ast-grep-0.26.1+0/crates/pyo3/src/py_node.rs --- old/ast-grep-0.26.0+0/crates/pyo3/src/py_node.rs 2024-08-08 04:44:39.000000000 +0200 +++ new/ast-grep-0.26.1+0/crates/pyo3/src/py_node.rs 2024-08-10 00:13:30.000000000 +0200 @@ -1,9 +1,9 @@ +use crate::py_lang::PyLang; use crate::range::Range; use crate::SgRoot; use ast_grep_config::{DeserializeEnv, RuleCore, SerializableRuleCore}; use ast_grep_core::{NodeMatch, StrDoc}; -use ast_grep_language::SupportLang; use std::collections::hash_map::DefaultHasher; use std::hash::{Hash, Hasher}; @@ -16,7 +16,7 @@ #[pyclass(mapping)] pub struct SgNode { - pub inner: NodeMatch<'static, StrDoc<SupportLang>>, + pub inner: NodeMatch<'static, StrDoc<PyLang>>, // refcount SgRoot pub(crate) root: Py<SgRoot>, } @@ -328,7 +328,7 @@ &self, config: Option<Bound<PyDict>>, kwargs: Option<Bound<PyDict>>, - ) -> PyResult<RuleCore<SupportLang>> { + ) -> PyResult<RuleCore<PyLang>> { let lang = self.inner.lang(); let config = if let Some(config) = config { config_from_dict(config)? @@ -358,10 +358,7 @@ }) } -fn get_matcher_from_rule( - lang: &SupportLang, - dict: Option<Bound<PyDict>>, -) -> PyResult<RuleCore<SupportLang>> { +fn get_matcher_from_rule(lang: &PyLang, dict: Option<Bound<PyDict>>) -> PyResult<RuleCore<PyLang>> { let rule = dict.ok_or_else(|| PyErr::new::<PyValueError, _>("rule must not be empty"))?; let env = DeserializeEnv::new(*lang); let config = config_from_rule(rule)?; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ast-grep-0.26.0+0/crates/pyo3/tests/test_register_lang.py new/ast-grep-0.26.1+0/crates/pyo3/tests/test_register_lang.py --- old/ast-grep-0.26.0+0/crates/pyo3/tests/test_register_lang.py 1970-01-01 01:00:00.000000000 +0100 +++ new/ast-grep-0.26.1+0/crates/pyo3/tests/test_register_lang.py 2024-08-10 00:13:30.000000000 +0200 @@ -0,0 +1,35 @@ +from ast_grep_py import SgRoot, register_dynamic_language +import platform + +source = """ +{ + "test": 123 +} +""".strip() + +# at the moment only test darwin arm64 +def is_arm_mac(): + return platform.system() == 'Darwin' and platform.processor() == 'arm' + +def register_lang(): + if not is_arm_mac(): + return + register_dynamic_language({ + "myjson": { + "library_path": "../../benches/fixtures/json-mac.so", + "language_symbol": "tree_sitter_json", + } + }) + +register_lang() + +def test_load_json_lang(): + if not is_arm_mac(): + return + sg = SgRoot(source, "myjson") + root = sg.root() + node = root.find(pattern="123") + assert node + assert node.kind() == "number" + node = root.find(pattern="456") + assert not node \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ast-grep-0.26.0+0/npm/package.json new/ast-grep-0.26.1+0/npm/package.json --- old/ast-grep-0.26.0+0/npm/package.json 2024-08-08 04:44:39.000000000 +0200 +++ new/ast-grep-0.26.1+0/npm/package.json 2024-08-10 00:13:30.000000000 +0200 @@ -1,6 +1,6 @@ { "name": "@ast-grep/cli", - "version": "0.26.0", + "version": "0.26.1", "publishConfig": { "access": "public" }, @@ -29,13 +29,13 @@ "postinstall": "node postinstall.js" }, "optionalDependencies": { - "@ast-grep/cli-win32-arm64-msvc": "0.26.0", - "@ast-grep/cli-win32-ia32-msvc": "0.26.0", - "@ast-grep/cli-win32-x64-msvc": "0.26.0", - "@ast-grep/cli-darwin-arm64": "0.26.0", - "@ast-grep/cli-darwin-x64": "0.26.0", - "@ast-grep/cli-linux-arm64-gnu": "0.26.0", - "@ast-grep/cli-linux-x64-gnu": "0.26.0" + "@ast-grep/cli-win32-arm64-msvc": "0.26.1", + "@ast-grep/cli-win32-ia32-msvc": "0.26.1", + "@ast-grep/cli-win32-x64-msvc": "0.26.1", + "@ast-grep/cli-darwin-arm64": "0.26.1", + "@ast-grep/cli-darwin-x64": "0.26.1", + "@ast-grep/cli-linux-arm64-gnu": "0.26.1", + "@ast-grep/cli-linux-x64-gnu": "0.26.1" }, "bin": { "sg": "sg", diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ast-grep-0.26.0+0/npm/platforms/darwin-arm64/package.json new/ast-grep-0.26.1+0/npm/platforms/darwin-arm64/package.json --- old/ast-grep-0.26.0+0/npm/platforms/darwin-arm64/package.json 2024-08-08 04:44:39.000000000 +0200 +++ new/ast-grep-0.26.1+0/npm/platforms/darwin-arm64/package.json 2024-08-10 00:13:30.000000000 +0200 @@ -1,6 +1,6 @@ { "name": "@ast-grep/cli-darwin-arm64", - "version": "0.26.0", + "version": "0.26.1", "os": [ "darwin" ], diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ast-grep-0.26.0+0/npm/platforms/darwin-x64/package.json new/ast-grep-0.26.1+0/npm/platforms/darwin-x64/package.json --- old/ast-grep-0.26.0+0/npm/platforms/darwin-x64/package.json 2024-08-08 04:44:39.000000000 +0200 +++ new/ast-grep-0.26.1+0/npm/platforms/darwin-x64/package.json 2024-08-10 00:13:30.000000000 +0200 @@ -1,6 +1,6 @@ { "name": "@ast-grep/cli-darwin-x64", - "version": "0.26.0", + "version": "0.26.1", "os": [ "darwin" ], diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ast-grep-0.26.0+0/npm/platforms/linux-arm64-gnu/package.json new/ast-grep-0.26.1+0/npm/platforms/linux-arm64-gnu/package.json --- old/ast-grep-0.26.0+0/npm/platforms/linux-arm64-gnu/package.json 2024-08-08 04:44:39.000000000 +0200 +++ new/ast-grep-0.26.1+0/npm/platforms/linux-arm64-gnu/package.json 2024-08-10 00:13:30.000000000 +0200 @@ -1,6 +1,6 @@ { "name": "@ast-grep/cli-linux-arm64-gnu", - "version": "0.26.0", + "version": "0.26.1", "os": [ "linux" ], diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ast-grep-0.26.0+0/npm/platforms/linux-x64-gnu/package.json new/ast-grep-0.26.1+0/npm/platforms/linux-x64-gnu/package.json --- old/ast-grep-0.26.0+0/npm/platforms/linux-x64-gnu/package.json 2024-08-08 04:44:39.000000000 +0200 +++ new/ast-grep-0.26.1+0/npm/platforms/linux-x64-gnu/package.json 2024-08-10 00:13:30.000000000 +0200 @@ -1,6 +1,6 @@ { "name": "@ast-grep/cli-linux-x64-gnu", - "version": "0.26.0", + "version": "0.26.1", "os": [ "linux" ], diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ast-grep-0.26.0+0/npm/platforms/win32-arm64-msvc/package.json new/ast-grep-0.26.1+0/npm/platforms/win32-arm64-msvc/package.json --- old/ast-grep-0.26.0+0/npm/platforms/win32-arm64-msvc/package.json 2024-08-08 04:44:39.000000000 +0200 +++ new/ast-grep-0.26.1+0/npm/platforms/win32-arm64-msvc/package.json 2024-08-10 00:13:30.000000000 +0200 @@ -1,6 +1,6 @@ { "name": "@ast-grep/cli-win32-arm64-msvc", - "version": "0.26.0", + "version": "0.26.1", "os": [ "win32" ], diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ast-grep-0.26.0+0/npm/platforms/win32-ia32-msvc/package.json new/ast-grep-0.26.1+0/npm/platforms/win32-ia32-msvc/package.json --- old/ast-grep-0.26.0+0/npm/platforms/win32-ia32-msvc/package.json 2024-08-08 04:44:39.000000000 +0200 +++ new/ast-grep-0.26.1+0/npm/platforms/win32-ia32-msvc/package.json 2024-08-10 00:13:30.000000000 +0200 @@ -1,6 +1,6 @@ { "name": "@ast-grep/cli-win32-ia32-msvc", - "version": "0.26.0", + "version": "0.26.1", "os": [ "win32" ], diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ast-grep-0.26.0+0/npm/platforms/win32-x64-msvc/package.json new/ast-grep-0.26.1+0/npm/platforms/win32-x64-msvc/package.json --- old/ast-grep-0.26.0+0/npm/platforms/win32-x64-msvc/package.json 2024-08-08 04:44:39.000000000 +0200 +++ new/ast-grep-0.26.1+0/npm/platforms/win32-x64-msvc/package.json 2024-08-10 00:13:30.000000000 +0200 @@ -1,6 +1,6 @@ { "name": "@ast-grep/cli-win32-x64-msvc", - "version": "0.26.0", + "version": "0.26.1", "os": [ "win32" ], diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ast-grep-0.26.0+0/pyproject.toml new/ast-grep-0.26.1+0/pyproject.toml --- old/ast-grep-0.26.0+0/pyproject.toml 2024-08-08 04:44:39.000000000 +0200 +++ new/ast-grep-0.26.1+0/pyproject.toml 2024-08-10 00:13:30.000000000 +0200 @@ -4,7 +4,7 @@ [project] name = "ast-grep-cli" -version = "0.26.0" +version = "0.26.1" description = "Structural Search and Rewrite code at large scale using precise AST pattern." authors = [{ name = "Herrington Darkholme", email = "2883231+HerringtonDarkholme@users.noreply.github.com" }] maintainers = [{ name = "Herrington Darkholme", email = "2883231+HerringtonDarkholme@users.noreply.github.com" }] ++++++ vendor.tar.zst ++++++ /work/SRC/openSUSE:Factory/ast-grep/vendor.tar.zst /work/SRC/openSUSE:Factory/.ast-grep.new.7232/vendor.tar.zst differ: char 281831, line 1195
participants (1)
-
Source-Sync