Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ Grammar for Pascal and its dialects Delphi and Freepascal.
- Syntax highlighting
- Scopes


## Warren's fork of tree-sitter pascal is compatible with ML Code Index tools like REPOWISE
## warren's repowise fork has unit tests to test pascal unit parsing, for AI/ML/MCP integration.
# from warrens repowise fork
# https://github.com/wpostma/repowise
uv run --with-editable .\thirdparty\tree-sitter-pascal pytest test_parser.py -q

## Screenshots

(using nvim-treesitter)
Expand Down
Binary file not shown.
11 changes: 11 additions & 0 deletions bindings/python/tests/test_binding.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import ctypes
from unittest import TestCase

import tree_sitter
import tree_sitter_pascal


class TestLanguage(TestCase):
def test_returns_language_capsule(self):
capsule = tree_sitter_pascal.language()
self.assertEqual(type(capsule).__name__, "PyCapsule")

get_name = ctypes.pythonapi.PyCapsule_GetName
get_name.restype = ctypes.c_char_p
get_name.argtypes = [ctypes.py_object]

self.assertEqual(get_name(capsule).decode(), "tree_sitter.Language")

def test_can_load_grammar(self):
try:
tree_sitter.Language(tree_sitter_pascal.language())
Expand Down
45 changes: 45 additions & 0 deletions bindings/python/tree_sitter_pascal.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Metadata-Version: 2.4
Name: tree-sitter-pascal
Version: 0.9.1
Summary: Pascal grammar for tree-sitter
License: MIT
Project-URL: Homepage, https://github.com/tree-sitter/tree-sitter-pascal
Keywords: incremental,parsing,tree-sitter,pascal
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Topic :: Software Development :: Compilers
Classifier: Topic :: Text Processing :: Linguistic
Classifier: Typing :: Typed
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: core
Requires-Dist: tree-sitter~=0.21; extra == "core"
Dynamic: license-file

# tree-sitter-pascal

Grammar for Pascal and its dialects Delphi and Freepascal.

## Supported language features
- Classes, records, interfaces, class helpers
- Nested declarations
- Variant records
- Generics (Delphi- & FPC flavored)
- Anonymous procedures & functions
- Inline assember (but no highlighting)
- Extended RTTI attributes
- FPC PasCocoa extensions

## Tree-sitter features:
- Syntax highlighting
- Scopes

## Screenshots

(using nvim-treesitter)

<a href=".doc/scr1.png"><img src=".doc/scr1.png" style="width: 22%; height: 22%"></a>
<a href=".doc/scr2.png"><img src=".doc/scr2.png" style="width: 22%; height: 22%"></a>
<a href=".doc/scr3.png"><img src=".doc/scr3.png" style="width: 22%; height: 22%"></a>
<a href=".doc/scr4.png"><img src=".doc/scr4.png" style="width: 22%; height: 22%"></a>
22 changes: 22 additions & 0 deletions bindings/python/tree_sitter_pascal.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
LICENSE
README.md
pyproject.toml
setup.py
bindings/python/tree_sitter_pascal/binding.c
bindings/python/tree_sitter_pascal.egg-info/PKG-INFO
bindings/python/tree_sitter_pascal.egg-info/SOURCES.txt
bindings/python/tree_sitter_pascal.egg-info/dependency_links.txt
bindings/python/tree_sitter_pascal.egg-info/not-zip-safe
bindings/python/tree_sitter_pascal.egg-info/requires.txt
bindings/python/tree_sitter_pascal.egg-info/top_level.txt
bindings/python/tree_sitter_pascal/__init__.py
bindings/python/tree_sitter_pascal/__init__.pyi
bindings/python/tree_sitter_pascal/binding.c
bindings/python/tree_sitter_pascal/py.typed
bindings/python/tree_sitter_pascal.egg-info/PKG-INFO
bindings/python/tree_sitter_pascal.egg-info/SOURCES.txt
bindings/python/tree_sitter_pascal.egg-info/dependency_links.txt
bindings/python/tree_sitter_pascal.egg-info/not-zip-safe
bindings/python/tree_sitter_pascal.egg-info/requires.txt
bindings/python/tree_sitter_pascal.egg-info/top_level.txt
src/parser.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions bindings/python/tree_sitter_pascal.egg-info/not-zip-safe
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 3 additions & 0 deletions bindings/python/tree_sitter_pascal.egg-info/requires.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

[core]
tree-sitter~=0.21
2 changes: 2 additions & 0 deletions bindings/python/tree_sitter_pascal.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_binding
tree_sitter_pascal
5 changes: 4 additions & 1 deletion bindings/python/tree_sitter_pascal/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
def language() -> int: ...
from typing import Any


def language() -> Any: ...
Binary file not shown.
Binary file added bindings/python/tree_sitter_pascal/_binding.pyd
Binary file not shown.
2 changes: 1 addition & 1 deletion bindings/python/tree_sitter_pascal/binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ typedef struct TSLanguage TSLanguage;
TSLanguage *tree_sitter_pascal(void);

static PyObject* _binding_language(PyObject *self, PyObject *args) {
return PyLong_FromVoidPtr(tree_sitter_pascal());
return PyCapsule_New(tree_sitter_pascal(), "tree_sitter.Language", NULL);
}

static PyMethodDef methods[] = {
Expand Down
11 changes: 5 additions & 6 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ function statements(trailing) {

[rn('raise'), $ => seq(
$.kRaise,
field('exception', $._expr),
field('exception', optional($._expr)),
...semicolon
)],

Expand Down Expand Up @@ -814,8 +814,7 @@ module.exports = grammar({
$.kProperty,
field('name', $.identifier),
field('args', optional($.declPropArgs)),
':',
field('type', $.type),
optional(seq(':', field('type', $.type))),
repeat(choice(
seq($.kIndex, field('index', $._expr)),
...enable_if(delphi, seq($.kDispId, field('dispid', $._expr))),
Expand Down Expand Up @@ -1139,7 +1138,7 @@ module.exports = grammar({
kStatic: $ => /static/i,
kVirtual: $ => /virtual/i,
kAbstract: $ => /abstract/i,
kSealed: $ => /seled/i,
kSealed: $ => /sealed/i,
kDynamic: $ => /dynamic/i,
kOverride: $ => /override/i,
kOverload: $ => /overload/i,
Expand All @@ -1164,7 +1163,7 @@ module.exports = grammar({
kExport: $ => /export/i,
kFar: $ => /far/i,
kNear: $ => /near/i,
kSafecall: $ => /safecal/i,
kSafecall: $ => /safecall/i,
kAssembler: $ => /assembler/i,
kNostackframe: $ => /nostackframe/i,
kInterrupt: $ => /interrupt/i,
Expand Down Expand Up @@ -1193,7 +1192,7 @@ module.exports = grammar({
kIfndef: $ => /ifndef/i,
kEndif: $ => /endif/i,

identifier: $ => /[&]?[a-zA-Z_]+[0-9_a-zA-Z]*/,
identifier: $ => /[&]?[a-zA-Z_]+[0-9_a-zA-Z$]*/,

_space: $ => /[\s\r\n\t]+/,
pp: $ => /\{\$[^}]*\}/,
Expand Down
63 changes: 46 additions & 17 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1046,8 +1046,16 @@
"type": "FIELD",
"name": "exception",
"content": {
"type": "SYMBOL",
"name": "_expr"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expr"
},
{
"type": "BLANK"
}
]
}
},
{
Expand Down Expand Up @@ -2055,8 +2063,16 @@
"type": "FIELD",
"name": "exception",
"content": {
"type": "SYMBOL",
"name": "_expr"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expr"
},
{
"type": "BLANK"
}
]
}
}
]
Expand Down Expand Up @@ -6775,16 +6791,29 @@
}
},
{
"type": "STRING",
"value": ":"
},
{
"type": "FIELD",
"name": "type",
"content": {
"type": "SYMBOL",
"name": "type"
}
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ":"
},
{
"type": "FIELD",
"name": "type",
"content": {
"type": "SYMBOL",
"name": "type"
}
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
Expand Down Expand Up @@ -9282,7 +9311,7 @@
},
"kSealed": {
"type": "PATTERN",
"value": "seled",
"value": "sealed",
"flags": "i"
},
"kDynamic": {
Expand Down Expand Up @@ -9402,7 +9431,7 @@
},
"kSafecall": {
"type": "PATTERN",
"value": "safecal",
"value": "safecall",
"flags": "i"
},
"kAssembler": {
Expand Down Expand Up @@ -9527,7 +9556,7 @@
},
"identifier": {
"type": "PATTERN",
"value": "[&]?[a-zA-Z_]+[0-9_a-zA-Z]*"
"value": "[&]?[a-zA-Z_]+[0-9_a-zA-Z$]*"
},
"_space": {
"type": "PATTERN",
Expand Down
Loading