Skip to content

Commit

Permalink
Merge pull request #28 from watermarkhu/development
Browse files Browse the repository at this point in the history
Better find, caching, documentation
  • Loading branch information
watermarkhu authored Mar 6, 2024
2 parents ba24fb9 + 18dabb5 commit 8747140
Show file tree
Hide file tree
Showing 34 changed files with 1,875 additions and 172 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: documentation

on:
workflow_dispatch:
push:
branches:
- main
paths:
- 'docs/**'

permissions:
contents: write

jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install poetry
uses: abatilo/actions-poetry@v3

- name: Install dependencies
run: |
poetry install --without test,dev
- name: Sphinx build
run: |
cd docs && make html
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
with:
publish_branch: gh-pages
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/_build/
force_orphan: true
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,7 @@ cython_debug/
#.idea/

# Ruff cache
.ruff_cache/
.ruff_cache/

# Textemate cache
.textmate_cache/
5 changes: 3 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.2.2
rev: v0.3.0
hooks:
# Run the linter.
- id: ruff
Expand All @@ -19,5 +19,6 @@ repos:
exclude: |
(?x)^(
example.py|
test\/.*.py
test\/.*.py|
docs\/.*.py
)$
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Current File",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true
}
]
}
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

# textmate-grammar-python

An interpreter for grammar files as defined by TextMate and used in VSCode, implemented in Python. TextMate grammars use the oniguruma dialect (https://github.com/kkos/oniguruma). Supports loading grammar files from JSON, PLIST, or YAML format.
A lexer and tokenizer for grammar files as defined by TextMate and used in VSCode, implemented in Python. TextMate grammars use the oniguruma dialect (https://github.com/kkos/oniguruma). Supports loading grammar files from JSON, PLIST, or YAML format.


## Usage
Expand Down Expand Up @@ -65,8 +65,3 @@ Alternatively, with the keyword argument `flatten` the element is displayed as a
## TODO
- Implement Begin/While pattern, required for other grammars.

## Sources
- [Textmate guide](https://www.apeth.com/nonblog/stories/textmatebundle.html)
- [VSCode Syntax Highlighting guide](https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide)
- [vscode-textmate](https://github.com/microsoft/vscode-textmate)
- [Macromates texmate](https://macromates.com/textmate/manual/)
1 change: 1 addition & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./_build
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
11 changes: 11 additions & 0 deletions docs/apidocs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
API Reference
=============

This page contains auto-generated API reference documentation [#f1]_.

.. toctree::
:titlesonly:

textmate_grammar/textmate_grammar

.. [#f1] Created with `sphinx-autodoc2 <https://github.com/chrisjsewell/sphinx-autodoc2>`_
147 changes: 147 additions & 0 deletions docs/apidocs/textmate_grammar/textmate_grammar.cache.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
:py:mod:`textmate_grammar.cache`
================================

.. py:module:: textmate_grammar.cache
.. autodoc2-docstring:: textmate_grammar.cache
:allowtitles:

Module Contents
---------------

Classes
~~~~~~~

.. list-table::
:class: autosummary longtable
:align: left

* - :py:obj:`TextmateCache <textmate_grammar.cache.TextmateCache>`
- .. autodoc2-docstring:: textmate_grammar.cache.TextmateCache
:summary:
* - :py:obj:`SimpleCache <textmate_grammar.cache.SimpleCache>`
- .. autodoc2-docstring:: textmate_grammar.cache.SimpleCache
:summary:
* - :py:obj:`ShelveCache <textmate_grammar.cache.ShelveCache>`
- .. autodoc2-docstring:: textmate_grammar.cache.ShelveCache
:summary:

Functions
~~~~~~~~~

.. list-table::
:class: autosummary longtable
:align: left

* - :py:obj:`init_cache <textmate_grammar.cache.init_cache>`
- .. autodoc2-docstring:: textmate_grammar.cache.init_cache
:summary:

Data
~~~~

.. list-table::
:class: autosummary longtable
:align: left

* - :py:obj:`CACHE_DIR <textmate_grammar.cache.CACHE_DIR>`
- .. autodoc2-docstring:: textmate_grammar.cache.CACHE_DIR
:summary:
* - :py:obj:`CACHE <textmate_grammar.cache.CACHE>`
- .. autodoc2-docstring:: textmate_grammar.cache.CACHE
:summary:

API
~~~

.. py:data:: CACHE_DIR
:canonical: textmate_grammar.cache.CACHE_DIR
:value: 'resolve(...)'

.. autodoc2-docstring:: textmate_grammar.cache.CACHE_DIR

.. py:class:: TextmateCache
:canonical: textmate_grammar.cache.TextmateCache

Bases: :py:obj:`typing.Protocol`

.. autodoc2-docstring:: textmate_grammar.cache.TextmateCache

.. py:method:: cache_valid(filepath: pathlib.Path) -> bool
:canonical: textmate_grammar.cache.TextmateCache.cache_valid

.. autodoc2-docstring:: textmate_grammar.cache.TextmateCache.cache_valid

.. py:method:: load(filepath: pathlib.Path) -> textmate_grammar.elements.ContentElement
:canonical: textmate_grammar.cache.TextmateCache.load

.. autodoc2-docstring:: textmate_grammar.cache.TextmateCache.load

.. py:method:: save(filePath: pathlib.Path, element: textmate_grammar.elements.ContentElement) -> None
:canonical: textmate_grammar.cache.TextmateCache.save

.. autodoc2-docstring:: textmate_grammar.cache.TextmateCache.save

.. py:class:: SimpleCache()
:canonical: textmate_grammar.cache.SimpleCache

Bases: :py:obj:`textmate_grammar.cache.TextmateCache`

.. autodoc2-docstring:: textmate_grammar.cache.SimpleCache

.. rubric:: Initialization

.. autodoc2-docstring:: textmate_grammar.cache.SimpleCache.__init__

.. py:method:: cache_valid(filepath: pathlib.Path) -> bool
:canonical: textmate_grammar.cache.SimpleCache.cache_valid

.. autodoc2-docstring:: textmate_grammar.cache.SimpleCache.cache_valid

.. py:method:: load(filepath: pathlib.Path) -> textmate_grammar.elements.ContentElement
:canonical: textmate_grammar.cache.SimpleCache.load

.. autodoc2-docstring:: textmate_grammar.cache.SimpleCache.load

.. py:method:: save(filepath: pathlib.Path, element: textmate_grammar.elements.ContentElement) -> None
:canonical: textmate_grammar.cache.SimpleCache.save

.. autodoc2-docstring:: textmate_grammar.cache.SimpleCache.save

.. py:class:: ShelveCache()
:canonical: textmate_grammar.cache.ShelveCache

Bases: :py:obj:`textmate_grammar.cache.TextmateCache`

.. autodoc2-docstring:: textmate_grammar.cache.ShelveCache

.. rubric:: Initialization

.. autodoc2-docstring:: textmate_grammar.cache.ShelveCache.__init__

.. py:method:: cache_valid(filepath: pathlib.Path) -> bool
:canonical: textmate_grammar.cache.ShelveCache.cache_valid

.. autodoc2-docstring:: textmate_grammar.cache.ShelveCache.cache_valid

.. py:method:: load(filepath: pathlib.Path) -> textmate_grammar.elements.ContentElement
:canonical: textmate_grammar.cache.ShelveCache.load

.. autodoc2-docstring:: textmate_grammar.cache.ShelveCache.load

.. py:method:: save(filepath: pathlib.Path, element: textmate_grammar.elements.ContentElement) -> None
:canonical: textmate_grammar.cache.ShelveCache.save

.. autodoc2-docstring:: textmate_grammar.cache.ShelveCache.save

.. py:data:: CACHE
:canonical: textmate_grammar.cache.CACHE
:type: textmate_grammar.cache.TextmateCache
:value: 'SimpleCache(...)'

.. autodoc2-docstring:: textmate_grammar.cache.CACHE

.. py:function:: init_cache(type: str = 'simple') -> textmate_grammar.cache.TextmateCache
:canonical: textmate_grammar.cache.init_cache

.. autodoc2-docstring:: textmate_grammar.cache.init_cache
Loading

0 comments on commit 8747140

Please sign in to comment.