-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
34 additions
and
4 deletions.
There are no files selected for viewing
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
from tree_sitter import Language | ||
|
||
from albero import Token, TreeSitterHighlighter, lang_from_so, get_mapping | ||
|
||
py_lang: Language = lang_from_so("./examples/languages-darwin.so", "python") | ||
mapping: dict[str, str] = get_mapping("python") | ||
|
||
|
||
highlighter = TreeSitterHighlighter() | ||
|
||
highlighter.add_language("python", py_lang, mapping) | ||
highlighter.add_file( | ||
"test", "python" | ||
) # Trying to add a file with a language not in the system gives an AlberoException | ||
highlighter.update_file( | ||
"test", "def test(): ..." | ||
) # Trying to update a file not in the system gives an AlberoException | ||
|
||
tokens: list[Token] = highlighter.get_highlights( | ||
"test" | ||
) # Trying to use a file not in the system gives an AlberoException | ||
|
||
highlighter.remove_file("test") | ||
highlighter.remove_language( | ||
"python" | ||
) # Can be done first but it will already auto-close any files that use it | ||
|
||
print(tokens) |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters