Skip to content

Commit

Permalink
Add lang from so example
Browse files Browse the repository at this point in the history
  • Loading branch information
Moosems committed Jul 23, 2024
1 parent ff34b0b commit 91954ad
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 4 deletions.
Empty file added docs/source/classes.rst
Empty file.
Empty file added docs/source/functions.rst
Empty file.
4 changes: 1 addition & 3 deletions docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ Installation

To start using ``Albero``, first install it using pip:

# TODO: get v0.0.1 done

.. code-block:: console
$ pip install Albero
$ pip install albero
And it's installed! Congratulations on giving your code editors syntax highlighting and allowing yourself to not pull out hair in the process!

Expand Down
Empty file added docs/source/variables.rst
Empty file.
29 changes: 29 additions & 0 deletions examples/example_so_file_usage.py
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 added examples/languages-darwin.so
Binary file not shown.
Binary file added tests/languages-darwin.so
Binary file not shown.
5 changes: 4 additions & 1 deletion tests/test_usage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from tree_sitter import Language

from albero import Token, TreeSitterHighlighter, get_lang, get_mapping
from albero import Token, TreeSitterHighlighter, get_lang, get_mapping, lang_from_so

py_lang: Language = get_lang("python")
mapping: dict[str, str] = get_mapping("python")
Expand Down Expand Up @@ -73,3 +73,6 @@ def test_mapping_update():
"test"
) # Trying to use a file not in the system gives an AlberoException
assert tokens == []

def test_so_file():
lang_from_so("./examples/languages-darwin.so", "python")

0 comments on commit 91954ad

Please sign in to comment.