protonabu 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- protonabu-1.0.0/LICENSE +21 -0
- protonabu-1.0.0/PKG-INFO +75 -0
- protonabu-1.0.0/README.md +52 -0
- protonabu-1.0.0/pyproject.toml +40 -0
- protonabu-1.0.0/setup.cfg +4 -0
- protonabu-1.0.0/src/protonabu/__init__.py +54 -0
- protonabu-1.0.0/src/protonabu/adapter/__init__.py +18 -0
- protonabu-1.0.0/src/protonabu/adapter/adapterFactory.py +99 -0
- protonabu-1.0.0/src/protonabu/adapter/addendum.nabu +36 -0
- protonabu-1.0.0/src/protonabu/adapter/contrib/__init__.py +1 -0
- protonabu-1.0.0/src/protonabu/adapter/snippetAdapter.py +99 -0
- protonabu-1.0.0/src/protonabu/adapter/std/JsonSnippetAdapter/__init__.py +1 -0
- protonabu-1.0.0/src/protonabu/adapter/std/JsonSnippetAdapter/jsonSnippetAdapter.py +235 -0
- protonabu-1.0.0/src/protonabu/adapter/std/MarkdownSnippetAdapter/__init__.py +1 -0
- protonabu-1.0.0/src/protonabu/adapter/std/MarkdownSnippetAdapter/markdownSnippetAdapter.py +94 -0
- protonabu-1.0.0/src/protonabu/adapter/std/XmlSnippetAdapter/__init__.py +1 -0
- protonabu-1.0.0/src/protonabu/adapter/std/XmlSnippetAdapter/xmlSnippetAdapter.py +278 -0
- protonabu-1.0.0/src/protonabu/adapter/std/__init__.py +1 -0
- protonabu-1.0.0/src/protonabu/adapter/testSnippetAdapters.py +257 -0
- protonabu-1.0.0/src/protonabu/addendum.nabu +67 -0
- protonabu-1.0.0/src/protonabu/config.py +198 -0
- protonabu-1.0.0/src/protonabu/demoApp/__init__.py +0 -0
- protonabu-1.0.0/src/protonabu/demoApp/__main__.py +62 -0
- protonabu-1.0.0/src/protonabu/demoApp/doc/schema/publishSchema.py +35 -0
- protonabu-1.0.0/src/protonabu/demoApp/example/demo_site.facts +101 -0
- protonabu-1.0.0/src/protonabu/demoApp/htmlBuilder.py +482 -0
- protonabu-1.0.0/src/protonabu/demoApp/pdfExporter.py +239 -0
- protonabu-1.0.0/src/protonabu/demoApp/schema.facts +63 -0
- protonabu-1.0.0/src/protonabu/demoApp/siteGenerator.py +424 -0
- protonabu-1.0.0/src/protonabu/demoApp/siteModel.py +443 -0
- protonabu-1.0.0/src/protonabu/demoApp/siteParser.py +387 -0
- protonabu-1.0.0/src/protonabu/demoApp/styles.css +441 -0
- protonabu-1.0.0/src/protonabu/demoApp/testSiteGenerator.py +121 -0
- protonabu-1.0.0/src/protonabu/factParser.py +766 -0
- protonabu-1.0.0/src/protonabu/factSnippet.py +479 -0
- protonabu-1.0.0/src/protonabu/primitiveTokens.py +294 -0
- protonabu-1.0.0/src/protonabu/protonabuParser.py +866 -0
- protonabu-1.0.0/src/protonabu/protonabuSchema.py +655 -0
- protonabu-1.0.0/src/protonabu/rawFact.py +717 -0
- protonabu-1.0.0/src/protonabu/rawFactTestData.py +56 -0
- protonabu-1.0.0/src/protonabu/reportSchema.py +326 -0
- protonabu-1.0.0/src/protonabu/testLoops.py +195 -0
- protonabu-1.0.0/src/protonabu/testProtonabuParser.py +819 -0
- protonabu-1.0.0/src/protonabu/testRawFact.py +94 -0
- protonabu-1.0.0/src/protonabu/testStringUtil.py +215 -0
- protonabu-1.0.0/src/protonabu/testing/__init__.py +6 -0
- protonabu-1.0.0/src/protonabu/testing/addendum.nabu +10 -0
- protonabu-1.0.0/src/protonabu/testing/testing.py +305 -0
- protonabu-1.0.0/src/protonabu/tokenizedFact.py +407 -0
- protonabu-1.0.0/src/protonabu/util/__init__.py +20 -0
- protonabu-1.0.0/src/protonabu/util/addendum.nabu +14 -0
- protonabu-1.0.0/src/protonabu/util/error.py +190 -0
- protonabu-1.0.0/src/protonabu/util/loops.py +185 -0
- protonabu-1.0.0/src/protonabu/util/progress.py +94 -0
- protonabu-1.0.0/src/protonabu/util/stringUtil.py +922 -0
- protonabu-1.0.0/src/protonabu.egg-info/PKG-INFO +75 -0
- protonabu-1.0.0/src/protonabu.egg-info/SOURCES.txt +58 -0
- protonabu-1.0.0/src/protonabu.egg-info/dependency_links.txt +1 -0
- protonabu-1.0.0/src/protonabu.egg-info/requires.txt +1 -0
- protonabu-1.0.0/src/protonabu.egg-info/top_level.txt +1 -0
protonabu-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Avner Ben
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
protonabu-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: protonabu
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Open source infrastructure for authoring Domain-Specific Languages (DSLs), originally facilitating the Nabu Design Language
|
|
5
|
+
Author-email: Avner Ben <avnerben6@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: nabu,design,facts,parser,schema,dsl
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
17
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: pyparsing>=3.0.0
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# Protonabu
|
|
25
|
+
|
|
26
|
+
*Open source infrastructure for authoring Domain-Specific Languages (DSLs), originally facilitating the Nabu Design Language.*
|
|
27
|
+
|
|
28
|
+
- **Author:** Avner Ben
|
|
29
|
+
- **Version:** 1.0.0
|
|
30
|
+
- **License:** MIT
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Overview
|
|
35
|
+
|
|
36
|
+
**Protonabu** is the self-contained parser and runtime substrate of the Nabu ecosystem. It provides:
|
|
37
|
+
|
|
38
|
+
1. **Fact Parsing & Schema Engine:** Hierarchical, indentation-aware fact-base parsing against dynamic BNF-like schemas (`ProtonabuParser`, `ProtonabuSchema`, `RawFact`, `TokenizedFact`).
|
|
39
|
+
2. **Snippet Adapters:** Bi-directional snippet conversion and round-tripping for multiple structured formats including Markdown, JSON, and XML (`FactSnippetAdapter`, `snippetAdapterFactory`).
|
|
40
|
+
3. **Core Utility Library:** Standardized naming conventions (`NameMaker`, `QuantityNarrator`, `DocDate`), hierarchy traversal utilities (`iterUp`, `iterUps`, `find`, `findBehind`, `findNested`), progress reporting (`IProgressIndicator`, `DummyProgressIndicator`), and typed structured exception hierarchies (`Error`, `InternalError`, `ParsingError`, `FactFileError`).
|
|
41
|
+
4. **Testing Infrastructure:** Common testing harness and runner for test discovery and regression test execution (`testing.py`).
|
|
42
|
+
5. **Educational Site Generator Demo:** A complete demonstration application that compiles `.facts` site descriptions into static HTML sites and multi-page hyperlinked PDF books (`SiteGenerator`, `SiteParser`, `pdfExporter`).
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Installation
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pip install protonabu
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Or for local development:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install -e .
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Running Tests
|
|
61
|
+
|
|
62
|
+
To run the complete test suite:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
python programs/testAll.py
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Architecture & Interfaces
|
|
71
|
+
|
|
72
|
+
Detailed specifications and exported design interfaces are available in `doc/`:
|
|
73
|
+
- `doc/ProtonabuUserGuide.md` — Protonabu User Guide & Architecture
|
|
74
|
+
- `doc/NabuInCodeDocumentation.md` — Nabu In-Code Documentation Standards
|
|
75
|
+
- `doc/exported/` — Nabu design fact-bases and formal exported interface definitions
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Protonabu
|
|
2
|
+
|
|
3
|
+
*Open source infrastructure for authoring Domain-Specific Languages (DSLs), originally facilitating the Nabu Design Language.*
|
|
4
|
+
|
|
5
|
+
- **Author:** Avner Ben
|
|
6
|
+
- **Version:** 1.0.0
|
|
7
|
+
- **License:** MIT
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
**Protonabu** is the self-contained parser and runtime substrate of the Nabu ecosystem. It provides:
|
|
14
|
+
|
|
15
|
+
1. **Fact Parsing & Schema Engine:** Hierarchical, indentation-aware fact-base parsing against dynamic BNF-like schemas (`ProtonabuParser`, `ProtonabuSchema`, `RawFact`, `TokenizedFact`).
|
|
16
|
+
2. **Snippet Adapters:** Bi-directional snippet conversion and round-tripping for multiple structured formats including Markdown, JSON, and XML (`FactSnippetAdapter`, `snippetAdapterFactory`).
|
|
17
|
+
3. **Core Utility Library:** Standardized naming conventions (`NameMaker`, `QuantityNarrator`, `DocDate`), hierarchy traversal utilities (`iterUp`, `iterUps`, `find`, `findBehind`, `findNested`), progress reporting (`IProgressIndicator`, `DummyProgressIndicator`), and typed structured exception hierarchies (`Error`, `InternalError`, `ParsingError`, `FactFileError`).
|
|
18
|
+
4. **Testing Infrastructure:** Common testing harness and runner for test discovery and regression test execution (`testing.py`).
|
|
19
|
+
5. **Educational Site Generator Demo:** A complete demonstration application that compiles `.facts` site descriptions into static HTML sites and multi-page hyperlinked PDF books (`SiteGenerator`, `SiteParser`, `pdfExporter`).
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install protonabu
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Or for local development:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install -e .
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Running Tests
|
|
38
|
+
|
|
39
|
+
To run the complete test suite:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
python programs/testAll.py
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Architecture & Interfaces
|
|
48
|
+
|
|
49
|
+
Detailed specifications and exported design interfaces are available in `doc/`:
|
|
50
|
+
- `doc/ProtonabuUserGuide.md` — Protonabu User Guide & Architecture
|
|
51
|
+
- `doc/NabuInCodeDocumentation.md` — Nabu In-Code Documentation Standards
|
|
52
|
+
- `doc/exported/` — Nabu design fact-bases and formal exported interface definitions
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "protonabu"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Open source infrastructure for authoring Domain-Specific Languages (DSLs), originally facilitating the Nabu Design Language"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = [
|
|
11
|
+
{ name = "Avner Ben", email = "avnerben6@gmail.com" }
|
|
12
|
+
]
|
|
13
|
+
license = { text = "MIT" }
|
|
14
|
+
requires-python = ">=3.10"
|
|
15
|
+
keywords = ["nabu", "design", "facts", "parser", "schema", "dsl"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3.10",
|
|
19
|
+
"Programming Language :: Python :: 3.11",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
"Programming Language :: Python :: 3.13",
|
|
22
|
+
"Programming Language :: Python :: 3.14",
|
|
23
|
+
"License :: OSI Approved :: MIT License",
|
|
24
|
+
"Operating System :: OS Independent",
|
|
25
|
+
"Topic :: Software Development :: Code Generators",
|
|
26
|
+
"Topic :: Software Development :: Compilers",
|
|
27
|
+
]
|
|
28
|
+
dependencies = [
|
|
29
|
+
"pyparsing>=3.0.0",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[tool.setuptools.packages.find]
|
|
33
|
+
where = ["src"]
|
|
34
|
+
|
|
35
|
+
[tool.setuptools.package-data]
|
|
36
|
+
"protonabu" = ["*.nabu", "addendum.nabu"]
|
|
37
|
+
"protonabu.adapter" = ["*.nabu", "addendum.nabu"]
|
|
38
|
+
"protonabu.demoApp" = ["*.facts", "*.css", "schema.facts", "addendum.nabu", "example/*.facts"]
|
|
39
|
+
"protonabu.testing" = ["*.nabu", "addendum.nabu"]
|
|
40
|
+
"protonabu.util" = ["*.nabu", "addendum.nabu"]
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
""" Protonabu DSL Infrastructure Version """
|
|
2
|
+
__version__ = '1.0.0'
|
|
3
|
+
|
|
4
|
+
from .rawFact import RawFact
|
|
5
|
+
from .tokenizedFact import TokenizedFact
|
|
6
|
+
from .factSnippet import (
|
|
7
|
+
ProtonabuSnippet,
|
|
8
|
+
ProtonabuSnippetFromFile,
|
|
9
|
+
ProtonabuSnippetFromOpenFile,
|
|
10
|
+
ProtonabuSnippetInMemory
|
|
11
|
+
)
|
|
12
|
+
from .protonabuSchema import (
|
|
13
|
+
ProtonabuSchema,
|
|
14
|
+
Label,
|
|
15
|
+
ProtonabuParsingStack
|
|
16
|
+
)
|
|
17
|
+
from .protonabuParser import (
|
|
18
|
+
SnippetParser,
|
|
19
|
+
ProtonabuParseDispatcher,
|
|
20
|
+
ProtonabuParser,
|
|
21
|
+
ImportingProtonabuParser
|
|
22
|
+
)
|
|
23
|
+
from .util.error import (
|
|
24
|
+
Error,
|
|
25
|
+
InternalError,
|
|
26
|
+
ParsingError,
|
|
27
|
+
FactFileError
|
|
28
|
+
)
|
|
29
|
+
from .util.progress import (
|
|
30
|
+
IProgressIndicator,
|
|
31
|
+
DummyProgressIndicator
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
__all__ = [
|
|
35
|
+
'RawFact',
|
|
36
|
+
'TokenizedFact',
|
|
37
|
+
'ProtonabuSnippet',
|
|
38
|
+
'ProtonabuSnippetFromFile',
|
|
39
|
+
'ProtonabuSnippetFromOpenFile',
|
|
40
|
+
'ProtonabuSnippetInMemory',
|
|
41
|
+
'ProtonabuSchema',
|
|
42
|
+
'Label',
|
|
43
|
+
'ProtonabuParsingStack',
|
|
44
|
+
'SnippetParser',
|
|
45
|
+
'ProtonabuParseDispatcher',
|
|
46
|
+
'ProtonabuParser',
|
|
47
|
+
'ImportingProtonabuParser',
|
|
48
|
+
'Error',
|
|
49
|
+
'InternalError',
|
|
50
|
+
'ParsingError',
|
|
51
|
+
'FactFileError',
|
|
52
|
+
'IProgressIndicator',
|
|
53
|
+
'DummyProgressIndicator',
|
|
54
|
+
]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
""" Package: Protonabu Snippet Adapter
|
|
2
|
+
- Author: Avner Ben
|
|
3
|
+
- Created: 17-May-2026
|
|
4
|
+
- Generator: Antigravity (Claude Opus 4.6)
|
|
5
|
+
- Generated: 17-May-2026
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from .adapterFactory import snippetAdapterFactory
|
|
9
|
+
|
|
10
|
+
# to register standard Snippet Adapters
|
|
11
|
+
from .std.MarkdownSnippetAdapter.markdownSnippetAdapter import MarkdownSnippetAdapter
|
|
12
|
+
from .std.JsonSnippetAdapter.jsonSnippetAdapter import JsonSnippetAdapter
|
|
13
|
+
from .std.XmlSnippetAdapter.xmlSnippetAdapter import XmlSnippetAdapter
|
|
14
|
+
|
|
15
|
+
snippetAdapterFactory.register(MarkdownSnippetAdapter())
|
|
16
|
+
snippetAdapterFactory.register(JsonSnippetAdapter())
|
|
17
|
+
snippetAdapterFactory.register(XmlSnippetAdapter())
|
|
18
|
+
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
""" Module: Protonabu Snippet Adapter Factory
|
|
2
|
+
- Author: Avner Ben
|
|
3
|
+
- Created: 17-May-2026
|
|
4
|
+
- Generator: Antigravity (Claude Opus 4.6)
|
|
5
|
+
- Generated: 17-May-2026
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import Optional, TYPE_CHECKING
|
|
11
|
+
|
|
12
|
+
from ..util.error import InternalError
|
|
13
|
+
# [Additional]
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from ..factSnippet import ProtonabuSnippet
|
|
16
|
+
# [Additional]
|
|
17
|
+
from .snippetAdapter import FactSnippetAdapter
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class SnippetAdapterFactory:
|
|
21
|
+
""" Snippet Adapter Factory
|
|
22
|
+
- Purpose: to provide Snippet Adapter by file extension
|
|
23
|
+
- Stereotype: Singleton
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def __init__(self):
|
|
27
|
+
""" to INITIALIZE Snippet Adapter Factory
|
|
28
|
+
- Exported
|
|
29
|
+
"""
|
|
30
|
+
# Contains [0-N by Reference]: Snippet Adapter [Role "adapters]
|
|
31
|
+
# - Key: file extension
|
|
32
|
+
self.adapters: dict[str, FactSnippetAdapter] = {}
|
|
33
|
+
|
|
34
|
+
def register(self, adapter: FactSnippetAdapter):
|
|
35
|
+
""" to register Snippet Adapter
|
|
36
|
+
- Exported
|
|
37
|
+
- definitive [Part]
|
|
38
|
+
"""
|
|
39
|
+
# [Scan "file extensions"]: to register adapter
|
|
40
|
+
for ext in adapter.fileExtensions:
|
|
41
|
+
normalizedExt = ext if ext.startswith('.') else f'.{ext}'
|
|
42
|
+
# [Esc "Error"]: duplicate registration
|
|
43
|
+
if normalizedExt in self.adapters:
|
|
44
|
+
raise InternalError('Snippet adapter already registered for extension', [
|
|
45
|
+
('Extension', normalizedExt),
|
|
46
|
+
('Existing', type(self.adapters[normalizedExt]).__name__),
|
|
47
|
+
('New', type(adapter).__name__)
|
|
48
|
+
])
|
|
49
|
+
self.adapters[normalizedExt] = adapter
|
|
50
|
+
|
|
51
|
+
def getAdapter(self, fileName: str) -> Optional[FactSnippetAdapter]:
|
|
52
|
+
""" to get Snippet Adapter by file name
|
|
53
|
+
- Exported
|
|
54
|
+
- Output [Opt None]: Snippet Adapter
|
|
55
|
+
"""
|
|
56
|
+
ext = Path(fileName).suffix.lower()
|
|
57
|
+
return self.adapters.get(ext)
|
|
58
|
+
|
|
59
|
+
def hasAdapter(self, fileName: str) -> bool:
|
|
60
|
+
""" to tell if Snippet Adapter is registered for file name
|
|
61
|
+
- Exported
|
|
62
|
+
"""
|
|
63
|
+
ext = Path(fileName).suffix.lower()
|
|
64
|
+
return ext in self.adapters
|
|
65
|
+
|
|
66
|
+
def adaptInput(self,
|
|
67
|
+
snippet: ProtonabuSnippet
|
|
68
|
+
) -> ProtonabuSnippet:
|
|
69
|
+
""" to adapt snippet input using registered adapter
|
|
70
|
+
- Exported
|
|
71
|
+
- Input: raw snippet
|
|
72
|
+
- Output: native snippet
|
|
73
|
+
- definitive [Product]
|
|
74
|
+
"""
|
|
75
|
+
# [Msg]: to get Snippet Adapter by file name
|
|
76
|
+
adapter = self.getAdapter(snippet.fileName)
|
|
77
|
+
# [Esc Done]: no adapter registered
|
|
78
|
+
if not adapter: return snippet
|
|
79
|
+
# [Msg]: to adapt snippet input from foreign format
|
|
80
|
+
return adapter.adaptInput(snippet)
|
|
81
|
+
|
|
82
|
+
def adaptOutput(self,
|
|
83
|
+
snippet: ProtonabuSnippet
|
|
84
|
+
) -> ProtonabuSnippet:
|
|
85
|
+
""" to adapt snippet output using registered adapter
|
|
86
|
+
- Exported
|
|
87
|
+
- Input: nativesnippet
|
|
88
|
+
- Output: adapted snippet
|
|
89
|
+
"""
|
|
90
|
+
# [Msg]: to get Snippet Adapter by file name
|
|
91
|
+
adapter = self.getAdapter(snippet.fileName)
|
|
92
|
+
# [Esc Done]: no adapter registered
|
|
93
|
+
if not adapter: return snippet
|
|
94
|
+
# [Msg]: to adapt snippet output to foreign format
|
|
95
|
+
return adapter.adaptOutput(snippet)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
# to INITIALIZE Snippet Adapter Factory
|
|
99
|
+
snippetAdapterFactory = SnippetAdapterFactory()
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
PRODUCT: Snippet Adapter Package
|
|
2
|
+
ID
|
|
3
|
+
PROPERTY [AUTHOR]: Avner Ben
|
|
4
|
+
BULLET [CREATED]: 17-May-2026
|
|
5
|
+
BULLET [IMPROVED]: 24-Aug-2026
|
|
6
|
+
PROPERTY [GENERATOR]: Antigravity (Gemini 3.7 Flash)
|
|
7
|
+
BULLET [IMPROVED]: 24-Aug-2026
|
|
8
|
+
|
|
9
|
+
USE CASE: to adapt snippet input using registered adapter
|
|
10
|
+
TITLE: Adapting Snippet Input from Foreign Format
|
|
11
|
+
REQUIRES: to get Snippet Adapter by file name
|
|
12
|
+
REQUIRES: to adapt snippet input from foreign format
|
|
13
|
+
|
|
14
|
+
USE CASE: to adapt snippet output using registered adapter
|
|
15
|
+
TITLE: Adapting Snippet Output to Foreign Format
|
|
16
|
+
REQUIRES: to get Snippet Adapter by file name
|
|
17
|
+
REQUIRES: to adapt snippet output to foreign format
|
|
18
|
+
|
|
19
|
+
USE CASE: to register Snippet Adapter
|
|
20
|
+
TITLE: Registering Snippet Adapter in Factory
|
|
21
|
+
REQUIRES: to register Snippet Adapter
|
|
22
|
+
|
|
23
|
+
USE CASE: to perform Snippet Adapter Test Cases
|
|
24
|
+
TITLE: Performing Snippet Adapter Test Cases
|
|
25
|
+
SCENARIO: Full Snippet Adapter test
|
|
26
|
+
IN SCENARIO [Full Snippet Adapter test]: to INITIALIZE Snippet Adapter Test Case [FOR to INITIALIZE test case]
|
|
27
|
+
REQUIRES: to perform Unit Test
|
|
28
|
+
SCANNING: "test cases"
|
|
29
|
+
REQUIRES: to INITIALIZE Snippet Adapter Test Case
|
|
30
|
+
REQUIRES: to perform Snippet Adapter test case
|
|
31
|
+
REQUIRES: to test Snippet Adapter factory registration
|
|
32
|
+
REQUIRES: to test Markdown input line adaptation
|
|
33
|
+
REQUIRES: to test Markdown output line adaptation
|
|
34
|
+
REQUIRES: to test full Markdown snippet iteration
|
|
35
|
+
REQUIRES: to test JSON round-trip
|
|
36
|
+
REQUIRES: to test XML round-trip
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# contrib adapter extensions
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
""" Module: Protonabu Snippet Adapter
|
|
2
|
+
- Author: Avner Ben
|
|
3
|
+
- Created: 17-May-2026
|
|
4
|
+
- Generator: Antigravity (Claude Opus 4.6)
|
|
5
|
+
- Generated: 17-May-2026
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from abc import ABC, abstractmethod
|
|
9
|
+
from typing import Iterator
|
|
10
|
+
|
|
11
|
+
# [Additional]
|
|
12
|
+
from ..factSnippet import ProtonabuSnippet
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class SnippetAdapterSource(ProtonabuSnippet.ISource, ABC):
|
|
16
|
+
""" Line Adapter Fact Stream
|
|
17
|
+
- Purpose: to adapt Fact Line Stream (such as markdown) for foreign protonabu native format
|
|
18
|
+
- Description: Wraps a concrete ISource, intercepting line-level
|
|
19
|
+
I/O to perform format-specific transformations (e.g., stripping
|
|
20
|
+
or prepending Markdown bullet decoration). Subclasses implement
|
|
21
|
+
the raw-line protocol by overriding toNative and toForeign.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
def __init__(self, wrapped: ProtonabuSnippet.ISource):
|
|
25
|
+
""" to INITIALIZE Line Adapter Fact Stream
|
|
26
|
+
- Exported
|
|
27
|
+
"""
|
|
28
|
+
# Contains [1:1 By Reference]: Fact Stream
|
|
29
|
+
self.wrapped: ProtonabuSnippet.ISource = wrapped
|
|
30
|
+
|
|
31
|
+
@abstractmethod
|
|
32
|
+
def toNative(self, line: str) -> str:
|
|
33
|
+
""" to import fact-line thru <SUBSTITUTE Line> Adapter Fact Stream
|
|
34
|
+
- Exported
|
|
35
|
+
- definitive [Part]
|
|
36
|
+
- Input: Foreign format line
|
|
37
|
+
- Output: Native format line
|
|
38
|
+
"""
|
|
39
|
+
pass
|
|
40
|
+
|
|
41
|
+
@abstractmethod
|
|
42
|
+
def toForeign(self, line: str) -> str:
|
|
43
|
+
""" to export fact-line thru <SUBSTITUTE Line> Adapter Fact Stream
|
|
44
|
+
- Exported
|
|
45
|
+
- Input: Native format line
|
|
46
|
+
- Output: Foreign format line
|
|
47
|
+
"""
|
|
48
|
+
pass
|
|
49
|
+
|
|
50
|
+
def add(self, fact: str):
|
|
51
|
+
""" to append line to <Line Adapter> Fact Stream
|
|
52
|
+
- Exported
|
|
53
|
+
"""
|
|
54
|
+
# [Msg]: to export fact-line thru <SUBSTITUTE Line> Adapter Fact Stream
|
|
55
|
+
# [Msg]: to append line to Fact Stream
|
|
56
|
+
self.wrapped.add(self.toForeign(fact))
|
|
57
|
+
|
|
58
|
+
def __iter__(self) -> Iterator[str]:
|
|
59
|
+
""" to TRAVERSE <Line Adapter> Fact Stream
|
|
60
|
+
- Exported
|
|
61
|
+
- definitive
|
|
62
|
+
"""
|
|
63
|
+
# [Scan]: to TRAVERSE Fact Stream
|
|
64
|
+
for line in self.wrapped:
|
|
65
|
+
# [Msg]: to import fact-line thru <SUBSTITUTE Line> Adapter Fact Stream
|
|
66
|
+
yield self.toNative(line)
|
|
67
|
+
|
|
68
|
+
def close(self):
|
|
69
|
+
""" to close <Line Adapter> Fact Stream
|
|
70
|
+
- Exported
|
|
71
|
+
"""
|
|
72
|
+
# [Msg]: to close Fact Stream
|
|
73
|
+
self.wrapped.close()
|
|
74
|
+
|
|
75
|
+
class FactSnippetAdapter(ABC):
|
|
76
|
+
""" Fact Snippet Adapter
|
|
77
|
+
- Purpose: to adapt Protonabu Fact Snippet to and from foreign format
|
|
78
|
+
- Stereotype: Abstract
|
|
79
|
+
"""
|
|
80
|
+
fileExtensions: list[str] = []
|
|
81
|
+
|
|
82
|
+
@abstractmethod
|
|
83
|
+
def adaptInput(self, snippet: ProtonabuSnippet) -> ProtonabuSnippet:
|
|
84
|
+
""" to import facts thru <SUBSTITUTE Fact> Snippet Adapter
|
|
85
|
+
- Exported
|
|
86
|
+
- Input: foreign format snippet
|
|
87
|
+
- Output: native format snippet
|
|
88
|
+
- definitive [Part]
|
|
89
|
+
"""
|
|
90
|
+
pass
|
|
91
|
+
|
|
92
|
+
@abstractmethod
|
|
93
|
+
def adaptOutput(self, snippet: ProtonabuSnippet) -> ProtonabuSnippet:
|
|
94
|
+
""" to export facts thru <SUBSTITUTE Fact> Snippet Adapter
|
|
95
|
+
- Exported
|
|
96
|
+
- Input: native format snippet
|
|
97
|
+
- Output: foreign format snippet
|
|
98
|
+
"""
|
|
99
|
+
pass
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# JsonSnippetAdapter package
|