Compare commits
111 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
7b7d1aaa39 | |
|
|
bb5f9aa4b6 | |
|
|
4036dbe05b | |
|
|
a6e44b5611 | |
|
|
d68b2295e8 | |
|
|
6b26a5c700 | |
|
|
0da3828cd0 | |
|
|
4bfd730616 | |
|
|
86891e9e86 | |
|
|
09c8eef46b | |
|
|
c2a44f40c5 | |
|
|
237a417396 | |
|
|
b47c88ffde | |
|
|
4a1857c80f | |
|
|
3d8c1bf4b4 | |
|
|
22b19d4481 | |
|
|
62da1bacc3 | |
|
|
ee61ac9b00 | |
|
|
af71c12b21 | |
|
|
aad46ec9f9 | |
|
|
b420c89ab8 | |
|
|
001abba7bf | |
|
|
77475d3414 | |
|
|
00d5529930 | |
|
|
e3f41eee43 | |
|
|
3f3d0f7b0f | |
|
|
ca13bda9c5 | |
|
|
8989e05af7 | |
|
|
64a2763053 | |
|
|
eeb5c1bb93 | |
|
|
6e4babfa14 | |
|
|
f7a9d38298 | |
|
|
0d337e5c0c | |
|
|
5c104b155f | |
|
|
d7af2e213a | |
|
|
48f8d67736 | |
|
|
0ca9032d15 | |
|
|
53455e8ec2 | |
|
|
3d0d444181 | |
|
|
1c8ee2d6e8 | |
|
|
2f4d4ab973 | |
|
|
30e0486b7c | |
|
|
d94d6dbaed | |
|
|
4de49410a0 | |
|
|
bd2fdd8519 | |
|
|
92aa25d7dd | |
|
|
84d8fad28f | |
|
|
ac9f00f363 | |
|
|
d2390563e4 | |
|
|
36e56afa4c | |
|
|
611617a8fd | |
|
|
95173d5071 | |
|
|
8305f440ab | |
|
|
0f8c9e0f5e | |
|
|
c9d02dee1a | |
|
|
fce4b4b4c0 | |
|
|
e9b318b4c6 | |
|
|
5d71bc3710 | |
|
|
69822173d4 | |
|
|
0130cbf740 | |
|
|
7c6504d0aa | |
|
|
92ee19a1ac | |
|
|
79d22b18ad | |
|
|
e420ff8e5c | |
|
|
3e1c8b8f19 | |
|
|
ed330e66a4 | |
|
|
3c166d07e1 | |
|
|
06085a1398 | |
|
|
2516e10cc1 | |
|
|
1ef5907f0f | |
|
|
f4e16a0f3b | |
|
|
19ddd40134 | |
|
|
129b540d36 | |
|
|
d87f3c127c | |
|
|
909d5c2d67 | |
|
|
a2ae3c5d0e | |
|
|
7ba4af8d45 | |
|
|
eb00ae9edc | |
|
|
ffb8479e53 | |
|
|
650229af5c | |
|
|
3abb5c53f7 | |
|
|
c8082c44a3 | |
|
|
4eb9247c5f | |
|
|
e9837dbf99 | |
|
|
cf8c0d56d4 | |
|
|
62666e0ab4 | |
|
|
1e7eea3466 | |
|
|
b57ca251a0 | |
|
|
c8b60a7be0 | |
|
|
0e86cc5ca4 | |
|
|
ef9b53fcbc | |
|
|
6100f716b5 | |
|
|
dfc8a7b2d2 | |
|
|
00786d8480 | |
|
|
d1f4eaa6f2 | |
|
|
c52b7c959f | |
|
|
1fa28a41a7 | |
|
|
c4ee5f1e43 | |
|
|
43db9f7a09 | |
|
|
e64c6d7f41 | |
|
|
df2e0941c8 | |
|
|
8641fa8d9d | |
|
|
62ad85b8f4 | |
|
|
6cd7f8047a | |
|
|
ca773426db | |
|
|
e429175886 | |
|
|
3f7ef8a922 | |
|
|
5a2c044dc1 | |
|
|
7ab6f02635 | |
|
|
fbc899cb2c | |
|
|
bb5bec7a57 |
|
|
@ -0,0 +1,37 @@
|
||||||
|
# This workflow will install Python dependencies, run tests and lint with a single version of Python
|
||||||
|
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
|
||||||
|
|
||||||
|
name: Python Deployment
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ main, test*]
|
||||||
|
pull_request:
|
||||||
|
branches: [ main, test* ]
|
||||||
|
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deployment:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
environment: production
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Set up Python 3.10
|
||||||
|
uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: "3.10"
|
||||||
|
- name: Build the application
|
||||||
|
run: |
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
pip install -r requirements.txt
|
||||||
|
pip install -e .
|
||||||
|
pip install pydoctor
|
||||||
|
python -m bootstraparse "example_userfiles" "docs"
|
||||||
|
- name: Build the documentation
|
||||||
|
run: |
|
||||||
|
pydoctor --make-html --html-output=docs/apidoc src/bootstraparse/
|
||||||
|
- name: deploy
|
||||||
|
uses: JamesIves/github-pages-deploy-action@v4.3.3
|
||||||
|
with:
|
||||||
|
branch: gh-pages # The branch the action should deploy to.
|
||||||
|
folder: docs
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
# This workflow will install Python dependencies, run tests and lint with a single version of Python
|
# This workflow will install Python dependencies, run tests and lint with a single version of Python
|
||||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
|
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
|
||||||
|
|
||||||
name: Python application
|
name: Python Tests and Lint
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ main, test ]
|
branches: [ main, release, releases/*, test*]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ main, test ]
|
branches: [ main, release, releases/*, test* ]
|
||||||
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
@ -40,23 +40,3 @@ jobs:
|
||||||
- name: Test with pytest
|
- name: Test with pytest
|
||||||
run: |
|
run: |
|
||||||
pytest --cov-fail-under=100 -o xfail_strict=true --cov-report=term-missing .
|
pytest --cov-fail-under=100 -o xfail_strict=true --cov-report=term-missing .
|
||||||
deployment:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
environment: production
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- name: Set up Python 3.10
|
|
||||||
uses: actions/setup-python@v2
|
|
||||||
with:
|
|
||||||
python-version: "3.10"
|
|
||||||
- name: Build the application
|
|
||||||
run: |
|
|
||||||
python -m pip install --upgrade pip
|
|
||||||
pip install -r requirements.txt
|
|
||||||
pip install -e .
|
|
||||||
python -m bootstraparse "example_userfiles" "docs"
|
|
||||||
- name: deploy
|
|
||||||
uses: JamesIves/github-pages-deploy-action@v4.3.3
|
|
||||||
with:
|
|
||||||
branch: gh-pages # The branch the action should deploy to.
|
|
||||||
folder: docs
|
|
||||||
|
|
@ -156,4 +156,5 @@ cython_debug/
|
||||||
example_userfiles/output/
|
example_userfiles/output/
|
||||||
example_userfiles/output/*
|
example_userfiles/output/*
|
||||||
dev_outputs/*
|
dev_outputs/*
|
||||||
/example_output/*
|
example_output/*
|
||||||
|
docs/
|
||||||
|
|
|
||||||
65
README.md
65
README.md
|
|
@ -5,39 +5,70 @@ bootstraparse aims to be customisable in that regard, but its first iteration an
|
||||||
|
|
||||||
You can refer to the `example_userfiles` for an idea of what the parser expects you to feed it and find an example of our automated generation at https://idle-org.github.io/bootstraparse/ for this particular folder. Or you can run the program yourself for the same result!
|
You can refer to the `example_userfiles` for an idea of what the parser expects you to feed it and find an example of our automated generation at https://idle-org.github.io/bootstraparse/ for this particular folder. Or you can run the program yourself for the same result!
|
||||||
|
|
||||||
[](https://github.com/idle-org/bootstraparse/actions/workflows/python-app.yml)
|
- Main
|
||||||
|
- [](https://github.com/idle-org/bootstraparse/actions/workflows/python-tests.yml)
|
||||||
|
- Releases
|
||||||
|
- [](https://github.com/idle-org/bootstraparse/actions/workflows/python-tests.yml)
|
||||||
|
- Deploy
|
||||||
|
- [](https://github.com/idle-org/bootstraparse/actions/workflows/python-deploy.yml)
|
||||||
---
|
---
|
||||||
## Roadmap
|
## Release Notes
|
||||||
### V1.0.1
|
### V1.0.1
|
||||||
- Make the default example site way more useful
|
- Remove old regex usage
|
||||||
|
- Add copy behaviour to config file
|
||||||
- Add the type and return types of all functions
|
- Add the type and return types of all functions
|
||||||
- Add documentation to remaining lone functions
|
- Add documentation to remaining lone functions
|
||||||
- Write a documentation for the application (use specs.yaml)
|
- Copy un-parsable files to destination folder without modifications
|
||||||
|
- Many bug fixes and improvements
|
||||||
|
|
||||||
|
### V1.0.2
|
||||||
|
- Put out many fires
|
||||||
|
|
||||||
### V1.0.3
|
### V1.0.3
|
||||||
- Copy un-parsable files to destination folder without modifications
|
- Put out many more fires
|
||||||
- Add copy behaviour to config file
|
- Fixed continuous integration
|
||||||
|
- Added doc generation
|
||||||
|
|
||||||
|
### V1.0.4
|
||||||
|
- Made the default example site more useful
|
||||||
|
- Wrote a barebone documentation for the application
|
||||||
|
|
||||||
|
|
||||||
|
## Roadmap
|
||||||
|
### V1.0.5
|
||||||
|
- Add more context to the warning messages ☐
|
||||||
|
- Test configs more in-depth ☐
|
||||||
|
- Test overall site generation ☐
|
||||||
|
- Move the WARNING-level output to INFO for config overwrite ☐
|
||||||
|
|
||||||
|
### V1.0.6
|
||||||
|
- Option to ignore br behavior ☐
|
||||||
|
- Make the default example site way more useful ☐
|
||||||
|
|
||||||
### V1.1
|
### V1.1
|
||||||
- Functioning `table` Token
|
- Functioning `table` Token ☐
|
||||||
- Functioning `code` Token
|
- Functioning `code` Token ☐
|
||||||
- Establish a list of all configurable parameters to implement in the future, and update the roadmap with them.
|
- Establish a list of all configurable parameters to implement in the future, and update the roadmap with them. ☐
|
||||||
- Decide level of logic to be implemented, and whether it should be configurable
|
- Decide level of logic to be implemented, and whether it should be configurable ☐
|
||||||
- Update the uses of remaining files
|
- Update the uses of remaining files ☐
|
||||||
|
- Add a global line count and a line tracker to the parser ☐
|
||||||
|
|
||||||
### V1.2
|
### V1.2
|
||||||
- Check error messages and add a real debug level to parameters
|
- Check error messages and add a real debug level to parameters ☐
|
||||||
- Functioning `blockquote` Token
|
- Thouroughly test logging, and error messages for the user ☐
|
||||||
- Remove old regex usage
|
- Functioning `blockquote` Token ☐
|
||||||
|
|
||||||
### V1.3
|
### V1.3
|
||||||
- Add advanced lookahead logic for `*`
|
- Add advanced lookahead logic for `*`
|
||||||
|
- Functioning `lead` Token
|
||||||
|
|
||||||
### V1.4
|
### V1.4
|
||||||
- Add html indentation for human readability of the output.
|
- Add html indentation for human readability of the output. ☐
|
||||||
|
- Write thourough documentation for the application (use specs.yaml) ☐
|
||||||
|
|
||||||
### V2
|
### V2
|
||||||
- Add a functioning post-context enhancer able to generate menus and elements from arbitrary logic.
|
- Add a functioning post-context enhancer able to generate menus and elements from arbitrary logic.
|
||||||
- Achieve perfect markdown compatibility with appropriate config parameters
|
- Achieve perfect markdown compatibility with appropriate config parameters
|
||||||
|
|
||||||
|
### V3
|
||||||
|
- Add Template customisation.
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ shortcuts:
|
||||||
tab_bnw: 'tab_bnw_imported'
|
tab_bnw: 'tab_bnw_imported'
|
||||||
tab_color: 'tab_colour_imported'
|
tab_color: 'tab_colour_imported'
|
||||||
custom_permutation: 'custom_permutated'
|
custom_permutation: 'custom_permutated'
|
||||||
|
empty: ''
|
||||||
start: |
|
start: |
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
|
||||||
|
Structural Elements:
|
||||||
|
<<div
|
||||||
|
This is a div
|
||||||
|
div>>{class='blue', 123}{{cinsertion}}[var='test', number=11]
|
||||||
|
<<article
|
||||||
|
This is an article
|
||||||
|
article>>{class='blue', 123}{{cinsertion}}[var='test', number=11]
|
||||||
|
<<aside
|
||||||
|
This is an aside
|
||||||
|
aside>>{class='blue', 123}{{cinsertion}}[var='test', number=11]
|
||||||
|
<<section
|
||||||
|
This is a section
|
||||||
|
section>>{class='blue', 123}{{cinsertion}}[var='test', number=11]
|
||||||
|
<<div
|
||||||
|
<<article
|
||||||
|
<<aside
|
||||||
|
<<section
|
||||||
|
Text
|
||||||
|
section>>{class='blue', 123}{{cinsertion}}[var='test', number=11]
|
||||||
|
aside>>{class='blue', 123}{{cinsertion}}[var='test', number=11]
|
||||||
|
article>>{class='blue', 123}{{cinsertion}}[var='test', number=11]
|
||||||
|
div>>{class='blue', 123}{{cinsertion}}[var='test', number=11]
|
||||||
|
# Header 1 #{class='blue', 123}{{cinsertion}}[var='test', number=11]
|
||||||
|
! Display 1 !{class='blue', 123}{{cinsertion}}[var='test', number=11]
|
||||||
|
|
||||||
|
|
||||||
|
Inline Element:
|
||||||
|
[Link text]('http://this.is.a.link')
|
||||||
|
*This is in italic*
|
||||||
|
**This is strong**
|
||||||
|
~~This is stricken through~~
|
||||||
|
__This is underlined__
|
||||||
|
(#1)This is a custom span(#1)
|
||||||
|
|
||||||
|
|
||||||
|
Oneline elements:
|
||||||
|
- This is an unordered list item
|
||||||
|
- This is an unordered list item
|
||||||
|
- This is an unordered list item{class='blue', 123}{{cinsertion}}[var='test', number=11]
|
||||||
|
#. This is an ordered list item
|
||||||
|
#. This is an ordered list item
|
||||||
|
#. This is an ordered list item{class='blue', 123}{{cinsertion}}[var='test', number=11]
|
||||||
|
|
||||||
|
This is a long text segment. This is a long text segment. This is a long text segment. This is a long text segment. This is a long text segment.
|
||||||
|
This is still the same long text segment. This is still the same long text segment. This is still the same long text segment.
|
||||||
|
|
||||||
|
Use a double linebreak to force linebreaks.
|
||||||
|
|
@ -1,49 +1,28 @@
|
||||||
@[start]['bootstrap']
|
@[start]['Bootstraparse']
|
||||||
|
|
||||||
Structural Elements:
|
|
||||||
<<div
|
<<div
|
||||||
This is a div
|
<<header
|
||||||
div>>[class='blue', 123]{var='test', number=11}{{cinsertion}}
|
|
||||||
<<article
|
|
||||||
This is an article
|
|
||||||
article>>[class='blue', 123]{var='test', number=11}{{cinsertion}}
|
|
||||||
<<aside
|
|
||||||
This is an aside
|
|
||||||
aside>>[class='blue', 123]{var='test', number=11}{{cinsertion}}
|
|
||||||
<<section
|
|
||||||
This is a section
|
|
||||||
section>>[class='blue', 123]{var='test', number=11}{{cinsertion}}
|
|
||||||
<<div
|
<<div
|
||||||
<<article
|
<<div
|
||||||
<<aside
|
Bootstraparse
|
||||||
<<section
|
div>>{{blog-header-logo text-dark text-center border-bottom}}
|
||||||
Text
|
div>>{{row flex-nowrap justify-content-between align-items-center}}
|
||||||
section>>[class='blue', 123]{var='test', number=11}{{cinsertion}}
|
header>>{{blog-header py-3}}
|
||||||
aside>>[class='blue', 123]{var='test', number=11}{{cinsertion}}
|
<<div
|
||||||
article>>[class='blue', 123]{var='test', number=11}{{cinsertion}}
|
# What is bootstraparse ? #
|
||||||
div>>[class='blue', 123]{var='test', number=11}{{cinsertion}}
|
|
||||||
# Header 1 #[class='blue', 123]{var='test', number=11}{{cinsertion}}
|
bootstraparse is a tool that allows you to bootstrap your own project.
|
||||||
! Display 1 ![class='blue', 123]{var='test', number=11}{{cinsertion}}
|
In a very small number of steps, you can create a new project with the
|
||||||
|
following features:
|
||||||
|
- Imports, with the <code> ::< filename > </code>syntax you can import another file and have it's contents dumped into your file.
|
||||||
|
- Markup, a subset of markdown is already supported and the rest is incomming !
|
||||||
|
- Aliases : With the <code> @[alias_name] </code> syntax you can create an alias for a string of text, with replacement capabilities.
|
||||||
|
- Images: With the <code> @{imagename} </code> syntax you can specify an image template to import, with replacement capabilities.
|
||||||
|
|
||||||
|
And much much more !
|
||||||
|
|
||||||
|
|
||||||
Inline Element:
|
We encourage you to read the [documentation]("apidoc/index.html") to learn more about bootstraparse
|
||||||
[Link text]('http://this.is.a.link')
|
or explore the [source code]("https://github.com/idle-org/bootstraparse")
|
||||||
*This is in italic*
|
div>>{{nav-scroller py-1 mb-2}}
|
||||||
**This is strong**
|
div>>{{container}}
|
||||||
~~This is stricken through~~
|
|
||||||
__This is underlined__
|
|
||||||
(#1)This is a custom span(#1)
|
|
||||||
|
|
||||||
|
|
||||||
Oneline elements:
|
|
||||||
- This is an unordered list item
|
|
||||||
- This is an unordered list item
|
|
||||||
- This is an unordered list item[class='blue', 123]{var='test', number=11}{{cinsertion}}
|
|
||||||
#. This is an ordered list item
|
|
||||||
#. This is an ordered list item
|
|
||||||
#. This is an ordered list item[class='blue', 123]{var='test', number=11}{{cinsertion}}
|
|
||||||
|
|
||||||
This is a long text segment. This is a long text segment. This is a long text segment. This is a long text segment. This is a long text segment. This is a long text segment. This is a long text segment. This is a long text segment.
|
|
||||||
I wish there could be linebreaks.
|
|
||||||
|
|
||||||
@[end]
|
@[end]
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
pyyaml==6.0
|
pyyaml==6.0
|
||||||
rich==12.0.1
|
rich==12.0.1
|
||||||
regex==2022.3.15
|
|
||||||
pyparse~=1.1.7
|
pyparse~=1.1.7
|
||||||
pyparsing[diagrams]~=3.0.7
|
pyparsing[diagrams]~=3.0.7
|
||||||
|
|
||||||
pytest==7.1.1
|
pytest==7.1.1
|
||||||
|
|
@ -5,4 +5,3 @@ pytest-cov==3.0.0
|
||||||
mypy==0.941
|
mypy==0.941
|
||||||
pyyaml==6.0
|
pyyaml==6.0
|
||||||
rich==12.0.1
|
rich==12.0.1
|
||||||
regex==2022.3.15
|
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,14 @@
|
||||||
name = bootstraparse
|
name = bootstraparse
|
||||||
description = A custom markdown parser for Bootstrap & Python
|
description = A custom markdown parser for Bootstrap & Python
|
||||||
author = Vkyfox
|
author = Vkyfox
|
||||||
version = 1.0
|
version = 1.0.4
|
||||||
license = Mozilla Public License Version 2.0
|
license = Mozilla Public License Version 2.0
|
||||||
license_file = LICENSE
|
license_file = LICENSE
|
||||||
platforms = unix, linux, osx, cygwin, win32
|
platforms = unix, linux, osx, cygwin, win32
|
||||||
classifiers =
|
classifiers =
|
||||||
Programming Language :: Python :: 3
|
Programming Language :: Python :: 3
|
||||||
Programming Language :: Python :: 3 :: Only
|
Programming Language :: Python :: 3 :: Only
|
||||||
Programming Language :: Python :: 3.7
|
Programming Language :: Python :: 3.10
|
||||||
Programming Language :: Python :: 3.8
|
|
||||||
Programming Language :: Python :: 3.9
|
Programming Language :: Python :: 3.9
|
||||||
|
|
||||||
[options]
|
[options]
|
||||||
|
|
@ -19,7 +18,7 @@ packages =
|
||||||
bootstraparse.modules
|
bootstraparse.modules
|
||||||
install_requires =
|
install_requires =
|
||||||
pyyaml>=6.0
|
pyyaml>=6.0
|
||||||
python_requires = >=3.6
|
python_requires = >=3.9
|
||||||
package_dir =
|
package_dir =
|
||||||
=src
|
=src
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
"""
|
||||||
|
Bootstraparse is a tool to parse a folder and create a website from it.
|
||||||
|
After installing it with pip, you can use it by running the following command:
|
||||||
|
- bootstraparse <origin> <destination>
|
||||||
|
"""
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
# Main program, use this to start parsing
|
""" Main program, use this to start parsing"""
|
||||||
|
|
||||||
from bootstraparse.modules import sitecreator
|
from bootstraparse.modules import sitecreator, error_mngr
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
@ -21,5 +21,6 @@ def parse(_args):
|
||||||
|
|
||||||
if __name__ == "__main__": # pragma: no cover
|
if __name__ == "__main__": # pragma: no cover
|
||||||
args = parse(sys.argv[1:])
|
args = parse(sys.argv[1:])
|
||||||
|
error_mngr.init_logging(filename=None, loglevel="DEBUG", filemode='w', handler=None)
|
||||||
if sitecreator.create_website(args.origin, args.destination) == 0:
|
if sitecreator.create_website(args.origin, args.destination) == 0:
|
||||||
print("Bootstraparse run successful!")
|
print("Bootstraparse run successful!")
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ global:
|
||||||
template: "bootstrap.yml"
|
template: "bootstrap.yml"
|
||||||
output: "example_site/"
|
output: "example_site/"
|
||||||
bootstrap_version: "3.3.7"
|
bootstrap_version: "3.3.7"
|
||||||
version: "1.0.0"
|
version: "1.0.4"
|
||||||
bootstrap_location: ""
|
bootstrap_location: ""
|
||||||
|
|
||||||
logging:
|
logging:
|
||||||
|
|
@ -21,3 +21,4 @@ export:
|
||||||
intermediate_files: true
|
intermediate_files: true
|
||||||
type: "html"
|
type: "html"
|
||||||
force_rewrite: true
|
force_rewrite: true
|
||||||
|
copy_unparsable_files: copy
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
"""
|
||||||
|
The modules in this folder are used to parse the website.
|
||||||
|
"""
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
# Interprets config files
|
"""Interprets config files
|
||||||
# The Config will be loaded by the environment at runtime and should be accessed that way
|
The Config will be loaded by the environment at runtime and should be accessed that way
|
||||||
# Usage:
|
Usage:
|
||||||
# from bootstraparse.modules.config import ConfigLoader
|
- from bootstraparse.modules.config import ConfigLoader
|
||||||
# config = ConfigLoader([list of config files], extensions=[list of extensions])
|
- config = ConfigLoader([list of config files], extensions=[list of extensions])
|
||||||
# config['file']['key']
|
- config['file']['key']
|
||||||
# The ConfigLoader class has load_from_file and load_from_folder methods and __getitem__ for accessing loaded elements
|
The ConfigLoader class has load_from_file and load_from_folder methods and __getitem__ for accessing loaded elements
|
||||||
|
"""
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import rich
|
import rich
|
||||||
|
|
@ -17,16 +17,16 @@ class ConfigLoader:
|
||||||
"""
|
"""
|
||||||
Reads all config files in a folder
|
Reads all config files in a folder
|
||||||
Behaves like a dictionary of all config files
|
Behaves like a dictionary of all config files
|
||||||
return FileNotFound Error on Error
|
|
||||||
:param config_folder: The folder to read
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, config_folder=None, extensions=("yaml", "yml")):
|
def __init__(self, config_folder=None, extensions=("yaml", "yml")):
|
||||||
"""
|
"""
|
||||||
Defines the config folder and loads all configs
|
Defines the config folder and loads all configs
|
||||||
:param config_folder: path to config file
|
:param config_folder: path to config file
|
||||||
|
:type config_folder: (str | list[str])
|
||||||
:param extensions: file extensions to load
|
:param extensions: file extensions to load
|
||||||
:return: None
|
:type extensions: list[str]
|
||||||
|
:raise TypeError: if config_folder is not a string or a list of strings
|
||||||
"""
|
"""
|
||||||
if config_folder is None:
|
if config_folder is None:
|
||||||
self.config_folders = []
|
self.config_folders = []
|
||||||
|
|
@ -54,6 +54,7 @@ class ConfigLoader:
|
||||||
"""
|
"""
|
||||||
Add a Folder to the list of configs
|
Add a Folder to the list of configs
|
||||||
:param folder: path to folder
|
:param folder: path to folder
|
||||||
|
:type folder: str
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
self.config_folders.append(folder)
|
self.config_folders.append(folder)
|
||||||
|
|
@ -63,6 +64,7 @@ class ConfigLoader:
|
||||||
"""
|
"""
|
||||||
Loads a config file
|
Loads a config file
|
||||||
:param filepath: path to config file
|
:param filepath: path to config file
|
||||||
|
:type filepath: str
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
basename = os.path.basename(filepath)
|
basename = os.path.basename(filepath)
|
||||||
|
|
@ -72,15 +74,22 @@ class ConfigLoader:
|
||||||
if name not in self.loaded_conf:
|
if name not in self.loaded_conf:
|
||||||
self.loaded_conf[name] = yaml.safe_load(f)
|
self.loaded_conf[name] = yaml.safe_load(f)
|
||||||
else:
|
else:
|
||||||
self.loaded_conf[name].update(yaml.safe_load(f))
|
new_config = yaml.safe_load(f)
|
||||||
error_mngr.log_message(f"Warning: {name} is already in {self.loaded_conf}", level='WARNING')
|
for key in new_config:
|
||||||
|
if key in self.loaded_conf[name]:
|
||||||
|
self.loaded_conf[name][key].update(new_config[key])
|
||||||
|
else:
|
||||||
|
self.loaded_conf[name][key] = new_config[key]
|
||||||
|
error_mngr.log_message(f"Warning: {name} is already in {self.loaded_conf}", level='CRITICAL')
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
error_mngr.log_message(f'Error parsing in file {basename} at {filepath}.', level='CRITICAL')
|
error_mngr.log_message(f'Error parsing in file {basename} at {filepath}.', level='CRITICAL')
|
||||||
error_mngr.log_exception(str(e), level='CRITICAL')
|
error_mngr.log_exception(e, level='CRITICAL')
|
||||||
|
|
||||||
def load_from_folder(self, folder):
|
def load_from_folder(self, folder):
|
||||||
"""
|
"""
|
||||||
Loads all configs in the config folder
|
Loads all configs in the config folder
|
||||||
|
:param folder: path to folder
|
||||||
|
:type folder: str
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
for filename in os.listdir(folder):
|
for filename in os.listdir(folder):
|
||||||
|
|
@ -92,6 +101,8 @@ class ConfigLoader:
|
||||||
"""
|
"""
|
||||||
Returns a yaml config object if in self.loaded_conf
|
Returns a yaml config object if in self.loaded_conf
|
||||||
:param item: config key
|
:param item: config key
|
||||||
|
:type item: str
|
||||||
|
:raise KeyError: if item is not in self.loaded_conf
|
||||||
:return: config value
|
:return: config value
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
|
@ -102,36 +113,21 @@ class ConfigLoader:
|
||||||
def __contains__(self, item):
|
def __contains__(self, item):
|
||||||
"""
|
"""
|
||||||
Same as a dictionary.
|
Same as a dictionary.
|
||||||
|
:param item: config key
|
||||||
|
:type item: str
|
||||||
|
:return: True if item is in self.loaded_conf
|
||||||
"""
|
"""
|
||||||
return item in self.loaded_conf
|
return item in self.loaded_conf
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
"""
|
"""
|
||||||
Returns config as string
|
Returns config as string
|
||||||
:return: config as string
|
:return: the dict of configs and their values
|
||||||
|
:rtype: str
|
||||||
"""
|
"""
|
||||||
return self.loaded_conf.__repr__()
|
return str(self.loaded_conf.__repr__())
|
||||||
|
|
||||||
|
|
||||||
# class UserConfig(ConfigLoader):
|
|
||||||
# """
|
|
||||||
# Reads user config file.
|
|
||||||
# :param config_folder: path to config file
|
|
||||||
# :return: None
|
|
||||||
# """
|
|
||||||
# def __init__(self, config_folder):
|
|
||||||
# super().__init__(config_folder)
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# class GlobalConfig(ConfigLoader):
|
|
||||||
# """
|
|
||||||
# Reads global config file.
|
|
||||||
# :param config_folder: path to config file
|
|
||||||
# :return: None
|
|
||||||
# """
|
|
||||||
# def __init__(self, config_folder):
|
|
||||||
# super().__init__(config_folder)
|
|
||||||
|
|
||||||
if __name__ == '__main__': # pragma: no cover
|
if __name__ == '__main__': # pragma: no cover
|
||||||
conf = ConfigLoader("../configs/")
|
conf = ConfigLoader("../configs/")
|
||||||
conf.add_folder("../../../example_userfiles/config/")
|
conf.add_folder("../../../example_userfiles/config/")
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,16 @@
|
||||||
# Interprets where the parser is located and resolves errors
|
"""Interprets where the parser is located and resolves errors
|
||||||
# You're probably here for the ContextManager class.
|
You're probably here for the ContextManager class.
|
||||||
# Containers have class_name, debug_map and validate methods for debug,
|
Containers have class_name, debug_map and validate methods for debug,
|
||||||
# self.content: accessible via __getitem__, __setitem__, add, __len__, __iter__ and __getslice__.
|
- self.content: accessible via __getitem__, __setitem__, add, __len__, __iter__ and __getslice__.
|
||||||
# self.optionals: accessible via __rshift__ (remapped to return self.map[other]())
|
- self.optionals: accessible via __rshift__ (remapped to return self.map[other]())
|
||||||
# and self.map: accessible via __invert__ (remapped to return self.optionals)
|
- and self.map: accessible via __invert__ (remapped to return self.optionals)
|
||||||
# Usage:
|
Usage:
|
||||||
# from bootstraparse.modules.context_mngr import ContextManager
|
- from bootstraparse.modules.context_mngr import ContextManager
|
||||||
# ctx = ContextManager()
|
- ctx = ContextManager()
|
||||||
# ctx.???
|
- container = BaseContainer()
|
||||||
# container = BaseContainer()
|
- container[number] -> The number element in the content
|
||||||
# container[number] -> The number element in the content
|
- "class_insert" >> container[number] -> Get an element from one of the mapped methods
|
||||||
# "class_insert" >> container[number] -> Get an element from one of the mapped methods
|
"""
|
||||||
|
|
||||||
from bootstraparse.modules import syntax, error_mngr, export
|
from bootstraparse.modules import syntax, error_mngr, export
|
||||||
from bootstraparse.modules.error_mngr import MismatchedContainerError, log_exception, log_message, LonelyOptionalError # noqa
|
from bootstraparse.modules.error_mngr import MismatchedContainerError, log_exception, log_message, LonelyOptionalError # noqa
|
||||||
|
|
||||||
|
|
@ -24,6 +23,14 @@ class BaseContainer:
|
||||||
subtype = None
|
subtype = None
|
||||||
|
|
||||||
def __init__(self, content=None, optionals=None, others=None):
|
def __init__(self, content=None, optionals=None, others=None):
|
||||||
|
"""
|
||||||
|
:param content: List of tokens to be added to the container
|
||||||
|
:param optionals: List of optional tokens to be added to the container (from the parser)
|
||||||
|
:param others: List of values to add to the .format() method
|
||||||
|
:type content: (list[(syntax.SemanticType | BaseContainer)])
|
||||||
|
:type optionals: (syntax.SemanticType)
|
||||||
|
:type others: (dict[str, str])
|
||||||
|
"""
|
||||||
if content is None:
|
if content is None:
|
||||||
content = []
|
content = []
|
||||||
if others is None:
|
if others is None:
|
||||||
|
|
@ -34,24 +41,41 @@ class BaseContainer:
|
||||||
self.indentation_level = 0 # future: add an indentation level to every token for human readability of the final output
|
self.indentation_level = 0 # future: add an indentation level to every token for human readability of the final output
|
||||||
|
|
||||||
def get_content(self, exm, arbitrary_list=None):
|
def get_content(self, exm, arbitrary_list=None):
|
||||||
|
"""
|
||||||
|
Get the content of any BaseContainer object (default self.content).
|
||||||
|
:param exm: ExportManager to use for exporting
|
||||||
|
:param arbitrary_list: List to get the content from
|
||||||
|
:type exm: export.ExportManager
|
||||||
|
:type arbitrary_list: list[BaseContainer]
|
||||||
|
:rtype : str
|
||||||
|
"""
|
||||||
output = ""
|
output = ""
|
||||||
if not arbitrary_list:
|
if not arbitrary_list:
|
||||||
arbitrary_list = self.content
|
arbitrary_list = self.content
|
||||||
# rich.inspect(arbitrary_list)
|
|
||||||
for element in arbitrary_list:
|
for element in arbitrary_list:
|
||||||
if isinstance(element, BaseContainer):
|
if isinstance(element, BaseContainer):
|
||||||
output += element.export(exm) + " "
|
output += element.export(exm) + " "
|
||||||
# rich.inspect(output[:-1])
|
|
||||||
return output[:-1]
|
return output[:-1]
|
||||||
|
|
||||||
def get_optionals(self):
|
def get_optionals(self):
|
||||||
|
"""
|
||||||
|
Get the optionals of the container.
|
||||||
|
:rtype : (syntax.SemanticType | BaseContainer)
|
||||||
|
:return: The optionals of the container
|
||||||
|
"""
|
||||||
return self.optionals
|
return self.optionals
|
||||||
|
|
||||||
def get_others(self):
|
def get_others(self):
|
||||||
|
"""
|
||||||
|
Get the other values of the container.
|
||||||
|
:rtype : dict[str, str]
|
||||||
|
:return: The other values of the container
|
||||||
|
"""
|
||||||
return self.others
|
return self.others
|
||||||
|
|
||||||
def export(self, exm):
|
def export(self, exm):
|
||||||
"""
|
"""
|
||||||
|
Export the container to a string.
|
||||||
:type exm: export.ExportManager
|
:type exm: export.ExportManager
|
||||||
:rtype : str
|
:rtype : str
|
||||||
"""
|
"""
|
||||||
|
|
@ -62,15 +86,27 @@ class BaseContainer:
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def add(self, other):
|
def add(self, other):
|
||||||
|
"""
|
||||||
|
Adds a list of elements to the container.
|
||||||
|
:param other: List of elements to add
|
||||||
|
:type other: syntax.SemanticType
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
self.content.append(other)
|
self.content.append(other)
|
||||||
|
|
||||||
def class_name(self):
|
def class_name(self):
|
||||||
|
"""
|
||||||
|
A string representation of the class name.
|
||||||
|
:rtype : str
|
||||||
|
"""
|
||||||
return self.__class__.__name__
|
return self.__class__.__name__
|
||||||
|
|
||||||
def validate(self, other):
|
def validate(self, other):
|
||||||
"""
|
"""
|
||||||
Takes a list as input and checks if every element is in map.
|
Takes a list as input and checks if every element is in map.
|
||||||
:return: Bool
|
:param other: List of elements to check
|
||||||
|
:type other: list[(syntax.SemanticType | BaseContainer)]
|
||||||
|
:return: True if every element is in map, False otherwise
|
||||||
"""
|
"""
|
||||||
for o in other:
|
for o in other:
|
||||||
if o not in self.map:
|
if o not in self.map:
|
||||||
|
|
@ -78,30 +114,68 @@ class BaseContainer:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def debug_map(self):
|
def debug_map(self):
|
||||||
|
"""
|
||||||
|
Prints the map of the container.
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
print(f'Debug for {self.class_name()} <{id(self)}>')
|
print(f'Debug for {self.class_name()} <{id(self)}>')
|
||||||
for k, v in self.map.items():
|
for k, v in self.map.items():
|
||||||
print(f'{k} = {v}')
|
print(f'{k} = {v}')
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
|
"""
|
||||||
|
:rtype : int
|
||||||
|
"""
|
||||||
return len(self.content)
|
return len(self.content)
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
|
"""
|
||||||
|
:ytype : iter[syntax.SemanticType]
|
||||||
|
"""
|
||||||
for content in self.content:
|
for content in self.content:
|
||||||
yield content
|
yield content
|
||||||
|
|
||||||
def __getitem__(self, item):
|
def __getitem__(self, item):
|
||||||
|
"""
|
||||||
|
:param item: Index of the element to get
|
||||||
|
:type item: int
|
||||||
|
:rtype : (syntax.SemanticType | BaseContainer)
|
||||||
|
"""
|
||||||
return self.content[item]
|
return self.content[item]
|
||||||
|
|
||||||
def __setitem__(self, key, value):
|
def __setitem__(self, key, value):
|
||||||
|
"""
|
||||||
|
:param key: Index of the element to set
|
||||||
|
:param value: Value to set
|
||||||
|
:type key: int
|
||||||
|
:type value: (syntax.SemanticType | BaseContainer)
|
||||||
|
"""
|
||||||
self.content[key] = value
|
self.content[key] = value
|
||||||
|
|
||||||
def __getslice__(self, start, end):
|
def __getslice__(self, start, end):
|
||||||
|
"""
|
||||||
|
:param start: Start index of the slice
|
||||||
|
:param end: End index of the slice
|
||||||
|
:type start: int
|
||||||
|
:type end: int
|
||||||
|
:rtype : list[(syntax.SemanticType | BaseContainer)]
|
||||||
|
"""
|
||||||
return self.content[start:end]
|
return self.content[start:end]
|
||||||
|
|
||||||
def __rshift__(self, other):
|
def __rshift__(self, other):
|
||||||
|
"""
|
||||||
|
:param other: The name of the map element to get
|
||||||
|
:type other: str
|
||||||
|
:rtype : (syntax.SemanticType | BaseContainer)
|
||||||
|
"""
|
||||||
return self.map[other]()
|
return self.map[other]()
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
|
"""
|
||||||
|
:param other: The other object to compare to
|
||||||
|
:type other: BaseContainer | list[(syntax.SemanticType | BaseContainer)] | syntax.SemanticType
|
||||||
|
:rtype : bool
|
||||||
|
"""
|
||||||
if not hasattr(other, "__len__"):
|
if not hasattr(other, "__len__"):
|
||||||
return False
|
return False
|
||||||
if len(self) != len(other):
|
if len(self) != len(other):
|
||||||
|
|
@ -123,13 +197,23 @@ class BaseContainer:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def __invert__(self):
|
def __invert__(self):
|
||||||
|
"""
|
||||||
|
Returns the inverted optionals of the container.
|
||||||
|
:rtype : BaseContainer
|
||||||
|
"""
|
||||||
return self.get_optionals()
|
return self.get_optionals()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
"""
|
||||||
|
:rtype : str
|
||||||
|
"""
|
||||||
return '{} ({})'.format(", ".join(map(str, self.content)),
|
return '{} ({})'.format(", ".join(map(str, self.content)),
|
||||||
", ".join(map(str, self.get_optionals())) if self.get_optionals() else "")
|
", ".join(map(str, self.get_optionals().content)) if self.get_optionals() else "")
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
"""
|
||||||
|
:rtype : str
|
||||||
|
"""
|
||||||
representation = {}
|
representation = {}
|
||||||
for content in self.content:
|
for content in self.content:
|
||||||
if type(content) in representation:
|
if type(content) in representation:
|
||||||
|
|
@ -146,6 +230,9 @@ class BaseContainer:
|
||||||
)
|
)
|
||||||
|
|
||||||
def print_all(self, ident=''):
|
def print_all(self, ident=''):
|
||||||
|
"""
|
||||||
|
Prints the container and all its content.
|
||||||
|
"""
|
||||||
print(ident + self.class_name())
|
print(ident + self.class_name())
|
||||||
for e in self:
|
for e in self:
|
||||||
if isinstance(e, BaseContainer):
|
if isinstance(e, BaseContainer):
|
||||||
|
|
@ -154,8 +241,12 @@ class BaseContainer:
|
||||||
print(ident + "> " + str(e))
|
print(ident + "> " + str(e))
|
||||||
print("")
|
print("")
|
||||||
|
|
||||||
def to_container(self, filter_func=None): # idea: additional parameters for encapsulation
|
def to_container(self, filter_func=None): # noqa : C901
|
||||||
return self
|
"""
|
||||||
|
Returns a container with the same content as the current container.
|
||||||
|
Used for compatibility with the syntax for encapsulation.
|
||||||
|
"""
|
||||||
|
return self # idea: additional parameters for encapsulation
|
||||||
|
|
||||||
|
|
||||||
# Define containers all the Enhanced text elements, divs, headers, list and any element that can be a container
|
# Define containers all the Enhanced text elements, divs, headers, list and any element that can be a container
|
||||||
|
|
@ -194,7 +285,7 @@ class EtCustomSpanContainer(BaseContainer):
|
||||||
type = "inline_elements"
|
type = "inline_elements"
|
||||||
|
|
||||||
def export(self, exm):
|
def export(self, exm):
|
||||||
self.subtype = "custom_" + self.content[0].content[0]
|
self.subtype = "custom_" + self.content[0].content[0] # noqa F821 (self.content[0] is a token, by definition
|
||||||
return super().export(exm)
|
return super().export(exm)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -244,7 +335,7 @@ class SeContainer(BaseContainer):
|
||||||
type = "structural_elements"
|
type = "structural_elements"
|
||||||
|
|
||||||
def export(self, exm):
|
def export(self, exm):
|
||||||
self.subtype = self[0].content[0]
|
self.subtype = "se_"+self[0].content[0]
|
||||||
return super().export(exm)
|
return super().export(exm)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -253,7 +344,7 @@ class HeaderContainer(BaseContainer):
|
||||||
subtype = "header"
|
subtype = "header"
|
||||||
|
|
||||||
def export(self, exm):
|
def export(self, exm):
|
||||||
self.others = {}
|
self.others = {} # noqa F821
|
||||||
self.others["header_level"] = len(self.content[0].content[0])
|
self.others["header_level"] = len(self.content[0].content[0])
|
||||||
return super().export(exm)
|
return super().export(exm)
|
||||||
|
|
||||||
|
|
@ -345,10 +436,12 @@ class ContextManager:
|
||||||
def __init__(self, parsed_list, name=None, ident=0):
|
def __init__(self, parsed_list, name=None, ident=0):
|
||||||
"""
|
"""
|
||||||
Takes a list of parsed tokens.
|
Takes a list of parsed tokens.
|
||||||
Parameters
|
:type parsed_list : list[syntax.SemanticType]
|
||||||
----------
|
:param parsed_list: List of parsed tokens output by our parser.
|
||||||
parsed_list : list[syntax.SemanticType]
|
:type name: str
|
||||||
List of parsed tokens output by our parser.
|
:param name: Name of the file being parsed.
|
||||||
|
:type ident: int
|
||||||
|
:param ident: Number of spaces to indent the output.
|
||||||
"""
|
"""
|
||||||
self.output = []
|
self.output = []
|
||||||
self.parsed_list = parsed_list
|
self.parsed_list = parsed_list
|
||||||
|
|
@ -369,15 +462,12 @@ class ContextManager:
|
||||||
"""
|
"""
|
||||||
Method to encapsulate a number of tokens together as a final container object
|
Method to encapsulate a number of tokens together as a final container object
|
||||||
and replace all elements in the pile with None, except the first one which becomes the container.
|
and replace all elements in the pile with None, except the first one which becomes the container.
|
||||||
Parameters
|
:type start : int
|
||||||
----------
|
:param start: Index of the pile where the encapsulation must begin.
|
||||||
start : int
|
:type end: int
|
||||||
Index of the pile where the encapsulation must begin.
|
:param end: Index of the pile where the encapsulation must end.
|
||||||
end : int
|
:rtype: list[(BaseContainer|None)]
|
||||||
Index of the pile where the encapsulation must end.
|
:return: List of containers and None objects.
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
list[(BaseContainer|None)]
|
|
||||||
"""
|
"""
|
||||||
# Enabling this will allow us to debug the pile
|
# Enabling this will allow us to debug the pile
|
||||||
# print(f"Step : [{end}] - encapsulation:")
|
# print(f"Step : [{end}] - encapsulation:")
|
||||||
|
|
@ -419,25 +509,38 @@ class ContextManager:
|
||||||
container.add(self.pile[end])
|
container.add(self.pile[end])
|
||||||
self.pile[end] = None
|
self.pile[end] = None
|
||||||
self.pile[start] = container
|
self.pile[start] = container
|
||||||
|
return self.pile # ? I think this is the right way to return the pile
|
||||||
# print(" <<< Pile:", self.pile)
|
# print(" <<< Pile:", self.pile)
|
||||||
|
|
||||||
def _add_matched(self, label, index):
|
def _add_matched(self, label, index):
|
||||||
|
"""
|
||||||
|
Method to add a matched element to the dictionary of matched elements.
|
||||||
|
:type label : str
|
||||||
|
:param label: Label of the matched element.
|
||||||
|
:type index: int
|
||||||
|
:param index: Index of the matched element in the pile.
|
||||||
|
"""
|
||||||
if label not in self.matched_elements:
|
if label not in self.matched_elements:
|
||||||
self.matched_elements[label] = []
|
self.matched_elements[label] = []
|
||||||
self.matched_elements[label] += [index]
|
self.matched_elements[label] += [index]
|
||||||
|
|
||||||
def _get_matched(self, label):
|
def _get_matched(self, label):
|
||||||
|
"""
|
||||||
|
Method to get the index of the last matched element of a given label.
|
||||||
|
:type label: str
|
||||||
|
:param label: Label of the matched element.
|
||||||
|
:rtype: int
|
||||||
|
:return: Index of the last matched element
|
||||||
|
"""
|
||||||
return self.matched_elements[label].pop()
|
return self.matched_elements[label].pop()
|
||||||
|
|
||||||
def __call__(self):
|
def __call__(self):
|
||||||
"""
|
"""
|
||||||
Interprets the list of tokens provided and deduces context, encapsulating them to their closest neighbour and
|
Interprets the list of tokens provided and deduces context, encapsulating them to their closest neighbour and
|
||||||
containing all tokens inbetween.
|
containing all tokens inbetween.
|
||||||
Returns
|
:rtype: list[BaseContainer]
|
||||||
-------
|
:return: Returns the pile entirely processed as a list of containers.
|
||||||
list[BaseContainer]
|
:raises: MismatchedContainerError if a container is not matched to its corresponding token.
|
||||||
Returns the pile entirely processed as a list of containers.
|
|
||||||
"""
|
"""
|
||||||
# self.pile = self.parsed_list.copy()
|
# self.pile = self.parsed_list.copy()
|
||||||
if self.contextualised:
|
if self.contextualised:
|
||||||
|
|
@ -448,6 +551,7 @@ class ContextManager:
|
||||||
while index < len(self.parsed_list):
|
while index < len(self.parsed_list):
|
||||||
token = self.parsed_list[index]
|
token = self.parsed_list[index]
|
||||||
token.line_number = line_number
|
token.line_number = line_number
|
||||||
|
token.index = index
|
||||||
token.file_name = self.name
|
token.file_name = self.name
|
||||||
token.ident = self.ident
|
token.ident = self.ident
|
||||||
self.pile.append(token)
|
self.pile.append(token)
|
||||||
|
|
@ -480,16 +584,17 @@ class ContextManager:
|
||||||
|
|
||||||
# Error if closing token does not have a start
|
# Error if closing token does not have a start
|
||||||
elif isinstance(token, syntax.ClosedSemanticType):
|
elif isinstance(token, syntax.ClosedSemanticType):
|
||||||
raise MismatchedContainerError(token)
|
raise MismatchedContainerError(token, self.parsed_list)
|
||||||
|
|
||||||
# Starting token by default (can cause unintended behaviours on bad implementations)
|
# Starting token by default (can cause unintended behaviours on bad implementations)
|
||||||
elif isinstance(token, syntax.TokensToMatch):
|
elif isinstance(token, syntax.TokensToMatch):
|
||||||
self._add_matched(token.label, index)
|
self._add_matched(token.label, index)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise MismatchedContainerError(token)
|
raise MismatchedContainerError(token, self.parsed_list)
|
||||||
|
|
||||||
except MismatchedContainerError as e:
|
except MismatchedContainerError as e:
|
||||||
|
error_mngr.log_message(f"In context: {e.get_context()}", level="CRITICAL")
|
||||||
error_mngr.log_exception(e, level="CRITICAL") # FUTURE: Try to guess some hints.
|
error_mngr.log_exception(e, level="CRITICAL") # FUTURE: Try to guess some hints.
|
||||||
index += 1
|
index += 1
|
||||||
|
|
||||||
|
|
@ -497,6 +602,10 @@ class ContextManager:
|
||||||
return self.finalize_pile()
|
return self.finalize_pile()
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
|
"""
|
||||||
|
Iterator over the pile.
|
||||||
|
:ytype: BaseContainer
|
||||||
|
"""
|
||||||
for e in self.pile:
|
for e in self.pile:
|
||||||
if e:
|
if e:
|
||||||
yield e
|
yield e
|
||||||
|
|
@ -505,6 +614,7 @@ class ContextManager:
|
||||||
"""
|
"""
|
||||||
Function for cleaning up of the pile after full contextualisation.
|
Function for cleaning up of the pile after full contextualisation.
|
||||||
Removes Nones and checks for any errors or illogical containers.
|
Removes Nones and checks for any errors or illogical containers.
|
||||||
|
:return: list[BaseContainer]
|
||||||
"""
|
"""
|
||||||
final_pile = []
|
final_pile = []
|
||||||
for p in self.pile:
|
for p in self.pile:
|
||||||
|
|
@ -532,6 +642,12 @@ class ContextManager:
|
||||||
def lookahead(self, token, index):
|
def lookahead(self, token, index):
|
||||||
"""
|
"""
|
||||||
Iterates the pile beginning from index and looks for all tokens matching labels with token.
|
Iterates the pile beginning from index and looks for all tokens matching labels with token.
|
||||||
|
:type token : syntax.BaseContainer
|
||||||
|
:param token: Token to look for.
|
||||||
|
:type index : int
|
||||||
|
:param index: Index of the token in the pile.
|
||||||
|
:return: (number of tokens matched, number of linebreaks)
|
||||||
|
:rtype: (int, int)
|
||||||
"""
|
"""
|
||||||
range_to_encapsulate = 0
|
range_to_encapsulate = 0
|
||||||
line_skipped = 0
|
line_skipped = 0
|
||||||
|
|
@ -557,18 +673,23 @@ class ContextManager:
|
||||||
return range_to_encapsulate, line_skipped
|
return range_to_encapsulate, line_skipped
|
||||||
|
|
||||||
def recontext(self, token):
|
def recontext(self, token):
|
||||||
|
"""
|
||||||
|
Function to recontextualise the content of a token.
|
||||||
|
:param token: Token to recontextualise.
|
||||||
|
:type token: syntax.SemanticType
|
||||||
|
:return: Token to recontextualise.
|
||||||
|
:rtype: syntax.SemanticType
|
||||||
|
"""
|
||||||
token.content = ContextManager(token.content, name=self.name)()
|
token.content = ContextManager(token.content, name=self.name)()
|
||||||
|
|
||||||
def get_last_container_in_pile(self, index):
|
def get_last_container_in_pile(self, index):
|
||||||
"""
|
"""
|
||||||
Returns the last element in the pile if it is a Container, raises an error otherwise.
|
Returns the last element in the pile if it is a Container, raises an error otherwise.
|
||||||
Return
|
:type index : int
|
||||||
------
|
:param index: Index of the element to check.
|
||||||
BaseContainer
|
:return: Last element in the pile if it is a Container, raises an error otherwise.
|
||||||
|
:rtype: BaseContainer
|
||||||
Raises
|
:raise: error_mngr.LonelyOptionalError when an element is found in the pile that is not encapsulated in a container.
|
||||||
------
|
|
||||||
error_mngr.LonelyOptionalError
|
|
||||||
"""
|
"""
|
||||||
i = index-1 # skip last token as it is self
|
i = index-1 # skip last token as it is self
|
||||||
while i >= 0:
|
while i >= 0:
|
||||||
|
|
@ -581,6 +702,9 @@ class ContextManager:
|
||||||
log_exception(LonelyOptionalError(self.pile[index], None), level="CRITICAL")
|
log_exception(LonelyOptionalError(self.pile[index], None), level="CRITICAL")
|
||||||
|
|
||||||
def print_all(self):
|
def print_all(self):
|
||||||
|
"""
|
||||||
|
Prints the pile.
|
||||||
|
"""
|
||||||
for e in self:
|
for e in self:
|
||||||
if isinstance(e, BaseContainer):
|
if isinstance(e, BaseContainer):
|
||||||
e.print_all()
|
e.print_all()
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,20 @@
|
||||||
# Module for containing super important variables
|
"""Module for containing super important variables
|
||||||
# Environment has self._mParams for mandatory parameters, self._sParams for secondary parameters and
|
Environment has self._mParams for mandatory parameters, self._sParams for secondary parameters and
|
||||||
# self.wasInitialised and integrity_check for debug.
|
- self.wasInitialised and integrity_check for debug.
|
||||||
# __getattr__ and __setattr__ check for existing super, s or m parameters, returns error if not found.
|
- __getattr__ and __setattr__ check for existing super, s or m parameters, returns error if not found.
|
||||||
# Usage:
|
Usage:
|
||||||
# from bootstraparse.modules.environment import Environment
|
- from bootstraparse.modules.environment import Environment
|
||||||
# env = Environment()
|
- env = Environment()
|
||||||
# env.integrity_check() -> Checks if all mandatory parameters are set.
|
- env.integrity_check() -> Checks if all mandatory parameters are set.
|
||||||
# env["config"] -> returns config object
|
- env["config"] -> returns config object
|
||||||
# env["template"] -> returns template object
|
- env["template"] -> returns template object
|
||||||
# env["export_mngr"] -> returns export manager object
|
- env["export_mngr"] -> returns export manager object
|
||||||
# env["global_path"] -> returns global path ???
|
- env["global_path"] -> returns global path ???
|
||||||
# env["user_path"] -> returns user path ???
|
- env["user_path"] -> returns user path ???
|
||||||
# env["site_path"] -> returns site path
|
- env["site_path"] -> returns site path
|
||||||
# env["export"] -> returns export object ???
|
- env["export"] -> returns export object ???
|
||||||
# env["site_crawler"] -> returns site crawler object
|
- env["site_crawler"] -> returns site crawler object
|
||||||
|
"""
|
||||||
|
|
||||||
from bootstraparse.modules import error_mngr
|
from bootstraparse.modules import error_mngr
|
||||||
|
|
||||||
|
|
@ -26,6 +27,10 @@ class Environment:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
"""
|
||||||
|
Initialises the environment, all parameters are set to None.
|
||||||
|
Set _wasInitialised to False for all parameters.
|
||||||
|
"""
|
||||||
# mandatoryParameters
|
# mandatoryParameters
|
||||||
self._mParams = {
|
self._mParams = {
|
||||||
'config': None,
|
'config': None,
|
||||||
|
|
@ -60,8 +65,10 @@ class Environment:
|
||||||
|
|
||||||
def __getattr__(self, attribute):
|
def __getattr__(self, attribute):
|
||||||
"""
|
"""
|
||||||
Getter for all parameters.
|
Getter for all parameters, looks for super if the parameter is prefaced with an underscore.
|
||||||
|
Looks for mandatory parameters first, then secondary parameters.
|
||||||
:param attribute: The name of the parameter to get.
|
:param attribute: The name of the parameter to get.
|
||||||
|
:type attribute: str
|
||||||
:return: The value of the parameter.
|
:return: The value of the parameter.
|
||||||
"""
|
"""
|
||||||
if attribute[0] == "_":
|
if attribute[0] == "_":
|
||||||
|
|
@ -80,8 +87,9 @@ class Environment:
|
||||||
|
|
||||||
def __setattr__(self, attribute, value):
|
def __setattr__(self, attribute, value):
|
||||||
"""
|
"""
|
||||||
Setter for all parameters.
|
Setter for all parameters, looks for super if the parameter is prefaced with an underscore.
|
||||||
:param attribute: The name of the parameter to set.
|
:param attribute: The name of the parameter to set.
|
||||||
|
:type attribute: str
|
||||||
"""
|
"""
|
||||||
if attribute[0] == "_":
|
if attribute[0] == "_":
|
||||||
super().__setattr__(attribute, value)
|
super().__setattr__(attribute, value)
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,14 @@
|
||||||
# Dedicated module for defining and interpreting errors as well as generating error messages
|
"""
|
||||||
# You're probably here for log_message or log_exception.
|
Dedicated module for defining and interpreting errors as well as generating error messages
|
||||||
# They take: message, level=("ERROR, "INFO", "WARNING", "DEBUG", "CRITICAL")
|
You're probably here for log_message or log_exception.
|
||||||
# There's also a dict_check(dic, *args) that returns true if all args are keys in the dict.
|
- They take: message, level=("ERROR, "INFO", "WARNING", "DEBUG", "CRITICAL")
|
||||||
# Usage:
|
There's also a dict_check(dic, *args) that returns true if all args are keys in the dict.
|
||||||
# from bootstraparse.modules.error_mngr import log_message, log_exception
|
Usage:
|
||||||
# log_message("This is a message", level="INFO") level=("ERROR, "INFO", "WARNING", "DEBUG", "CRITICAL")
|
- from bootstraparse.modules.error_mngr import log_message, log_exception
|
||||||
# log_exception(Exception("This is an exception"), level="ERROR")
|
- log_message("This is a message", level="INFO") level=("ERROR, "INFO", "WARNING", "DEBUG", "CRITICAL")
|
||||||
# dict_check({"a": 1, "b": 2}, "a", "b") # returns [True, True]
|
- log_exception(Exception("This is an exception"), level="ERROR")
|
||||||
|
- dict_check({"a": 1, "b": 2}, "a", "b") # returns [True, True]
|
||||||
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import traceback
|
import traceback
|
||||||
|
|
@ -15,17 +17,19 @@ from bootstraparse.modules.tools import __GLk # __GFi, __GFu, __GL
|
||||||
|
|
||||||
# Define the error codes
|
# Define the error codes
|
||||||
_ERRORS = ["ParsingError", "MismatchedContainerError"]
|
_ERRORS = ["ParsingError", "MismatchedContainerError"]
|
||||||
__all__ = _ERRORS+[]
|
|
||||||
|
|
||||||
|
|
||||||
def init_logging(filename=None, loglevel="ERROR", filemode='w', handler=None):
|
def init_logging(filename=None, loglevel="ERROR", filemode='w', handler=None):
|
||||||
"""
|
"""
|
||||||
Initializes logging
|
Initializes logging
|
||||||
:param filename: The name of the log file
|
:param filename: The path for the log file
|
||||||
:param loglevel: The level of logging
|
:param loglevel: The level of logging: "ERROR", "INFO", "WARNING", "DEBUG", "CRITICAL"
|
||||||
:type loglevel: str
|
:param filemode: The mode of the log file: "w", "a"
|
||||||
:param filemode: The mode of the log file
|
|
||||||
:param handler: The handler to use
|
:param handler: The handler to use
|
||||||
|
:type filename: str
|
||||||
|
:type loglevel: str
|
||||||
|
:type filemode: str
|
||||||
|
:type handler: logging.Handler
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
loglevel = loglevel.upper()
|
loglevel = loglevel.upper()
|
||||||
|
|
@ -50,6 +54,7 @@ def log_message(message, level="ERROR"):
|
||||||
:param message: The message to log
|
:param message: The message to log
|
||||||
:param level: The level of the message
|
:param level: The level of the message
|
||||||
:type level: str
|
:type level: str
|
||||||
|
:type message: str
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
level = level.lower()
|
level = level.lower()
|
||||||
|
|
@ -83,52 +88,79 @@ def log_exception(exception, level="ERROR"):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def dict_check(dic, *args):
|
|
||||||
"""
|
|
||||||
Helper function to test existence within a dictionary.
|
|
||||||
:param dic: The dictionary of dictionaries to check
|
|
||||||
:param args: Any number of keys to check the dictionaries for
|
|
||||||
:return: A table of Booleans for every key checked.
|
|
||||||
"""
|
|
||||||
output = [False for _ in args]
|
|
||||||
for i in range(len(args)):
|
|
||||||
if args[i] in dic:
|
|
||||||
output[i] = True
|
|
||||||
dic = dic[args[i]]
|
|
||||||
else:
|
|
||||||
break
|
|
||||||
return output
|
|
||||||
|
|
||||||
|
|
||||||
def str_dict_check(dic, *args):
|
|
||||||
"""
|
|
||||||
Helper function to test existence within a dictionary and return a string of the values.
|
|
||||||
'arg[0]' : True or False
|
|
||||||
|
|
||||||
"""
|
|
||||||
out = dict_check(dic, *args)
|
|
||||||
return "\n".join([f"{args[i]}: {out[i]}" for i in range(len(out))])
|
|
||||||
|
|
||||||
|
|
||||||
class BootstraparseError(Exception):
|
class BootstraparseError(Exception):
|
||||||
|
"""
|
||||||
|
Base class for all Bootstraparse errors
|
||||||
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class BootstraparseTokenError(BootstraparseError):
|
||||||
|
"""
|
||||||
|
Error on a token, provides if possible the line and column number of the error,
|
||||||
|
the file name and the message of the error
|
||||||
|
and if possible a context for the error
|
||||||
|
"""
|
||||||
|
def __init__(self, token, pile, message):
|
||||||
|
self.token = token
|
||||||
|
self.pile = pile
|
||||||
|
if token is not None:
|
||||||
|
self.line = token.line_number
|
||||||
|
self.index = token.index
|
||||||
|
self.label = token.label
|
||||||
|
self.name = token.file_name
|
||||||
|
else:
|
||||||
|
self.line = None
|
||||||
|
self.index = None
|
||||||
|
self.label = None
|
||||||
|
self.name = None
|
||||||
|
self.context = self.get_context()
|
||||||
|
super().__init__(message+"\n"+self.context_multiline())
|
||||||
|
|
||||||
|
def get_context(self, context_size=5):
|
||||||
|
"""
|
||||||
|
Returns the context of the error
|
||||||
|
:return: The context of the error
|
||||||
|
:rtype: str
|
||||||
|
"""
|
||||||
|
if self.pile:
|
||||||
|
st = max(0, self.index - context_size)
|
||||||
|
en = min(len(self.pile), self.index + context_size)
|
||||||
|
return self.pile[st:en]
|
||||||
|
return []
|
||||||
|
|
||||||
|
def context_multiline(self, context_size=10):
|
||||||
|
"""
|
||||||
|
Returns the context of the error as a multiline string
|
||||||
|
:return: The context of the error
|
||||||
|
:rtype: str
|
||||||
|
"""
|
||||||
|
if self.pile:
|
||||||
|
return "\n".join([
|
||||||
|
f"{' ' if i!=context_size else '> '}{i-context_size:2d}: {j}"
|
||||||
|
for i, j in enumerate(self.get_context(context_size)) if j.label != "linebreak"
|
||||||
|
])
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
class ParsingError(Exception):
|
class ParsingError(Exception):
|
||||||
"""
|
"""
|
||||||
Exception class for parsing errors
|
Exception class for parsing errors
|
||||||
:param message: The message to display
|
|
||||||
:type message: str
|
|
||||||
:param line: The line number of the error
|
|
||||||
:param column: The column number of the error
|
|
||||||
:param file: The name of the file
|
|
||||||
:return: None
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, message=None, line=None, column=None, file=None):
|
def __init__(self, message=None, line=None, column=None, file=None):
|
||||||
"""
|
"""
|
||||||
Initializes the ParsingError class with the filename and a line and column number
|
Initializes the ParsingError class with the filename and a line and column number
|
||||||
based on the current position in the file (if available)
|
based on the current position in the file (if available)
|
||||||
|
:param message: The message to display
|
||||||
|
:type message: str
|
||||||
|
:param line: The line number of the error
|
||||||
|
:type line: int
|
||||||
|
:param column: The column number of the error
|
||||||
|
:type column: int
|
||||||
|
:param file: The name of the file
|
||||||
|
:type file: str
|
||||||
|
:return: None
|
||||||
"""
|
"""
|
||||||
super().__init__(message)
|
super().__init__(message)
|
||||||
self.line = line
|
self.line = line
|
||||||
|
|
@ -149,12 +181,18 @@ class ParsingError(Exception):
|
||||||
return str(self.message)
|
return str(self.message)
|
||||||
|
|
||||||
|
|
||||||
class MismatchedContainerError(BootstraparseError):
|
class MismatchedContainerError(BootstraparseTokenError):
|
||||||
"""
|
"""
|
||||||
The token is not final and cannot be contained. Indicative of a mismatched token.
|
The token is not final and cannot be contained. Indicative of a mismatched token.
|
||||||
"""
|
"""
|
||||||
def __init__(self, token):
|
def __init__(self, token, pile=None):
|
||||||
|
"""
|
||||||
|
Initializes the MismatchedContainerError class with the token that was not final
|
||||||
|
:param token: The token that is not final
|
||||||
|
:type token: syntax.SemanticType
|
||||||
|
"""
|
||||||
self.token = token
|
self.token = token
|
||||||
|
self.pile = pile
|
||||||
if token:
|
if token:
|
||||||
self.line = token.line_number
|
self.line = token.line_number
|
||||||
self.label = token.label
|
self.label = token.label
|
||||||
|
|
@ -163,7 +201,7 @@ class MismatchedContainerError(BootstraparseError):
|
||||||
self.line = None
|
self.line = None
|
||||||
self.label = None
|
self.label = None
|
||||||
self.name = None
|
self.name = None
|
||||||
super().__init__(f"Could not process {self.label} at line {self.line} in file {self.name}.")
|
super().__init__(token, pile, f"Could not process {self.label} at line {self.line} in file {self.name}.")
|
||||||
|
|
||||||
|
|
||||||
class LonelyOptionalError(BootstraparseError):
|
class LonelyOptionalError(BootstraparseError):
|
||||||
|
|
@ -171,6 +209,14 @@ class LonelyOptionalError(BootstraparseError):
|
||||||
Optional token could not be matched with last element in pile (not a container).
|
Optional token could not be matched with last element in pile (not a container).
|
||||||
"""
|
"""
|
||||||
def __init__(self, token, last_in_pile):
|
def __init__(self, token, last_in_pile):
|
||||||
|
"""
|
||||||
|
Initializes the LonelyOptionalError class with the token found and the last element in the pile
|
||||||
|
Used when a token is found that is optional and cannot be matched with the last element in the pile (not a container)
|
||||||
|
:param token: The token that is not final
|
||||||
|
:type token: syntax.SemanticType
|
||||||
|
:param last_in_pile: The last element in the pile
|
||||||
|
:type last_in_pile: syntax.SemanticType
|
||||||
|
"""
|
||||||
self.token = token
|
self.token = token
|
||||||
if token:
|
if token:
|
||||||
self.line = token.line_number
|
self.line = token.line_number
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,17 @@
|
||||||
# Module for final generation of the translated website
|
"""
|
||||||
# Usage:
|
Module for final generation of the translated website
|
||||||
# from bootstraparse.modules.export import ExportManager, ExportRequest, ExportResponse
|
Usage:
|
||||||
# rqs = ExportRequest("strucural_elements", "div", "optionals", {"id": "my_id", "class": "my_class"})
|
- from bootstraparse.modules.export import ExportManager, ExportRequest, ExportResponse
|
||||||
# rsp = ExportResponse("start_string", "end_string")
|
- rqs = ExportRequest("strucural_elements", "div", "optionals", {"id": "my_id", "class": "my_class"})
|
||||||
# em = ExportManager(config_file, template_file)
|
- rsp = ExportResponse("start_string", "end_string")
|
||||||
# em(ExportRequest()) -> ExportResponse()
|
- em = ExportManager(config_file, template_file)
|
||||||
# import rich
|
- em(ExportRequest()) -> ExportResponse()
|
||||||
import rich
|
"""
|
||||||
|
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from bootstraparse.modules import config, pathresolver, error_mngr, context_mngr
|
from bootstraparse.modules import config, pathresolver, error_mngr, context_mngr
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
from bootstraparse.modules import tools
|
||||||
|
|
||||||
from bootstraparse.modules import syntax # noqa F401
|
from bootstraparse.modules import syntax # noqa F401
|
||||||
|
|
||||||
|
|
@ -47,7 +48,14 @@ class ExportManager:
|
||||||
"""
|
"""
|
||||||
Transforms ExportRequest tuples to ExportResponse tuples with the config-provided appropriate markup.
|
Transforms ExportRequest tuples to ExportResponse tuples with the config-provided appropriate markup.
|
||||||
"""
|
"""
|
||||||
def __init__(self, cnoifg, templates): # noqa
|
def __init__(self, cnoifg, templates):
|
||||||
|
"""
|
||||||
|
Initialization function for the ExportManager.
|
||||||
|
:param cnoifg: Config file
|
||||||
|
:type cnoifg: config.ConfigLoader
|
||||||
|
:param templates: Templates file
|
||||||
|
:type templates: config.ConfigLoader
|
||||||
|
"""
|
||||||
self.config = cnoifg
|
self.config = cnoifg
|
||||||
self.templates = templates
|
self.templates = templates
|
||||||
self.advanced_export = {
|
self.advanced_export = {
|
||||||
|
|
@ -61,6 +69,12 @@ class ExportManager:
|
||||||
}
|
}
|
||||||
|
|
||||||
def __call__(self, export_request):
|
def __call__(self, export_request):
|
||||||
|
"""
|
||||||
|
Callable function for ExportManager, transforming ExportRequest tuples into ExportResponse tuples.
|
||||||
|
:param export_request: ExportRequest tuples
|
||||||
|
:type export_request: ExportRequest
|
||||||
|
:return: ExportResponse tuples
|
||||||
|
"""
|
||||||
return self.transform(export_request)
|
return self.transform(export_request)
|
||||||
|
|
||||||
def transform(self, export_request):
|
def transform(self, export_request):
|
||||||
|
|
@ -82,18 +96,10 @@ class ExportManager:
|
||||||
"""
|
"""
|
||||||
Function for initializing other transform functions.
|
Function for initializing other transform functions.
|
||||||
|
|
||||||
Parameters:
|
:param export_request: ExportRequest tuples
|
||||||
----------
|
:type export_request: ExportRequest
|
||||||
export_request: ExportRequest tuples
|
:return: start, end, optionals
|
||||||
|
:rtype: str, str, str
|
||||||
Returns:
|
|
||||||
-------
|
|
||||||
start: str
|
|
||||||
Start string of the markup element
|
|
||||||
end: str
|
|
||||||
End string of the markup element
|
|
||||||
optionals: syntax.Optionals
|
|
||||||
Optionals object containing html_insert and class_insert
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
start, end = None, None
|
start, end = None, None
|
||||||
|
|
@ -101,8 +107,7 @@ class ExportManager:
|
||||||
start, end = self.templates["bootstrap"][export_request.type][export_request.subtype]
|
start, end = self.templates["bootstrap"][export_request.type][export_request.subtype]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
log_entries = ["bootstrap", export_request.type, export_request.subtype]
|
log_entries = ["bootstrap", export_request.type, export_request.subtype]
|
||||||
log_ = error_mngr.dict_check(self.templates, *log_entries)
|
log_ = tools.dict_check(self.templates, *log_entries)
|
||||||
print()
|
|
||||||
error_mngr.log_exception(
|
error_mngr.log_exception(
|
||||||
KeyError(
|
KeyError(
|
||||||
f'Template "bootstrap"/{export_request.type}/{export_request.subtype} could not be found.\n' +
|
f'Template "bootstrap"/{export_request.type}/{export_request.subtype} could not be found.\n' +
|
||||||
|
|
@ -151,6 +156,7 @@ class ExportManager:
|
||||||
"""
|
"""
|
||||||
Specific template for display.
|
Specific template for display.
|
||||||
:type export_request: ExportRequest
|
:type export_request: ExportRequest
|
||||||
|
:rtype: ExportResponse
|
||||||
"""
|
"""
|
||||||
start, end, optionals = self._get_template(export_request)
|
start, end, optionals = self._get_template(export_request)
|
||||||
start = start.format(optionals=optionals, display_level=export_request.others["display_level"])
|
start = start.format(optionals=optionals, display_level=export_request.others["display_level"])
|
||||||
|
|
@ -160,6 +166,7 @@ class ExportManager:
|
||||||
"""
|
"""
|
||||||
Specific template for link.
|
Specific template for link.
|
||||||
:type export_request: ExportRequest
|
:type export_request: ExportRequest
|
||||||
|
:rtype: ExportResponse
|
||||||
"""
|
"""
|
||||||
start, end, _ = self._get_template(export_request)
|
start, end, _ = self._get_template(export_request)
|
||||||
start = start.format(url=export_request.others["url"])
|
start = start.format(url=export_request.others["url"])
|
||||||
|
|
@ -169,6 +176,7 @@ class ExportManager:
|
||||||
"""
|
"""
|
||||||
Specific template for table content.
|
Specific template for table content.
|
||||||
:type export_request: ExportRequest
|
:type export_request: ExportRequest
|
||||||
|
:rtype: ExportResponse
|
||||||
"""
|
"""
|
||||||
start, end, _ = self._get_template(export_request)
|
start, end, _ = self._get_template(export_request)
|
||||||
start = start.format(col_span=export_request.others["col_span"])
|
start = start.format(col_span=export_request.others["col_span"])
|
||||||
|
|
@ -178,6 +186,7 @@ class ExportManager:
|
||||||
"""
|
"""
|
||||||
Specific template for images.
|
Specific template for images.
|
||||||
:type export_request: ExportRequest
|
:type export_request: ExportRequest
|
||||||
|
:rtype: ExportResponse
|
||||||
"""
|
"""
|
||||||
start, end, optionals = self._get_template(export_request)
|
start, end, optionals = self._get_template(export_request)
|
||||||
end = end.format(optionals=optionals)
|
end = end.format(optionals=optionals)
|
||||||
|
|
@ -191,12 +200,12 @@ class ContextConverter:
|
||||||
def __init__(self, pile, exporter, destination):
|
def __init__(self, pile, exporter, destination):
|
||||||
"""
|
"""
|
||||||
Takes a pile and the exporter object
|
Takes a pile and the exporter object
|
||||||
Parameters
|
:type pile : list[context_mngr.BaseContainer]
|
||||||
----------
|
:param pile: output from the context manager.
|
||||||
pile : list[context_mngr.BaseContainer]
|
:type exporter : ExportManager
|
||||||
pile output from the context manager.
|
:param exporter: Our ExportManager
|
||||||
exporter : ExportManager
|
:type destination : str
|
||||||
Our ExportManager
|
:param destination: Destination of the output file.
|
||||||
"""
|
"""
|
||||||
self.io_output = StringIO()
|
self.io_output = StringIO()
|
||||||
self.pile = pile
|
self.pile = pile
|
||||||
|
|
@ -206,7 +215,8 @@ class ContextConverter:
|
||||||
|
|
||||||
def process_pile(self):
|
def process_pile(self):
|
||||||
"""
|
"""
|
||||||
Main method processing the given pile.
|
Processes the pile and writes the output to the io_output object.
|
||||||
|
:rtype: StringIO
|
||||||
"""
|
"""
|
||||||
for container in self.pile:
|
for container in self.pile:
|
||||||
self.io_output.write(container.export(self.exporter))
|
self.io_output.write(container.export(self.exporter))
|
||||||
|
|
@ -224,6 +234,7 @@ class ContextConverter:
|
||||||
def readlines(self):
|
def readlines(self):
|
||||||
"""
|
"""
|
||||||
Yields the converted pile line after line
|
Yields the converted pile line after line
|
||||||
|
:rtype: list[str]
|
||||||
"""
|
"""
|
||||||
return self.io_output.readlines()
|
return self.io_output.readlines()
|
||||||
|
|
||||||
|
|
@ -232,6 +243,9 @@ class ContextConverter:
|
||||||
f"Status: {'initialized' if self.io_initialized else 'uninitialized'}"
|
f"Status: {'initialized' if self.io_initialized else 'uninitialized'}"
|
||||||
|
|
||||||
def print_all(self):
|
def print_all(self):
|
||||||
|
"""
|
||||||
|
Prints the entirety of the converted pile
|
||||||
|
"""
|
||||||
print(self)
|
print(self)
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
|
|
@ -239,10 +253,11 @@ class ContextConverter:
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__': # pragma: no cover
|
if __name__ == '__main__': # pragma: no cover
|
||||||
|
import rich
|
||||||
from bootstraparse.modules import parser
|
from bootstraparse.modules import parser
|
||||||
|
|
||||||
io_string = StringIO(
|
io_string = StringIO(
|
||||||
"""[this is a link]('http://te.st')"""
|
"""! This is a test ! {{fgd}}"""
|
||||||
)
|
)
|
||||||
test = parser.parse_line(io_string)
|
test = parser.parse_line(io_string)
|
||||||
__config = config.ConfigLoader(pathresolver.b_path("configs/"))
|
__config = config.ConfigLoader(pathresolver.b_path("configs/"))
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
# Main parser, gets config files and parses them for the context manager.
|
"""
|
||||||
# parse_line takes a io and outputs it all as a list of parsed elements
|
Main parser, gets config files and parses them for the context manager.
|
||||||
# Usage:
|
parse_line takes a io and outputs it all as a list of parsed elements
|
||||||
# from bootstraparse.modules.parser import parse_line
|
Usage:
|
||||||
# parse_line(io) -> [element, element, element]
|
- from bootstraparse.modules.parser import parse_line
|
||||||
|
- parse_line(io) -> [element, element, element]
|
||||||
|
"""
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
|
||||||
import bootstraparse.modules.syntax as syntax
|
import bootstraparse.modules.syntax as syntax
|
||||||
|
|
@ -12,10 +13,10 @@ import bootstraparse.modules.syntax as syntax
|
||||||
def parse_line(io):
|
def parse_line(io):
|
||||||
"""
|
"""
|
||||||
Takes an io string and returns the parsed output.
|
Takes an io string and returns the parsed output.
|
||||||
Parameters:
|
:param io: The io string to parse.
|
||||||
io (StringIO): The io string to parse.
|
:type io: StringIO
|
||||||
Returns:
|
:return: The parsed output.
|
||||||
list[syntax.SemanticType]: The parsed output.
|
:rtype: list[syntax.SemanticType]
|
||||||
"""
|
"""
|
||||||
output = []
|
output = []
|
||||||
for line in io.readlines():
|
for line in io.readlines():
|
||||||
|
|
|
||||||
|
|
@ -1,27 +1,33 @@
|
||||||
# Module for resolving relative path problems
|
"""
|
||||||
# PathResolver takes a relative path in the module and outputs the absolute path,
|
Module for resolving relative path problems
|
||||||
# BoostraPath can deal with relative paths in the installation folder.
|
PathResolver takes a relative path in the module and outputs the absolute path,
|
||||||
# Usage:
|
BoostraPath can deal with relative paths in the installation folder.
|
||||||
# from bootstraparse.modules.pathresolver import PathResolver, b_path
|
Usage:
|
||||||
# b_path("../relative/path/to/file") # returns absolute path to file from the bootstraparse folder
|
- from bootstraparse.modules.pathresolver import PathResolver, b_path
|
||||||
# path= PathResolver("../relative/path/to/file") # Make a PathResolver object pointing at the first path given
|
- b_path("../relative/path/to/file") # returns absolute path to file from the bootstraparse folder
|
||||||
|
- path= PathResolver("../relative/path/to/file") # Make a PathResolver object pointing at the first path given
|
||||||
|
"""
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
class PathResolver:
|
class PathResolver:
|
||||||
"""
|
"""
|
||||||
Initialised with a relative path and returns the translated absolute path
|
Initialised with a relative path and returns the translated absolute path
|
||||||
:param base_path: Relative path to be resolved
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, base_path):
|
def __init__(self, base_path):
|
||||||
|
"""
|
||||||
|
Initialises the PathResolver with the base path
|
||||||
|
:param base_path: Base path
|
||||||
|
:type base_path: str
|
||||||
|
"""
|
||||||
self.base_path = os.path.normpath(os.path.join(os.getcwd(), os.path.dirname(base_path)))
|
self.base_path = os.path.normpath(os.path.join(os.getcwd(), os.path.dirname(base_path)))
|
||||||
|
|
||||||
def __call__(self, relative_path='.'):
|
def __call__(self, relative_path='.'):
|
||||||
"""
|
"""
|
||||||
Returns the absolute path of the relative path
|
Returns the absolute path of the relative path
|
||||||
:param relative_path: Relative path to be resolved
|
:param relative_path: Relative path to be resolved
|
||||||
|
:type relative_path: str
|
||||||
:return: Absolute path
|
:return: Absolute path
|
||||||
"""
|
"""
|
||||||
return self.give_absolute(relative_path)
|
return self.give_absolute(relative_path)
|
||||||
|
|
@ -30,6 +36,7 @@ class PathResolver:
|
||||||
"""
|
"""
|
||||||
Returns the absolute path of the relative path
|
Returns the absolute path of the relative path
|
||||||
:param relative_path: Relative path to be resolved
|
:param relative_path: Relative path to be resolved
|
||||||
|
:type relative_path: str
|
||||||
:return: Absolute path
|
:return: Absolute path
|
||||||
"""
|
"""
|
||||||
return os.path.normpath(os.path.join(self.base_path, relative_path))
|
return os.path.normpath(os.path.join(self.base_path, relative_path))
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,21 @@
|
||||||
# Module for pre-parsing user files in preparation for the parser
|
"""Module for pre-parsing user files in preparation for the parser
|
||||||
# Usage:
|
Usage:
|
||||||
# from bootstraparse.modules.preparser import preparser
|
- from bootstraparse.modules.preparser import preparser
|
||||||
# pp = preparser(file, enviroment)
|
- pp = preparser(file, enviroment)
|
||||||
# pp.do_import() # imports all the modules and adds them to the file, do the same for all the files that are to be imported # noqa
|
- pp.do_import() # imports all the modules and adds them to the file, do the same for all the files that are to be imported - # noqa
|
||||||
# pp.do_replacements() # replaces all images and shortcuts in the file
|
- pp.do_replacements() # replaces all images and shortcuts in the file
|
||||||
# pp.readlines() # returns the lines of ORIGINAL file
|
- pp.readlines() # returns the lines of ORIGINAL file
|
||||||
# pp.get_all_lines() # returns the lines of the file after replacements and imports
|
- pp.get_all_lines() # returns the lines of the file after replacements and imports
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import regex # future: remove regex
|
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
|
||||||
from bootstraparse.modules import pathresolver as pr
|
from bootstraparse.modules import pathresolver as pr
|
||||||
from bootstraparse.modules import environment
|
from bootstraparse.modules import environment
|
||||||
from bootstraparse.modules import syntax
|
from bootstraparse.modules import syntax
|
||||||
from bootstraparse.modules import error_mngr # noqa # pylint: disable=unused-import
|
from bootstraparse.modules import error_mngr
|
||||||
from bootstraparse.modules import export
|
from bootstraparse.modules import export
|
||||||
|
|
||||||
import rich
|
import rich
|
||||||
|
|
@ -37,6 +37,10 @@ class PreParser:
|
||||||
:param _env: the environment object
|
:param _env: the environment object
|
||||||
:param list_of_paths: the list of files that have been imported in this branch of the import tree
|
:param list_of_paths: the list of files that have been imported in this branch of the import tree
|
||||||
:param dict_of_imports: Dictionary of all imports made to avoid duplicate file opening / pre-parsing
|
:param dict_of_imports: Dictionary of all imports made to avoid duplicate file opening / pre-parsing
|
||||||
|
:type file_path: str
|
||||||
|
:type _env: environment.Environment
|
||||||
|
:type list_of_paths: list[str]
|
||||||
|
:type dict_of_imports: dict[str, PreParser]
|
||||||
"""
|
"""
|
||||||
if list_of_paths is None:
|
if list_of_paths is None:
|
||||||
list_of_paths = []
|
list_of_paths = []
|
||||||
|
|
@ -75,7 +79,6 @@ class PreParser:
|
||||||
def make_temporary_files(self):
|
def make_temporary_files(self):
|
||||||
"""
|
"""
|
||||||
Creates temporary files for the import list and the replacement.
|
Creates temporary files for the import list and the replacement.
|
||||||
:return: None
|
|
||||||
"""
|
"""
|
||||||
self.file_with_all_imports = StringIO()
|
self.file_with_all_imports = StringIO()
|
||||||
self.file_with_all_replacements = StringIO()
|
self.file_with_all_replacements = StringIO()
|
||||||
|
|
@ -86,13 +89,14 @@ class PreParser:
|
||||||
"""
|
"""
|
||||||
Make new temporary files, if the old one are not referenced,
|
Make new temporary files, if the old one are not referenced,
|
||||||
the garbage collector will delete them.
|
the garbage collector will delete them.
|
||||||
:return: None
|
|
||||||
"""
|
"""
|
||||||
self.make_temporary_files()
|
self.make_temporary_files()
|
||||||
|
|
||||||
def do_imports(self):
|
def do_imports(self):
|
||||||
"""
|
"""
|
||||||
Execute all actions needed to do the imports and setup for the next step
|
Execute all actions needed to do the imports and setup for the next step
|
||||||
|
:return: The file descriptor of the file with all imports
|
||||||
|
:rtype: StringIO
|
||||||
"""
|
"""
|
||||||
self.parse_import_list()
|
self.parse_import_list()
|
||||||
self.make_import_list()
|
self.make_import_list()
|
||||||
|
|
@ -103,6 +107,8 @@ class PreParser:
|
||||||
def do_replacements(self):
|
def do_replacements(self):
|
||||||
"""
|
"""
|
||||||
Execute all actions needed to do the replacements.
|
Execute all actions needed to do the replacements.
|
||||||
|
:return: The file descriptor of the file with all replacements
|
||||||
|
:rtype: StringIO
|
||||||
"""
|
"""
|
||||||
self.do_imports()
|
self.do_imports()
|
||||||
self.parse_shortcuts_and_images()
|
self.parse_shortcuts_and_images()
|
||||||
|
|
@ -112,7 +118,8 @@ class PreParser:
|
||||||
def readlines(self):
|
def readlines(self):
|
||||||
"""
|
"""
|
||||||
Reads the original file and returns a list of lines.
|
Reads the original file and returns a list of lines.
|
||||||
:return: A list of lines
|
:return: a list of lines
|
||||||
|
:rtype: list[str]
|
||||||
"""
|
"""
|
||||||
with open(self.relative_path_resolver(self.name), 'r') as f:
|
with open(self.relative_path_resolver(self.name), 'r') as f:
|
||||||
return f.readlines()
|
return f.readlines()
|
||||||
|
|
@ -121,6 +128,7 @@ class PreParser:
|
||||||
"""
|
"""
|
||||||
Get the lines from the file on the step you are in
|
Get the lines from the file on the step you are in
|
||||||
:return: A list of lines
|
:return: A list of lines
|
||||||
|
:rtype: list[str]
|
||||||
"""
|
"""
|
||||||
if self.current_origin_for_read is None:
|
if self.current_origin_for_read is None:
|
||||||
return self.readlines()
|
return self.readlines()
|
||||||
|
|
@ -133,6 +141,7 @@ class PreParser:
|
||||||
Makes sure that the files are not already imported through a previous import statement.
|
Makes sure that the files are not already imported through a previous import statement.
|
||||||
Recursively build a list of PreParser object for each file to be imported.
|
Recursively build a list of PreParser object for each file to be imported.
|
||||||
:return: the dictionary of all files to be imported (key: file name, value: PreParser object)
|
:return: the dictionary of all files to be imported (key: file name, value: PreParser object)
|
||||||
|
:rtype: dict[str, PreParser]
|
||||||
"""
|
"""
|
||||||
import_list = self.parse_import_list()
|
import_list = self.parse_import_list()
|
||||||
if self.is_global_dict_of_imports_initialized:
|
if self.is_global_dict_of_imports_initialized:
|
||||||
|
|
@ -144,8 +153,7 @@ class PreParser:
|
||||||
RecursionError(f"Error: {e} was imported earlier in {self.list_of_paths}"), level='CRITICAL'
|
RecursionError(f"Error: {e} was imported earlier in {self.list_of_paths}"), level='CRITICAL'
|
||||||
)
|
)
|
||||||
if e in self.global_dict_of_imports:
|
if e in self.global_dict_of_imports:
|
||||||
pp = self.global_dict_of_imports[e]
|
self.local_dict_of_imports[e] = self.global_dict_of_imports[e]
|
||||||
self.local_dict_of_imports[e] = pp
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
pp = PreParser(e, self._env, self.list_of_paths.copy(), self.global_dict_of_imports)
|
pp = PreParser(e, self._env, self.list_of_paths.copy(), self.global_dict_of_imports)
|
||||||
|
|
@ -162,7 +170,8 @@ class PreParser:
|
||||||
def parse_import_list(self):
|
def parse_import_list(self):
|
||||||
"""
|
"""
|
||||||
Parses the import list of the file.
|
Parses the import list of the file.
|
||||||
:return: a list of files to be imported
|
:return: a list of files to be imported, and the line number of the import statement
|
||||||
|
:rtype: list[(str, int)]
|
||||||
"""
|
"""
|
||||||
if self.saved_import_list:
|
if self.saved_import_list:
|
||||||
return self.saved_import_list
|
return self.saved_import_list
|
||||||
|
|
@ -170,10 +179,10 @@ class PreParser:
|
||||||
line_count = 0
|
line_count = 0
|
||||||
|
|
||||||
for line in self.readlines():
|
for line in self.readlines():
|
||||||
results = regex.match(_rgx_import_file, line)
|
results = _rgx_import_file.searchString(line)
|
||||||
if results:
|
if results:
|
||||||
for e in results.captures('file_name'):
|
for e in results[0]:
|
||||||
import_list += [(e, line_count)]
|
import_list += [(e.rstrip(), line_count)]
|
||||||
line_count += 1
|
line_count += 1
|
||||||
# converts relative paths to absolute and returns a table
|
# converts relative paths to absolute and returns a table
|
||||||
self.saved_import_list = [(self.relative_path_resolver(p), l) for p, l in import_list]
|
self.saved_import_list = [(self.relative_path_resolver(p), l) for p, l in import_list]
|
||||||
|
|
@ -183,6 +192,7 @@ class PreParser:
|
||||||
"""
|
"""
|
||||||
Return the file object with all file imports done
|
Return the file object with all file imports done
|
||||||
:return: a filelike object with all file imports done
|
:return: a filelike object with all file imports done
|
||||||
|
:rtype: StringIO
|
||||||
"""
|
"""
|
||||||
self.make_import_list()
|
self.make_import_list()
|
||||||
|
|
||||||
|
|
@ -202,9 +212,9 @@ class PreParser:
|
||||||
import_list = self.parse_import_list()
|
import_list = self.parse_import_list()
|
||||||
source_lines = self.readlines()
|
source_lines = self.readlines()
|
||||||
for import_path, import_line in import_list:
|
for import_path, import_line in import_list:
|
||||||
source_lines[import_line] = ""
|
source_lines[import_line] = "" # remove the line where the import was
|
||||||
temp_file.writelines(source_lines[source_line_count:import_line])
|
temp_file.writelines(source_lines[source_line_count:import_line]) # copy origin to destination
|
||||||
source_line_count = import_line
|
source_line_count = import_line # update origin for next import
|
||||||
import_file = self.global_dict_of_imports[import_path].export_with_imports()
|
import_file = self.global_dict_of_imports[import_path].export_with_imports()
|
||||||
temp_file.writelines(import_file.readlines())
|
temp_file.writelines(import_file.readlines())
|
||||||
temp_file.writelines(source_lines[source_line_count:])
|
temp_file.writelines(source_lines[source_line_count:])
|
||||||
|
|
@ -217,7 +227,8 @@ class PreParser:
|
||||||
"""
|
"""
|
||||||
Parses through the output files from export_with_imports
|
Parses through the output files from export_with_imports
|
||||||
and replaces shortcuts and images calls with appropriate html
|
and replaces shortcuts and images calls with appropriate html
|
||||||
:return: a table of occurrences and their lines
|
:return: The file descriptor of the file with all replacements
|
||||||
|
:rtype: StringIO
|
||||||
"""
|
"""
|
||||||
temp_file = self.file_with_all_imports
|
temp_file = self.file_with_all_imports
|
||||||
temp_text = ''
|
temp_text = ''
|
||||||
|
|
@ -238,7 +249,10 @@ class PreParser:
|
||||||
|
|
||||||
def get_element_from_config(self, *list_keys):
|
def get_element_from_config(self, *list_keys):
|
||||||
"""
|
"""
|
||||||
Fetches an element from the config
|
Fetches an element from the config (a nested dictionary) going through the list of keys
|
||||||
|
Raises an error if the element is not found
|
||||||
|
:param list_keys: the list of keys to go through the config
|
||||||
|
:type list_keys: str
|
||||||
"""
|
"""
|
||||||
sub_dict = self._env.config.loaded_conf
|
sub_dict = self._env.config.loaded_conf
|
||||||
validated_elements = []
|
validated_elements = []
|
||||||
|
|
@ -258,6 +272,12 @@ class PreParser:
|
||||||
def make_replacements(message, *var_list, **var_dict):
|
def make_replacements(message, *var_list, **var_dict):
|
||||||
"""
|
"""
|
||||||
Tries to format the message or give an error message and return the original message
|
Tries to format the message or give an error message and return the original message
|
||||||
|
:param message: the message to format
|
||||||
|
:type message: str
|
||||||
|
:param var_list: the list of variables to replace in the message
|
||||||
|
:type var_list: str
|
||||||
|
:keyword var_dict: the dictionary of variables to replace in the message
|
||||||
|
:type var_dict: dict[str, str]
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return message.format(*var_list, **var_dict)
|
return message.format(*var_list, **var_dict)
|
||||||
|
|
@ -271,10 +291,13 @@ class PreParser:
|
||||||
|
|
||||||
def get_alias_from_config(self, shortcut, optionals):
|
def get_alias_from_config(self, shortcut, optionals):
|
||||||
"""
|
"""
|
||||||
Fetches shortcut paths from aliases.yaml
|
Returns the alias from the config and makes the replacements with the options provided
|
||||||
:return: the html to insert as a string
|
|
||||||
:param shortcut: id of the shortcut to fetch
|
:param shortcut: id of the shortcut to fetch
|
||||||
|
:type shortcut: str
|
||||||
:param optionals: optional parameters along with alias
|
:param optionals: optional parameters along with alias
|
||||||
|
:type optionals: syntax.Optional
|
||||||
|
:return: the html to insert as a string
|
||||||
|
:rtype: str
|
||||||
"""
|
"""
|
||||||
output = self.get_element_from_config('aliases', 'shortcuts', shortcut)
|
output = self.get_element_from_config('aliases', 'shortcuts', shortcut)
|
||||||
_, _, var_list, var_dict = syntax.split_optionals(optionals)
|
_, _, var_list, var_dict = syntax.split_optionals(optionals)
|
||||||
|
|
@ -283,10 +306,12 @@ class PreParser:
|
||||||
|
|
||||||
def get_image_from_config(self, shortcut, optionals):
|
def get_image_from_config(self, shortcut, optionals):
|
||||||
"""
|
"""
|
||||||
Fetches image paths from aliases.yaml
|
Returns the image from the config and makes the replacements with the options provided
|
||||||
:return: html to insert as a string
|
:param shortcut: id of the image to fetch
|
||||||
:param shortcut: the id of the picture to fetch
|
:type shortcut: str
|
||||||
:param optionals: optional parameters along with image
|
:param optionals: optional parameters along with image
|
||||||
|
:type optionals: syntax.Optional
|
||||||
|
:return: the html to insert as a string
|
||||||
"""
|
"""
|
||||||
shortcut_s = self.get_element_from_config('aliases', 'images', shortcut)
|
shortcut_s = self.get_element_from_config('aliases', 'images', shortcut)
|
||||||
|
|
||||||
|
|
@ -299,7 +324,6 @@ class PreParser:
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
"""
|
"""
|
||||||
Returns a string representation of the PreParser object.
|
Returns a string representation of the PreParser object.
|
||||||
:return: a string representation of the PreParser object
|
|
||||||
"""
|
"""
|
||||||
return "PreParser[{}](path={}, name={}, base_path={}, " \
|
return "PreParser[{}](path={}, name={}, base_path={}, " \
|
||||||
"relative_path_resolver={}, list_of_paths={}, " \
|
"relative_path_resolver={}, list_of_paths={}, " \
|
||||||
|
|
@ -311,7 +335,6 @@ class PreParser:
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""
|
"""
|
||||||
Returns a string representation of the PreParser object.
|
Returns a string representation of the PreParser object.
|
||||||
:return: a string representation of the PreParser object
|
|
||||||
"""
|
"""
|
||||||
return self.__repr__()
|
return self.__repr__()
|
||||||
|
|
||||||
|
|
@ -334,6 +357,7 @@ class PreParser:
|
||||||
"""
|
"""
|
||||||
Checks if the PreParser object is not equal to another PreParser object.
|
Checks if the PreParser object is not equal to another PreParser object.
|
||||||
:param other: the other PreParser object
|
:param other: the other PreParser object
|
||||||
|
:type other: PreParser
|
||||||
:return: True if the PreParser objects are not equal, False otherwise
|
:return: True if the PreParser objects are not equal, False otherwise
|
||||||
"""
|
"""
|
||||||
return not self.__eq__(other)
|
return not self.__eq__(other)
|
||||||
|
|
@ -341,6 +365,14 @@ class PreParser:
|
||||||
def rich_tree(self, prefix="", suffix="", force=True, strip_prefix=""):
|
def rich_tree(self, prefix="", suffix="", force=True, strip_prefix=""):
|
||||||
"""
|
"""
|
||||||
Returns a rich representation of the PreParser object.
|
Returns a rich representation of the PreParser object.
|
||||||
|
:param prefix: the prefix to add to the representation
|
||||||
|
:type prefix: str
|
||||||
|
:param suffix: the suffix to add to the representation
|
||||||
|
:type suffix: str
|
||||||
|
:param force: if True, the representation is always computed, even if it has already been done
|
||||||
|
:type force: bool
|
||||||
|
:param strip_prefix: the prefix to remove from the path
|
||||||
|
:type strip_prefix: str
|
||||||
:return: a rich representation of the PreParser object
|
:return: a rich representation of the PreParser object
|
||||||
"""
|
"""
|
||||||
unparsed = False
|
unparsed = False
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,36 @@
|
||||||
# Module for file and directories repartition
|
"""
|
||||||
|
Module for file and directories repartition
|
||||||
|
Usage:
|
||||||
|
- from bootstraparse.modules import SiteCrawler
|
||||||
|
- crawler = SiteCrawler(origin_path, dest_path, _env)
|
||||||
|
- crawler.set_all_preparsers()
|
||||||
|
- crawler.copy_unparsable_files()
|
||||||
|
- for element, destination in crawler:
|
||||||
|
- - save(preparse_parse(element), destination, _env)
|
||||||
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
from bootstraparse.modules import pathresolver, preparser, error_mngr, environment, export
|
from bootstraparse.modules import pathresolver, preparser, error_mngr, environment, export
|
||||||
|
|
||||||
|
|
||||||
class SiteCrawler:
|
class SiteCrawler:
|
||||||
|
"""
|
||||||
|
A sitecrawler is a generator that yields a tuple of the form (PreParser, file)
|
||||||
|
Its goal is to create a list of preparsers and files to be parsed based on
|
||||||
|
the files and directories in the initial path.
|
||||||
|
This generator is to be used in a for loop to parse all the files and produce
|
||||||
|
the final website.
|
||||||
|
"""
|
||||||
def __init__(self, path, destination, _env):
|
def __init__(self, path, destination, _env):
|
||||||
|
"""
|
||||||
|
:param path: The path to the directory to be crawled
|
||||||
|
:param destination: The path to the directory where the website will be created
|
||||||
|
:param _env: The environment object
|
||||||
|
:type path: str
|
||||||
|
:type destination: str
|
||||||
|
:type _env: environment.Environment
|
||||||
|
"""
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
error_mngr.log_exception(
|
error_mngr.log_exception(
|
||||||
FileNotFoundError(f'The specified path "{path}" could not be found.'),
|
FileNotFoundError(f'The specified path "{path}" could not be found.'),
|
||||||
|
|
@ -20,6 +46,7 @@ class SiteCrawler:
|
||||||
self.force_rewrite = self._env.config["parser_config"]["export"]["force_rewrite"]
|
self.force_rewrite = self._env.config["parser_config"]["export"]["force_rewrite"]
|
||||||
self.directories = []
|
self.directories = []
|
||||||
self.files = []
|
self.files = []
|
||||||
|
self.files_to_copy = []
|
||||||
self.preparsers = []
|
self.preparsers = []
|
||||||
self.global_dict_of_imports = {}
|
self.global_dict_of_imports = {}
|
||||||
|
|
||||||
|
|
@ -32,26 +59,48 @@ class SiteCrawler:
|
||||||
self.create_all_paths()
|
self.create_all_paths()
|
||||||
|
|
||||||
def get_all_paths(self):
|
def get_all_paths(self):
|
||||||
self.files, self.directories = self.list_recursively(self.initial_path, self.initial_path)
|
"""
|
||||||
|
This method is used to get all the paths to be crawled.
|
||||||
|
Its goal is to get all the paths to be crawled and to store them in
|
||||||
|
the self.directories and self.files, self.files_to_copy variables.
|
||||||
|
"""
|
||||||
|
self.files, self.files_to_copy, self.directories = self.list_recursively(self.initial_path, self.initial_path)
|
||||||
|
|
||||||
def list_recursively(self, path, root):
|
def list_recursively(self, path, root):
|
||||||
|
"""
|
||||||
|
Recursive method to get all the paths to be crawled.
|
||||||
|
:param path: The current path to be crawled
|
||||||
|
:param root: The root path (initial path)
|
||||||
|
:type path: str
|
||||||
|
:type root: str
|
||||||
|
:return: A tuple of the form (files, directories)
|
||||||
|
:rtype: (list[(str, str)], list[(str, str)], list[(str, str)])
|
||||||
|
"""
|
||||||
files = []
|
files = []
|
||||||
directories = []
|
directories = []
|
||||||
|
files_to_copy = []
|
||||||
for element in os.listdir(path):
|
for element in os.listdir(path):
|
||||||
element_fpath = os.path.join(path, element)
|
element_fpath = os.path.join(path, element)
|
||||||
element_rpath = os.path.relpath(path, root)
|
element_rpath = os.path.relpath(path, root)
|
||||||
if os.path.isdir(element_fpath):
|
if os.path.isdir(element_fpath):
|
||||||
if element not in self.forbidden_folders:
|
if element not in self.forbidden_folders:
|
||||||
directories.append((element_rpath, element))
|
directories.append((element_rpath, element))
|
||||||
f, d = self.list_recursively(element_fpath, root)
|
f, fc, d = self.list_recursively(element_fpath, root)
|
||||||
files += f
|
files += f
|
||||||
directories += d
|
directories += d
|
||||||
|
files_to_copy += fc
|
||||||
else:
|
else:
|
||||||
if os.path.splitext(element)[1] in self.authorised_extensions and element[0] != "_":
|
if element[0] != "_":
|
||||||
|
if os.path.splitext(element)[1] in self.authorised_extensions:
|
||||||
files.append((element_rpath, element))
|
files.append((element_rpath, element))
|
||||||
return files, directories
|
else:
|
||||||
|
files_to_copy.append((element_rpath, element))
|
||||||
|
return files, files_to_copy, directories
|
||||||
|
|
||||||
def create_all_paths(self):
|
def create_all_paths(self):
|
||||||
|
"""
|
||||||
|
This method is used to create all the directories in the destination path.
|
||||||
|
"""
|
||||||
if not os.path.exists(self.destination_path):
|
if not os.path.exists(self.destination_path):
|
||||||
os.mkdir(self.destination_path)
|
os.mkdir(self.destination_path)
|
||||||
for root, di in self.directories:
|
for root, di in self.directories:
|
||||||
|
|
@ -60,6 +109,12 @@ class SiteCrawler:
|
||||||
os.mkdir(temp_path)
|
os.mkdir(temp_path)
|
||||||
|
|
||||||
def set_all_preparsers(self):
|
def set_all_preparsers(self):
|
||||||
|
"""
|
||||||
|
This method is used to set all the preparsers and initialize them.
|
||||||
|
The preparsers are stored in the self.preparsers variable.
|
||||||
|
:return: self.preparsers
|
||||||
|
:rtype: list[preparser.PreParser]
|
||||||
|
"""
|
||||||
for root, file in self.files:
|
for root, file in self.files:
|
||||||
preparser_path = os.path.join(self.initial_path, root, file)
|
preparser_path = os.path.join(self.initial_path, root, file)
|
||||||
pp = preparser.PreParser(preparser_path, self._env, dict_of_imports=self.global_dict_of_imports)
|
pp = preparser.PreParser(preparser_path, self._env, dict_of_imports=self.global_dict_of_imports)
|
||||||
|
|
@ -69,7 +124,21 @@ class SiteCrawler:
|
||||||
|
|
||||||
return self.preparsers
|
return self.preparsers
|
||||||
|
|
||||||
|
def copy_unparsable_files(self):
|
||||||
|
"""
|
||||||
|
This method is used to copy all the files that could not be parsed.
|
||||||
|
"""
|
||||||
|
if self._env.config["parser_config"]["export"]["copy_unparsable_files"].lower() == "copy":
|
||||||
|
for root, file in self.files_to_copy:
|
||||||
|
shutil.copy(os.path.join(self.initial_path, root, file), os.path.join(self.destination_path, root, file))
|
||||||
|
|
||||||
def create_file(self, path):
|
def create_file(self, path):
|
||||||
|
"""
|
||||||
|
This method is used to create a file.
|
||||||
|
:raises FileExistsError: If the file already exists and the force_rewrite option is False
|
||||||
|
:param path: The path to the file to be created
|
||||||
|
:type path: str
|
||||||
|
"""
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
if not self.force_rewrite:
|
if not self.force_rewrite:
|
||||||
error_mngr.log_exception(
|
error_mngr.log_exception(
|
||||||
|
|
@ -81,6 +150,11 @@ class SiteCrawler:
|
||||||
return path
|
return path
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
|
"""
|
||||||
|
This method is used to iterate over the preparsers and files.
|
||||||
|
:yield: A tuple of the form (PreParser, file)
|
||||||
|
:ytype: (preparser.PreParser, str)
|
||||||
|
"""
|
||||||
for pre in self.preparsers:
|
for pre in self.preparsers:
|
||||||
yield pre
|
yield pre
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,9 @@
|
||||||
# Module sequencing the successive actions necessary for website building
|
"""
|
||||||
|
Module sequencing the successive actions necessary for website building
|
||||||
|
Usage:
|
||||||
|
- create_website(origin, destination)
|
||||||
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from bootstraparse.modules import pathresolver, sitecrawler, environment, config, export, parser, context_mngr
|
from bootstraparse.modules import pathresolver, sitecrawler, environment, config, export, parser, context_mngr
|
||||||
|
|
@ -8,10 +13,16 @@ def create_website(origin, destination):
|
||||||
"""
|
"""
|
||||||
First function called by bparse.py,
|
First function called by bparse.py,
|
||||||
calls all other modules in the right order.
|
calls all other modules in the right order.
|
||||||
|
:param origin: The path of the website to be built.
|
||||||
|
:param destination: The destination path of the built website.
|
||||||
|
:type origin: str
|
||||||
|
:type destination: str
|
||||||
|
:return: 0 if everything went well, 1 otherwise.
|
||||||
"""
|
"""
|
||||||
env = create_environment(origin, destination)
|
env = create_environment(origin, destination)
|
||||||
crwlr = create_crawler(origin, destination, env)
|
crwlr = create_crawler(origin, destination, env)
|
||||||
crwlr.set_all_preparsers()
|
crwlr.set_all_preparsers()
|
||||||
|
crwlr.copy_unparsable_files()
|
||||||
for element, destination in crwlr:
|
for element, destination in crwlr:
|
||||||
save(preparse_parse(element), destination, env)
|
save(preparse_parse(element), destination, env)
|
||||||
|
|
||||||
|
|
@ -22,6 +33,12 @@ def create_environment(origin, destination):
|
||||||
"""
|
"""
|
||||||
Returns parserEnvironment as an object containing
|
Returns parserEnvironment as an object containing
|
||||||
everything needed for app execution.
|
everything needed for app execution.
|
||||||
|
:param origin: The path of the website to be built.
|
||||||
|
:param destination: The destination path of the built website.
|
||||||
|
:type origin: str
|
||||||
|
:type destination: str
|
||||||
|
:return: Environment object.
|
||||||
|
:rtype: environment.Environment
|
||||||
"""
|
"""
|
||||||
env = environment.Environment()
|
env = environment.Environment()
|
||||||
env.config = config.ConfigLoader(pathresolver.b_path("configs"))
|
env.config = config.ConfigLoader(pathresolver.b_path("configs"))
|
||||||
|
|
@ -42,11 +59,26 @@ def create_environment(origin, destination):
|
||||||
def create_crawler(origin, destination, _env):
|
def create_crawler(origin, destination, _env):
|
||||||
"""
|
"""
|
||||||
Returns crawler as an object for navigation in the user files.
|
Returns crawler as an object for navigation in the user files.
|
||||||
|
:param origin: The path of the website to be built.
|
||||||
|
:param destination: The destination path of the built website.
|
||||||
|
:param _env: The environment object.
|
||||||
|
:type origin: str
|
||||||
|
:type destination: str
|
||||||
|
:type _env: environment.Environment
|
||||||
|
:return: Crawler object.
|
||||||
|
:rtype: sitecrawler.SiteCrawler
|
||||||
"""
|
"""
|
||||||
return sitecrawler.SiteCrawler(origin, destination, _env)
|
return sitecrawler.SiteCrawler(origin, destination, _env)
|
||||||
|
|
||||||
|
|
||||||
def preparse_parse(preparser):
|
def preparse_parse(preparser):
|
||||||
|
"""
|
||||||
|
Returns a list of containers from a preparser.
|
||||||
|
:param preparser: The preparser object.
|
||||||
|
:type preparser: parser.Preparser
|
||||||
|
:return: List of containers.
|
||||||
|
:rtype: list
|
||||||
|
"""
|
||||||
io = preparser.do_replacements()
|
io = preparser.do_replacements()
|
||||||
parsed_list = parser.parse_line(io)
|
parsed_list = parser.parse_line(io)
|
||||||
output = context_mngr.ContextManager(parsed_list, name=preparser.name)()
|
output = context_mngr.ContextManager(parsed_list, name=preparser.name)()
|
||||||
|
|
@ -54,6 +86,15 @@ def preparse_parse(preparser):
|
||||||
|
|
||||||
|
|
||||||
def save(list_of_containers, destination, env):
|
def save(list_of_containers, destination, env):
|
||||||
|
"""
|
||||||
|
Saves the list of containers in the destination path.
|
||||||
|
:param list_of_containers: The list of containers to be saved.
|
||||||
|
:param destination: The destination path.
|
||||||
|
:param env: The environment object.
|
||||||
|
:type list_of_containers: list
|
||||||
|
:type destination: str
|
||||||
|
:type env: environment.Environment
|
||||||
|
"""
|
||||||
with open(destination, "w") as output_file:
|
with open(destination, "w") as output_file:
|
||||||
output_file.write(export.ContextConverter(list_of_containers, env.export_mngr, destination).process_pile().read())
|
output_file.write(export.ContextConverter(list_of_containers, env.export_mngr, destination).process_pile().read())
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
"""
|
||||||
# Dedicated module for the syntax of all the parsing
|
# Dedicated module for the syntax of all the parsing
|
||||||
# All tokens inherit a SemanticType among SemanticType, ExplicitSemanticType and EmptySemanticType
|
# All tokens inherit a SemanticType among SemanticType, ExplicitSemanticType and EmptySemanticType
|
||||||
# All tokens have a label, and __eq__ and __ne__ methods.
|
# All tokens have a label, and __eq__ and __ne__ methods.
|
||||||
|
|
@ -8,6 +9,7 @@
|
||||||
# line_to_replace.parse_line('string') # returns a List of tokens parsed for replacements
|
# line_to_replace.parse_line('string') # returns a List of tokens parsed for replacements
|
||||||
# imports.parse_line('string', True) # returns a List of tokens parsed for imports
|
# imports.parse_line('string', True) # returns a List of tokens parsed for imports
|
||||||
# any_token.create_diagram("filename") # Debugging
|
# any_token.create_diagram("filename") # Debugging
|
||||||
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from itertools import zip_longest
|
from itertools import zip_longest
|
||||||
|
|
@ -16,7 +18,6 @@ from collections import namedtuple
|
||||||
from bootstraparse.modules.error_mngr import MismatchedContainerError
|
from bootstraparse.modules.error_mngr import MismatchedContainerError
|
||||||
from bootstraparse.modules import context_mngr as cm
|
from bootstraparse.modules import context_mngr as cm
|
||||||
import pyparsing as pp
|
import pyparsing as pp
|
||||||
import regex # future: remove regex
|
|
||||||
|
|
||||||
pps = pp.Suppress
|
pps = pp.Suppress
|
||||||
|
|
||||||
|
|
@ -29,6 +30,11 @@ class SemanticType:
|
||||||
label = None
|
label = None
|
||||||
|
|
||||||
def __init__(self, content):
|
def __init__(self, content):
|
||||||
|
"""
|
||||||
|
Initialises the token.
|
||||||
|
:param content: The content of the token.
|
||||||
|
:type content: list[pp.ParseResults]
|
||||||
|
"""
|
||||||
self.content = content
|
self.content = content
|
||||||
self.line_number = "Undefined"
|
self.line_number = "Undefined"
|
||||||
self.file_name = "Undefined"
|
self.file_name = "Undefined"
|
||||||
|
|
@ -37,6 +43,8 @@ class SemanticType:
|
||||||
def to_markup(self):
|
def to_markup(self):
|
||||||
"""
|
"""
|
||||||
Function used for testing and readability purposes. Replaces matched markup with html-like tags.
|
Function used for testing and readability purposes. Replaces matched markup with html-like tags.
|
||||||
|
:return: The markup of the token.
|
||||||
|
:rtype: str
|
||||||
"""
|
"""
|
||||||
if self.content:
|
if self.content:
|
||||||
return_list = []
|
return_list = []
|
||||||
|
|
@ -51,6 +59,8 @@ class SemanticType:
|
||||||
def to_original(self):
|
def to_original(self):
|
||||||
"""
|
"""
|
||||||
Return the original string of the token.
|
Return the original string of the token.
|
||||||
|
:return: The original string of the token.
|
||||||
|
:rtype: str
|
||||||
"""
|
"""
|
||||||
return " ".join(self.content)
|
return " ".join(self.content)
|
||||||
|
|
||||||
|
|
@ -79,36 +89,40 @@ class SemanticType:
|
||||||
return not self.__eq__(other)
|
return not self.__eq__(other)
|
||||||
|
|
||||||
def counterpart(self): # noqa # FUTURE: Check for static counterpart implementation
|
def counterpart(self): # noqa # FUTURE: Check for static counterpart implementation
|
||||||
|
"""
|
||||||
|
Function called by the context manager to know how to deal with the encapsulation of the token.
|
||||||
|
Will return the counterpart of the token (the previous token to look for).
|
||||||
|
:return: The counterpart of the token.
|
||||||
|
:rtype: str | None
|
||||||
|
"""
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def to_container(self, filter_func=None):
|
def to_container(self, filter_func=None):
|
||||||
"""
|
"""
|
||||||
Function called by the context manager to know how to deal with the encapsulation of the token.
|
Function called by the context manager to know how to deal with the encapsulation of the token.
|
||||||
|
:param filter_func: A function that will be used to filter the content of the token.
|
||||||
Parameters
|
:type filter_func: (callable| None)
|
||||||
----------
|
:return: Self if containable, the expected replacement token if it can, raises an error otherwise.
|
||||||
filter_func: (function | None)
|
:rtype: SemanticType | context_mngr.BaseContainer
|
||||||
A function that takes a token and returns a boolean. If the token is not valid, it should return False.
|
:raises CannotBeContainedError: Raises error if the token we were trying to encapsulate cannot be (probably mismatched).
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
SemanticType
|
|
||||||
Self if containable, the expected replacement token if it can, raises an error otherwise.
|
|
||||||
Raises
|
|
||||||
------
|
|
||||||
CannotBeContainedError
|
|
||||||
Raises error if the token we were trying to encapsulate cannot be (probably mismatched).
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
raise MismatchedContainerError(self)
|
raise MismatchedContainerError(self)
|
||||||
|
|
||||||
|
|
||||||
class TokensToMatch:
|
class TokensToMatch(SemanticType):
|
||||||
"""Class used for verification in the context manager.
|
"""
|
||||||
Classes inheriting this should be added to matched_elements."""
|
Class used for verification in the context manager.
|
||||||
|
Classes inheriting this should be added to matched_elements.
|
||||||
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class AddFirstElementToLabel(SemanticType):
|
class AddFirstElementToLabel(SemanticType):
|
||||||
|
"""
|
||||||
|
Class used for verification in the context manager.
|
||||||
|
Adds the first element of the content to the label (for matching purposes).
|
||||||
|
"""
|
||||||
def __init__(self, content):
|
def __init__(self, content):
|
||||||
super().__init__(content)
|
super().__init__(content)
|
||||||
self.label += ":" + content[0]
|
self.label += ":" + content[0]
|
||||||
|
|
@ -247,12 +261,12 @@ class DisplayToken(FinalSemanticType):
|
||||||
|
|
||||||
|
|
||||||
class StructuralElementStartToken(AddFirstElementToLabel, OpenedSemanticType, TokensToMatch):
|
class StructuralElementStartToken(AddFirstElementToLabel, OpenedSemanticType, TokensToMatch):
|
||||||
"""<<div|article|section|aside"""
|
"""<<div|article|section|aside|header|body|nav"""
|
||||||
label = 'se:start'
|
label = 'se:start'
|
||||||
|
|
||||||
|
|
||||||
class StructuralElementEndToken(AddFirstElementToLabel, ClosedSemanticType):
|
class StructuralElementEndToken(AddFirstElementToLabel, ClosedSemanticType):
|
||||||
"""div|article|section|aside>>"""
|
"""div|article|section|aside|header|body|nav>>"""
|
||||||
label = "se:end"
|
label = "se:end"
|
||||||
|
|
||||||
def counterpart(self):
|
def counterpart(self):
|
||||||
|
|
@ -330,7 +344,9 @@ def of_type(token_class):
|
||||||
"""
|
"""
|
||||||
Function creating a custom function for generating the given Token type.
|
Function creating a custom function for generating the given Token type.
|
||||||
:param token_class: SemanticType class
|
:param token_class: SemanticType class
|
||||||
|
:type token_class: type
|
||||||
:return: returns a function creating an instance of the given class
|
:return: returns a function creating an instance of the given class
|
||||||
|
:rtype: function
|
||||||
"""
|
"""
|
||||||
def _of_type(_, __, content):
|
def _of_type(_, __, content):
|
||||||
if len(content) == 0: # Drop Empty token
|
if len(content) == 0: # Drop Empty token
|
||||||
|
|
@ -344,7 +360,9 @@ def reparse(parse_element):
|
||||||
"""
|
"""
|
||||||
Creates a function which reparses given match with specified parsing element.
|
Creates a function which reparses given match with specified parsing element.
|
||||||
:param parse_element: pp object defining desired match
|
:param parse_element: pp object defining desired match
|
||||||
|
:type parse_element: pp.ParserElement
|
||||||
:return: returns a function parsing given match with specified parsing element
|
:return: returns a function parsing given match with specified parsing element
|
||||||
|
:rtype: function
|
||||||
"""
|
"""
|
||||||
def _reparse(__, _, tokens):
|
def _reparse(__, _, tokens):
|
||||||
return parse_element.parseString(tokens[0]) # Future: document this behaviour more in-depth
|
return parse_element.parseString(tokens[0]) # Future: document this behaviour more in-depth
|
||||||
|
|
@ -392,6 +410,7 @@ def readable_markup(list_of_tokens):
|
||||||
"""
|
"""
|
||||||
Function used for testing and readability purposes. Replaces matched markup with html-like tags.
|
Function used for testing and readability purposes. Replaces matched markup with html-like tags.
|
||||||
:param list_of_tokens: list of matched markup tokens in analysed text.
|
:param list_of_tokens: list of matched markup tokens in analysed text.
|
||||||
|
:type list_of_tokens: list
|
||||||
:return: returns readable string.
|
:return: returns readable string.
|
||||||
:rtype: string
|
:rtype: string
|
||||||
"""
|
"""
|
||||||
|
|
@ -408,8 +427,7 @@ def readable_markup(list_of_tokens):
|
||||||
|
|
||||||
|
|
||||||
# Pre-parser expressions
|
# Pre-parser expressions
|
||||||
rgx_import_file = regex.compile(r'::( ?\< ?(?P<file_name>[\w\-._/]+) ?\>[ \s]*)+')
|
rgx_import_file = pps("::") + pp.OneOrMore(pps("<") + pp.SkipTo(">").set_name("file_name")("file_name") + pps(">"))
|
||||||
|
|
||||||
|
|
||||||
# Base elements
|
# Base elements
|
||||||
quotes = pp.Word(r""""'""")
|
quotes = pp.Word(r""""'""")
|
||||||
|
|
@ -446,7 +464,10 @@ structural_elements = (
|
||||||
pp.CaselessLiteral('div') |
|
pp.CaselessLiteral('div') |
|
||||||
pp.CaselessLiteral('article') |
|
pp.CaselessLiteral('article') |
|
||||||
pp.CaselessLiteral('aside') |
|
pp.CaselessLiteral('aside') |
|
||||||
pp.CaselessLiteral('section')
|
pp.CaselessLiteral('section') |
|
||||||
|
pp.CaselessLiteral('header') |
|
||||||
|
pp.CaselessLiteral('body') |
|
||||||
|
pp.CaselessLiteral('nav')
|
||||||
)('structural_element')
|
)('structural_element')
|
||||||
header_element = pp.Word('#')
|
header_element = pp.Word('#')
|
||||||
display_element = pp.Word('!')
|
display_element = pp.Word('!')
|
||||||
|
|
@ -501,22 +522,20 @@ multi_line = se | table | quotation
|
||||||
one_header = (
|
one_header = (
|
||||||
header_element +
|
header_element +
|
||||||
pp.SkipTo(pp.match_previous_literal(header_element)) +
|
pp.SkipTo(pp.match_previous_literal(header_element)) +
|
||||||
pps(pp.match_previous_literal(header_element)) +
|
pps(pp.match_previous_literal(header_element))
|
||||||
pp.Opt(optional)
|
).add_parse_action(of_type(HeaderToken)) + pp.Opt(optional)
|
||||||
).add_parse_action(of_type(HeaderToken))
|
|
||||||
one_display = (
|
one_display = (
|
||||||
display_element +
|
display_element +
|
||||||
pp.SkipTo(pp.match_previous_literal(display_element)) +
|
pp.SkipTo(pp.match_previous_literal(display_element)) +
|
||||||
pps(pp.match_previous_literal(display_element)) +
|
pps(pp.match_previous_literal(display_element))
|
||||||
pp.Opt(optional)
|
).add_parse_action(of_type(DisplayToken)) + pp.Opt(optional)
|
||||||
).add_parse_action(of_type(DisplayToken))
|
|
||||||
one_olist = pp.line_start + (
|
one_olist = pp.line_start + (
|
||||||
pps(pp.Literal('#.')) + (
|
pps(pp.Combine(pp.line_start + pp.Literal('#.'))) + (
|
||||||
(pp.SkipTo(optional)('text').add_parse_action(reparse(enhanced_text)) + optional) |
|
(pp.SkipTo(optional)('text').add_parse_action(reparse(enhanced_text)) + optional) |
|
||||||
enhanced_text)
|
enhanced_text)
|
||||||
).add_parse_action(of_type(EtOlistToken))
|
).add_parse_action(of_type(EtOlistToken))
|
||||||
one_ulist = pp.line_start + (
|
one_ulist = pp.line_start + (
|
||||||
pps(pp.Literal('-')) + (
|
pps(pp.Combine(pp.line_start + pp.Literal('-'))) + (
|
||||||
(pp.SkipTo(optional)('text').add_parse_action(reparse(enhanced_text)) + optional) |
|
(pp.SkipTo(optional)('text').add_parse_action(reparse(enhanced_text)) + optional) |
|
||||||
enhanced_text)
|
enhanced_text)
|
||||||
).add_parse_action(of_type(EtUlistToken))
|
).add_parse_action(of_type(EtUlistToken))
|
||||||
|
|
@ -538,10 +557,9 @@ alias = alias_element + pp.Opt(optional)
|
||||||
|
|
||||||
# Syntax elements
|
# Syntax elements
|
||||||
line_to_replace = pp.OneOrMore(
|
line_to_replace = pp.OneOrMore(
|
||||||
pp.SkipTo(image ^ alias)('text').add_parse_action(of_type(TextToken))
|
pp.SkipTo(image)('text').add_parse_action(of_type(TextToken)) + image.add_parse_action(of_type(ImageToken)) |
|
||||||
^ image.add_parse_action(of_type(ImageToken))
|
pp.SkipTo(alias)('text').add_parse_action(of_type(TextToken)) + alias.add_parse_action(of_type(AliasToken))
|
||||||
^ alias.add_parse_action(of_type(AliasToken))
|
) | pp.rest_of_line('text').add_parse_action(of_type(TextToken))
|
||||||
) ^ pp.rest_of_line('text').add_parse_action(of_type(TextToken))
|
|
||||||
|
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
|
||||||
|
|
@ -1 +1,3 @@
|
||||||
# Module for interpreting default or custom templates.
|
"""
|
||||||
|
Module for interpreting default or custom templates.
|
||||||
|
"""
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,58 @@
|
||||||
###############################################################################
|
"""
|
||||||
# List of tools for testing
|
List of tools for testing
|
||||||
###############################################################################
|
=========================
|
||||||
# Usage:
|
|
||||||
# from bootstraparse.modules.tools import __GLk, __GL, find_*_in_file
|
Usage:
|
||||||
# __GLk(n) # Returns a file link n traceback objects back
|
- from bootstraparse.modules.tools import __GLk, __GL, find_*_in_file
|
||||||
# __GL() # Returns a line number at current position
|
- __GLk(n) # Returns a file link n traceback objects back
|
||||||
# find_*_in_file(file) # Try to find (class, function or variable) in file and return its line number
|
- __GL() # Returns a line number at current position
|
||||||
|
- find_*_in_file(file) # Try to find (class, function or variable) in file and return its line number
|
||||||
|
"""
|
||||||
|
|
||||||
import inspect
|
import inspect
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Dictionary checks
|
||||||
|
########################################
|
||||||
|
|
||||||
|
def dict_check(dic, *args):
|
||||||
|
"""
|
||||||
|
Helper function to test existence of a list of succesive keys within a nested dictionary.
|
||||||
|
:param dic: The dictionary of dictionaries to check
|
||||||
|
:param args: Any number of keys to check the dictionaries for
|
||||||
|
:type dic: dict | config.ConfigLoader
|
||||||
|
:type args: str
|
||||||
|
:return: A table of Booleans for every key checked.
|
||||||
|
"""
|
||||||
|
output = [False for _ in args]
|
||||||
|
for i in range(len(args)):
|
||||||
|
if args[i] in dic:
|
||||||
|
output[i] = True
|
||||||
|
dic = dic[args[i]]
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
return output
|
||||||
|
|
||||||
|
|
||||||
|
def str_dict_check(dic, *args):
|
||||||
|
"""
|
||||||
|
Helper function to test existence within a dictionary and return a string of the values of the keys checked
|
||||||
|
and wether they exist.
|
||||||
|
'arg[0]' : True or False
|
||||||
|
:param dic: The nested dictionary to check
|
||||||
|
:param args: Any number of keys to check successively
|
||||||
|
:type dic: dict
|
||||||
|
:type args: str
|
||||||
|
:return: A string of the values of the keys checked and wether they exist.
|
||||||
|
:rtype: str
|
||||||
|
"""
|
||||||
|
out = dict_check(dic, *args)
|
||||||
|
return "\n".join([f"{args[i]}: {out[i]}" for i in range(len(out))])
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Paths
|
# Paths
|
||||||
########################################
|
########################################
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,11 @@
|
||||||
structural_elements:
|
structural_elements:
|
||||||
div: ["<div{optionals}>", "</div>"]
|
se_div: ["<div{optionals}>", "</div>"]
|
||||||
article: ["<article{optionals}>", "</article>"]
|
se_article: ["<article{optionals}>", "</article>"]
|
||||||
aside: ["<aside{optionals}>", "</aside>"]
|
se_aside: ["<aside{optionals}>", "</aside>"]
|
||||||
section: ["<section{optionals}>", "</section>"]
|
se_section: ["<section{optionals}>", "</section>"]
|
||||||
|
se_nav: ["<nav{optionals}>", "</nav>"]
|
||||||
|
se_header: ["<header{optionals}>", "</header>"]
|
||||||
|
se_body: ["<body{optionals}>", "</body>"]
|
||||||
header: ["<h{header_level}{optionals}>", "</h{header_level}>"]
|
header: ["<h{header_level}{optionals}>", "</h{header_level}>"]
|
||||||
display: ["<p class=\"display-{display_level}\"{optionals}>", "</p>"]
|
display: ["<p class=\"display-{display_level}\"{optionals}>", "</p>"]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from yaml.scanner import ScannerError
|
||||||
|
|
||||||
import bootstraparse.modules.config as config
|
import bootstraparse.modules.config as config
|
||||||
import pytest
|
import pytest
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
@ -10,7 +12,8 @@ configs = {
|
||||||
"app/configs/parser_config.yaml": '{"parser": {"name": "test_parser", "type": "test_parser"}}',
|
"app/configs/parser_config.yaml": '{"parser": {"name": "test_parser", "type": "test_parser"}}',
|
||||||
"app/configs/aliases.yaml": '{"parser": {"name": "test_parser", "type": "test_parser"}}',
|
"app/configs/aliases.yaml": '{"parser": {"name": "test_parser", "type": "test_parser"}}',
|
||||||
"user/config/aliases.yaml": '{"aliases": {"test_alias": "test_parser"}}',
|
"user/config/aliases.yaml": '{"aliases": {"test_alias": "test_parser"}}',
|
||||||
"user/config/glossary.yaml": '{"glossary": {"test_glossary": "test_parser"}}',
|
"app/configs/glossary.yaml": '{"glossary": {"test_glossary": "test_parser"}}',
|
||||||
|
"user/config/glossary.yaml": '{"glossary": {"test_glossary": "second_parser"}}',
|
||||||
"user/config/custom_template.yaml": '{"custom_template": {"test_template": "test_parser"}}',
|
"user/config/custom_template.yaml": '{"custom_template": {"test_template": "test_parser"}}',
|
||||||
}
|
}
|
||||||
bad_configs = {
|
bad_configs = {
|
||||||
|
|
@ -36,7 +39,9 @@ def make_false_configs():
|
||||||
def test_config_load():
|
def test_config_load():
|
||||||
usr_c = config.ConfigLoader(user_conf)
|
usr_c = config.ConfigLoader(user_conf)
|
||||||
assert usr_c["aliases"] == {"aliases": {"test_alias": "test_parser"}}
|
assert usr_c["aliases"] == {"aliases": {"test_alias": "test_parser"}}
|
||||||
assert usr_c["glossary"] == {"glossary": {"test_glossary": "test_parser"}}
|
assert usr_c["glossary"] == {"glossary": {"test_glossary": "second_parser"}}
|
||||||
|
assert usr_c["glossary"]["glossary"] == {"test_glossary": "second_parser"}
|
||||||
|
assert usr_c["glossary"]["glossary"]["test_glossary"] == "second_parser"
|
||||||
assert usr_c["aliases"]["aliases"] == {"test_alias": "test_parser"}
|
assert usr_c["aliases"]["aliases"] == {"test_alias": "test_parser"}
|
||||||
assert usr_c["aliases"]["aliases"]["test_alias"] == "test_parser"
|
assert usr_c["aliases"]["aliases"]["test_alias"] == "test_parser"
|
||||||
with pytest.raises(KeyError):
|
with pytest.raises(KeyError):
|
||||||
|
|
@ -54,7 +59,6 @@ def test_add_to_config():
|
||||||
assert from_list["aliases"] == {"aliases": {"test_alias": "test_parser"},
|
assert from_list["aliases"] == {"aliases": {"test_alias": "test_parser"},
|
||||||
"parser": {"name": "test_parser", "type": "test_parser"}}
|
"parser": {"name": "test_parser", "type": "test_parser"}}
|
||||||
assert from_list["parser_config"] == {"parser": {"name": "test_parser", "type": "test_parser"}}
|
assert from_list["parser_config"] == {"parser": {"name": "test_parser", "type": "test_parser"}}
|
||||||
|
|
||||||
with pytest.raises(KeyError): # Not FileNotFoundError
|
with pytest.raises(KeyError): # Not FileNotFoundError
|
||||||
assert from_empty["aliases"]
|
assert from_empty["aliases"]
|
||||||
from_empty.add_folder(user_conf)
|
from_empty.add_folder(user_conf)
|
||||||
|
|
@ -64,7 +68,7 @@ def test_add_to_config():
|
||||||
assert from_empty["aliases"] == {"aliases": {"test_alias": "test_parser"},
|
assert from_empty["aliases"] == {"aliases": {"test_alias": "test_parser"},
|
||||||
"parser": {"name": "test_parser", "type": "test_parser"}}
|
"parser": {"name": "test_parser", "type": "test_parser"}}
|
||||||
|
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(ScannerError):
|
||||||
from_empty.load_from_file(os.path.join(bad_conf, "bad_config.yaml"))
|
from_empty.load_from_file(os.path.join(bad_conf, "bad_config.yaml"))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,21 @@ _token_list_with_expected_result = [
|
||||||
],
|
],
|
||||||
__GLk(1),
|
__GLk(1),
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
[
|
||||||
|
sy.StructuralElementStartToken(["header"]),
|
||||||
|
sy.TextToken(["1"]),
|
||||||
|
sy.StructuralElementEndToken(["header"]),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
context_mngr.SeContainer([
|
||||||
|
sy.StructuralElementStartToken(["header"]),
|
||||||
|
context_mngr.TextContainer([sy.TextToken(["1"])]),
|
||||||
|
sy.StructuralElementEndToken(["header"])
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
__GLk(1),
|
||||||
|
],
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
sy.EtEmToken(["*"]),
|
sy.EtEmToken(["*"]),
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ from collections import namedtuple
|
||||||
from importlib import reload
|
from importlib import reload
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
import pytest
|
import pytest
|
||||||
|
import bootstraparse.modules.tools as tools
|
||||||
import bootstraparse.modules.error_mngr as error_mngr
|
import bootstraparse.modules.error_mngr as error_mngr
|
||||||
from bootstraparse.modules.error_mngr import ParsingError, MismatchedContainerError
|
from bootstraparse.modules.error_mngr import ParsingError, MismatchedContainerError
|
||||||
|
|
||||||
|
|
@ -83,23 +84,23 @@ def test_dict_check():
|
||||||
"""
|
"""
|
||||||
Test the dict_check function
|
Test the dict_check function
|
||||||
"""
|
"""
|
||||||
assert(error_mngr.dict_check({"test": "test"}, "test") == [True])
|
assert(tools.dict_check({"test": "test"}, "test") == [True])
|
||||||
assert(error_mngr.dict_check({"test": "test"}, "test2") == [False])
|
assert(tools.dict_check({"test": "test"}, "test2") == [False])
|
||||||
assert(error_mngr.dict_check({"test": {"test3": "test5"}}, "test", "test3") == [True, True])
|
assert(tools.dict_check({"test": {"test3": "test5"}}, "test", "test3") == [True, True])
|
||||||
assert(error_mngr.dict_check({"test": {"test3": "test5"}}, "test4", "test4") == [False, False])
|
assert(tools.dict_check({"test": {"test3": "test5"}}, "test4", "test4") == [False, False])
|
||||||
assert(error_mngr.dict_check({"test": {"test3": "test5"}}, "test", "test34") == [True, False])
|
assert(tools.dict_check({"test": {"test3": "test5"}}, "test", "test34") == [True, False])
|
||||||
|
|
||||||
|
|
||||||
# @pytest.mark.xfail(strict=True, reason="This test is not implemented yet")
|
# @pytest.mark.xfail(strict=True, reason="This test is not implemented yet")
|
||||||
def test_dict_check_2():
|
def test_dict_check_2():
|
||||||
assert(error_mngr.dict_check({"test": "test"}, "test", "test2") == [True, False])
|
assert(tools.dict_check({"test": "test"}, "test", "test2") == [True, False])
|
||||||
assert(error_mngr.dict_check({"test": "test"}, "test", "test2", "test3") == [True, False, False])
|
assert(tools.dict_check({"test": "test"}, "test", "test2", "test3") == [True, False, False])
|
||||||
|
|
||||||
|
|
||||||
def test_dict_str():
|
def test_dict_str():
|
||||||
assert error_mngr.str_dict_check({"test": "test"}, "test") == "test: True"
|
assert tools.str_dict_check({"test": "test"}, "test") == "test: True"
|
||||||
assert error_mngr.str_dict_check({"test": "test"}, "test2") == "test2: False"
|
assert tools.str_dict_check({"test": "test"}, "test2") == "test2: False"
|
||||||
assert error_mngr.str_dict_check({"test": {"test3": "test5"}}, "test", "test3") == "test: True\ntest3: True"
|
assert tools.str_dict_check({"test": {"test3": "test5"}}, "test", "test3") == "test: True\ntest3: True"
|
||||||
|
|
||||||
|
|
||||||
def test_weird_exception_cases():
|
def test_weird_exception_cases():
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,14 @@ __templates = config.ConfigLoader(pathresolver.b_path("templates/"))
|
||||||
__XF = pytest.mark.xfail
|
__XF = pytest.mark.xfail
|
||||||
_all_templates = {
|
_all_templates = {
|
||||||
"structural_elements": [
|
"structural_elements": [
|
||||||
["div", __GLk(1)],
|
["se_div", __GLk(1)],
|
||||||
["article", __GLk(1)],
|
["se_article", __GLk(1)],
|
||||||
["aside", __GLk(1)],
|
["se_aside", __GLk(1)],
|
||||||
["section", __GLk(1)],
|
["se_section", __GLk(1)],
|
||||||
["header", __GLk(1)],
|
["header", __GLk(1)],
|
||||||
["display", __GLk(1)],
|
["display", __GLk(1)],
|
||||||
|
["se_body", __GLk(1)],
|
||||||
|
["se_nav", __GLk(1)],
|
||||||
],
|
],
|
||||||
"inline_elements": [
|
"inline_elements": [
|
||||||
["link", __GLk(1)],
|
["link", __GLk(1)],
|
||||||
|
|
@ -86,7 +88,7 @@ def test_export_response():
|
||||||
("table", "t_head"),
|
("table", "t_head"),
|
||||||
("table", "t_row"),
|
("table", "t_row"),
|
||||||
("table", "t_cell"),
|
("table", "t_cell"),
|
||||||
("structural_elements", "div"),
|
("structural_elements", "se_div"),
|
||||||
])
|
])
|
||||||
def test_transform(export_type, export_subtype):
|
def test_transform(export_type, export_subtype):
|
||||||
"""
|
"""
|
||||||
|
|
@ -118,7 +120,7 @@ def test_get_template_error():
|
||||||
|
|
||||||
def test_with_optionnals():
|
def test_with_optionnals():
|
||||||
em = export.ExportManager(__config, __templates)
|
em = export.ExportManager(__config, __templates)
|
||||||
em(export.ExportRequest("structural_elements", "div", _opts)) # noqa E741
|
em(export.ExportRequest("structural_elements", "se_div", _opts)) # noqa E741
|
||||||
|
|
||||||
|
|
||||||
def test_format_optionnals():
|
def test_format_optionnals():
|
||||||
|
|
@ -147,6 +149,7 @@ def test_bad_header():
|
||||||
|
|
||||||
@pytest.mark.parametrize("export_type, export_subtype, line", zipped_templates)
|
@pytest.mark.parametrize("export_type, export_subtype, line", zipped_templates)
|
||||||
def test_get_templates(export_type, export_subtype, line):
|
def test_get_templates(export_type, export_subtype, line):
|
||||||
|
print(line)
|
||||||
em = export.ExportManager(__config, __templates)
|
em = export.ExportManager(__config, __templates)
|
||||||
# assert type(em.get_templates()) is dict
|
# assert type(em.get_templates()) is dict
|
||||||
print(export_type, export_subtype)
|
print(export_type, export_subtype)
|
||||||
|
|
|
||||||
|
|
@ -246,7 +246,7 @@ def test_make_import_list(filename, content, capsys):
|
||||||
])
|
])
|
||||||
def test_preparser_content(filename, content):
|
def test_preparser_content(filename, content):
|
||||||
"""
|
"""
|
||||||
Test the preparser content
|
Test the PreParser content
|
||||||
"""
|
"""
|
||||||
testfile = temp_name(os.path.join(_BASE_PATH_GIVEN, filename))
|
testfile = temp_name(os.path.join(_BASE_PATH_GIVEN, filename))
|
||||||
assert os.path.exists(testfile)
|
assert os.path.exists(testfile)
|
||||||
|
|
@ -258,7 +258,7 @@ def test_preparser_content(filename, content):
|
||||||
|
|
||||||
def test_subfolder_parsing():
|
def test_subfolder_parsing():
|
||||||
"""
|
"""
|
||||||
Test the preparser content
|
Test the PreParser content
|
||||||
"""
|
"""
|
||||||
testfile = temp_name(os.path.join(_BASE_PATH_GIVEN, "superimports.bpr"))
|
testfile = temp_name(os.path.join(_BASE_PATH_GIVEN, "superimports.bpr"))
|
||||||
assert os.path.exists(testfile)
|
assert os.path.exists(testfile)
|
||||||
|
|
|
||||||
|
|
@ -19,12 +19,21 @@ files = [
|
||||||
("base/config/test6.bpr", "", None),
|
("base/config/test6.bpr", "", None),
|
||||||
("base/config/test7.yml", "", None),
|
("base/config/test7.yml", "", None),
|
||||||
("base/templates/test8.yml", "", None),
|
("base/templates/test8.yml", "", None),
|
||||||
|
("base/unparsable.php", "", ""),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def make_new_file(path, content="", mode="w+"):
|
def make_new_file(path, content="", mode="w+"):
|
||||||
"""
|
"""
|
||||||
Make a new file
|
Make a new file and all the directories in the path
|
||||||
|
:param path: the path to the file
|
||||||
|
:type path: str
|
||||||
|
:param content: the content of the file
|
||||||
|
:type content: str
|
||||||
|
:param mode: the mode of the file
|
||||||
|
:type mode: str
|
||||||
|
:return: the path to the file
|
||||||
|
:rtype: str
|
||||||
"""
|
"""
|
||||||
name = os.path.join(_TEMP_DIRECTORY.name, path)
|
name = os.path.join(_TEMP_DIRECTORY.name, path)
|
||||||
os.makedirs(os.path.dirname(name), exist_ok=True)
|
os.makedirs(os.path.dirname(name), exist_ok=True)
|
||||||
|
|
@ -88,6 +97,7 @@ def test_result_crawler(list_files, env):
|
||||||
"""
|
"""
|
||||||
crw = sitecrawler.SiteCrawler(_BASE, _DEST, env)
|
crw = sitecrawler.SiteCrawler(_BASE, _DEST, env)
|
||||||
crw.set_all_preparsers()
|
crw.set_all_preparsers()
|
||||||
|
crw.copy_unparsable_files()
|
||||||
for pp, dest in crw:
|
for pp, dest in crw:
|
||||||
assert os.path.exists(dest)
|
assert os.path.exists(dest)
|
||||||
assert os.path.isfile(dest)
|
assert os.path.isfile(dest)
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import pyparsing
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import bootstraparse.modules.syntax as sy
|
import bootstraparse.modules.syntax as sy
|
||||||
from bootstraparse.modules.tools import __GL, __module_path, find_variables_in_file
|
from bootstraparse.modules.tools import __GL, __GLk, __module_path, find_variables_in_file
|
||||||
|
|
||||||
ptp = pytest.param
|
ptp = pytest.param
|
||||||
__XF = pytest.mark.xfail
|
__XF = pytest.mark.xfail
|
||||||
|
|
@ -111,33 +111,33 @@ dict_advanced_syntax_input_and_expected_output = {
|
||||||
# Enhanced text
|
# Enhanced text
|
||||||
"et_em": [
|
"et_em": [
|
||||||
# Single em element, should only match the first "*"
|
# Single em element, should only match the first "*"
|
||||||
("*", (sy.EtEmToken(["*"]),), __GL()),
|
("*", (sy.EtEmToken(["*"]),), __GLk()),
|
||||||
],
|
],
|
||||||
"et_strong": [
|
"et_strong": [
|
||||||
# Single strong element, should only match the first "**"
|
# Single strong element, should only match the first "**"
|
||||||
("**", (sy.EtStrongToken(["**"]),), __GL()),
|
("**", (sy.EtStrongToken(["**"]),), __GLk()),
|
||||||
],
|
],
|
||||||
"et_underline": [
|
"et_underline": [
|
||||||
# Single underline element, should only match the first "__"
|
# Single underline element, should only match the first "__"
|
||||||
("__", (sy.EtUnderlineToken(["__"]),), __GL()),
|
("__", (sy.EtUnderlineToken(["__"]),), __GLk()),
|
||||||
],
|
],
|
||||||
"et_strikethrough": [
|
"et_strikethrough": [
|
||||||
# Single strikethrough element, should only match the first "~~"
|
# Single strikethrough element, should only match the first "~~"
|
||||||
("~~", (sy.EtStrikethroughToken(["~~"]),), __GL()),
|
("~~", (sy.EtStrikethroughToken(["~~"]),), __GLk()),
|
||||||
],
|
],
|
||||||
"et_custom_span": [
|
"et_custom_span": [
|
||||||
# Single custom span element, should only match the first "(#number)"
|
# Single custom span element, should only match the first "(#number)"
|
||||||
("(#12345)", (sy.EtCustomSpanToken(["12345"]),), __GL()),
|
("(#12345)", (sy.EtCustomSpanToken(["12345"]),), __GLk()),
|
||||||
],
|
],
|
||||||
"il_link": [
|
"il_link": [
|
||||||
# Single link element, should only match the first "[link_name]('link')"
|
# Single link element, should only match the first "[link_name]('link')"
|
||||||
("[text_link]('text://www.website.com/link.html')",
|
("[text_link]('text://www.website.com/link.html')",
|
||||||
[sy.HyperlinkToken(["[text_link]('text://www.website.com/link.html')"])], __GL())
|
[sy.HyperlinkToken(["[text_link]('text://www.website.com/link.html')"])], __GLk())
|
||||||
],
|
],
|
||||||
"assignation": [
|
"assignation": [
|
||||||
# Single assignation element, should only match the first "a=1"
|
# Single assignation element, should only match the first "a=1"
|
||||||
("a=1", [sy.BeAssignToken([["a", 1]]), ], __GL()),
|
("a=1", [sy.BeAssignToken([["a", 1]]), ], __GLk()),
|
||||||
("a='str'", [sy.BeAssignToken([["a", 'str']]), ], __GL()),
|
("a='str'", [sy.BeAssignToken([["a", 'str']]), ], __GLk()),
|
||||||
],
|
],
|
||||||
"var": [
|
"var": [
|
||||||
# List of variables or assignations, should match "[a=12, b=13, 'c']"
|
# List of variables or assignations, should match "[a=12, b=13, 'c']"
|
||||||
|
|
@ -145,13 +145,13 @@ dict_advanced_syntax_input_and_expected_output = {
|
||||||
sy.BeAssignToken([["a_12", 12]]),
|
sy.BeAssignToken([["a_12", 12]]),
|
||||||
sy.BeAssignToken([["b", 13]]),
|
sy.BeAssignToken([["b", 13]]),
|
||||||
sy.BeValueToken(["c"]),
|
sy.BeValueToken(["c"]),
|
||||||
], __GL()),
|
], __GLk()),
|
||||||
("[a=12, b=13, 'c', d=14]", [
|
("[a=12, b=13, 'c', d=14]", [
|
||||||
sy.BeAssignToken([["a", 12]]),
|
sy.BeAssignToken([["a", 12]]),
|
||||||
sy.BeAssignToken([["b", 13]]),
|
sy.BeAssignToken([["b", 13]]),
|
||||||
sy.BeValueToken(["c"]),
|
sy.BeValueToken(["c"]),
|
||||||
sy.BeAssignToken([["d", 14]]),
|
sy.BeAssignToken([["d", 14]]),
|
||||||
], __GL()),
|
], __GLk()),
|
||||||
],
|
],
|
||||||
"optional": [
|
"optional": [
|
||||||
# Optional element, should match any optional element
|
# Optional element, should match any optional element
|
||||||
|
|
@ -163,7 +163,7 @@ dict_advanced_syntax_input_and_expected_output = {
|
||||||
sy.BeValueToken(["c"]),
|
sy.BeValueToken(["c"]),
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
], __GL()),
|
], __GLk()),
|
||||||
("[a=12, b=13, 'c', d=14]", [
|
("[a=12, b=13, 'c', d=14]", [
|
||||||
sy.OptionalToken([
|
sy.OptionalToken([
|
||||||
sy.OptionalVarToken([
|
sy.OptionalVarToken([
|
||||||
|
|
@ -173,7 +173,7 @@ dict_advanced_syntax_input_and_expected_output = {
|
||||||
sy.BeAssignToken([["d", 14]]),
|
sy.BeAssignToken([["d", 14]]),
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
], __GL()),
|
], __GLk()),
|
||||||
("[a=12]{aze,/.}", (
|
("[a=12]{aze,/.}", (
|
||||||
sy.OptionalToken([
|
sy.OptionalToken([
|
||||||
sy.OptionalVarToken([
|
sy.OptionalVarToken([
|
||||||
|
|
@ -183,7 +183,7 @@ dict_advanced_syntax_input_and_expected_output = {
|
||||||
"aze,/.",
|
"aze,/.",
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
), __GL()),
|
), __GLk()),
|
||||||
("{aze,/.__}[a=12]", (
|
("{aze,/.__}[a=12]", (
|
||||||
sy.OptionalToken([
|
sy.OptionalToken([
|
||||||
sy.OptionalInsertToken([
|
sy.OptionalInsertToken([
|
||||||
|
|
@ -193,21 +193,21 @@ dict_advanced_syntax_input_and_expected_output = {
|
||||||
sy.BeAssignToken([["a", 12]]),
|
sy.BeAssignToken([["a", 12]]),
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
), __GL()),
|
), __GLk()),
|
||||||
("{aze!=}", (
|
("{aze!=}", (
|
||||||
sy.OptionalToken([
|
sy.OptionalToken([
|
||||||
sy.OptionalInsertToken([
|
sy.OptionalInsertToken([
|
||||||
"aze!=",
|
"aze!=",
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
), __GL()),
|
), __GLk()),
|
||||||
("{{aze!=}}", (
|
("{{aze!=}}", (
|
||||||
sy.OptionalToken([
|
sy.OptionalToken([
|
||||||
sy.OptionalClassToken([
|
sy.OptionalClassToken([
|
||||||
"aze!=",
|
"aze!=",
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
), __GL()),
|
), __GLk()),
|
||||||
("{{aze!=}}{azett!=}", (
|
("{{aze!=}}{azett!=}", (
|
||||||
sy.OptionalToken([
|
sy.OptionalToken([
|
||||||
sy.OptionalClassToken([
|
sy.OptionalClassToken([
|
||||||
|
|
@ -217,7 +217,7 @@ dict_advanced_syntax_input_and_expected_output = {
|
||||||
"azett!=",
|
"azett!=",
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
), __GL()),
|
), __GLk()),
|
||||||
("{{aze!=}}{azett!=}[a_32=12]", (
|
("{{aze!=}}{azett!=}[a_32=12]", (
|
||||||
sy.OptionalToken([
|
sy.OptionalToken([
|
||||||
sy.OptionalClassToken([
|
sy.OptionalClassToken([
|
||||||
|
|
@ -230,7 +230,7 @@ dict_advanced_syntax_input_and_expected_output = {
|
||||||
sy.BeAssignToken([["a_32", 12]]),
|
sy.BeAssignToken([["a_32", 12]]),
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
), __GL()),
|
), __GLk()),
|
||||||
("[_a=12]{aze,/.}{{azer!=}}", (
|
("[_a=12]{aze,/.}{{azer!=}}", (
|
||||||
sy.OptionalToken([
|
sy.OptionalToken([
|
||||||
sy.OptionalVarToken([
|
sy.OptionalVarToken([
|
||||||
|
|
@ -243,36 +243,36 @@ dict_advanced_syntax_input_and_expected_output = {
|
||||||
"azer!=",
|
"azer!=",
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
), __GL()),
|
), __GLk()),
|
||||||
],
|
],
|
||||||
# Enhanced Text
|
# Enhanced Text
|
||||||
"enhanced_text": [
|
"enhanced_text": [
|
||||||
# Matches a line of text, with or without inline elements
|
# Matches a line of text, with or without inline elements
|
||||||
("*test*", (sy.EtEmToken(["*"]), sy.TextToken(["test"]), sy.EtEmToken(["*"])), __GL()),
|
("*test*", (sy.EtEmToken(["*"]), sy.TextToken(["test"]), sy.EtEmToken(["*"])), __GLk()),
|
||||||
("**test**", (sy.EtStrongToken(["**"]), sy.TextToken(["test"]), sy.EtStrongToken(["**"])), __GL()),
|
("**test**", (sy.EtStrongToken(["**"]), sy.TextToken(["test"]), sy.EtStrongToken(["**"])), __GLk()),
|
||||||
("__test__", (sy.EtUnderlineToken(["__"]), sy.TextToken(["test"]), sy.EtUnderlineToken(["__"])), __GL()),
|
("__test__", (sy.EtUnderlineToken(["__"]), sy.TextToken(["test"]), sy.EtUnderlineToken(["__"])), __GLk()),
|
||||||
("~~test~~", (sy.EtStrikethroughToken(["~~"]), sy.TextToken(["test"]), sy.EtStrikethroughToken(["~~"])), __GL()),
|
("~~test~~", (sy.EtStrikethroughToken(["~~"]), sy.TextToken(["test"]), sy.EtStrikethroughToken(["~~"])), __GLk()),
|
||||||
("(#12345)", (sy.EtCustomSpanToken(["12345"]),), __GL()),
|
("(#12345)", (sy.EtCustomSpanToken(["12345"]),), __GLk()),
|
||||||
("*test*test*", (sy.EtEmToken(["*"]), sy.TextToken(["test"]), sy.EtEmToken(["*"]), sy.TextToken(["test"]),
|
("*test*test*", (sy.EtEmToken(["*"]), sy.TextToken(["test"]), sy.EtEmToken(["*"]), sy.TextToken(["test"]),
|
||||||
sy.EtEmToken(["*"])), __GL()),
|
sy.EtEmToken(["*"])), __GLk()),
|
||||||
("**test**test**",
|
("**test**test**",
|
||||||
(sy.EtStrongToken(["**"]), sy.TextToken(["test"]), sy.EtStrongToken(["**"]), sy.TextToken(["test"]),
|
(sy.EtStrongToken(["**"]), sy.TextToken(["test"]), sy.EtStrongToken(["**"]), sy.TextToken(["test"]),
|
||||||
sy.EtStrongToken(["**"]),), __GL()),
|
sy.EtStrongToken(["**"]),), __GLk()),
|
||||||
("__test__test__", (sy.EtUnderlineToken(["__"]), sy.TextToken(["test"]), sy.EtUnderlineToken(["__"]),
|
("__test__test__", (sy.EtUnderlineToken(["__"]), sy.TextToken(["test"]), sy.EtUnderlineToken(["__"]),
|
||||||
sy.TextToken(["test"]), sy.EtUnderlineToken(["__"]),), __GL()),
|
sy.TextToken(["test"]), sy.EtUnderlineToken(["__"]),), __GLk()),
|
||||||
("~~test~~test~~", (sy.EtStrikethroughToken(["~~"]), sy.TextToken(["test"]), sy.EtStrikethroughToken(["~~"]),
|
("~~test~~test~~", (sy.EtStrikethroughToken(["~~"]), sy.TextToken(["test"]), sy.EtStrikethroughToken(["~~"]),
|
||||||
sy.TextToken(["test"]), sy.EtStrikethroughToken(["~~"]),), __GL()),
|
sy.TextToken(["test"]), sy.EtStrikethroughToken(["~~"]),), __GLk()),
|
||||||
("(#12345)test(#12345)", (sy.EtCustomSpanToken(["12345"]), sy.TextToken(["test"]),
|
("(#12345)test(#12345)", (sy.EtCustomSpanToken(["12345"]), sy.TextToken(["test"]),
|
||||||
sy.EtCustomSpanToken(["12345"]),), __GL()),
|
sy.EtCustomSpanToken(["12345"]),), __GLk()),
|
||||||
("__test(#12)test**test__test~~", (sy.EtUnderlineToken(["__"]), sy.TextToken(["test"]),
|
("__test(#12)test**test__test~~", (sy.EtUnderlineToken(["__"]), sy.TextToken(["test"]),
|
||||||
sy.EtCustomSpanToken(["12"]), sy.TextToken(["test"]),
|
sy.EtCustomSpanToken(["12"]), sy.TextToken(["test"]),
|
||||||
sy.EtStrongToken(["**"]),
|
sy.EtStrongToken(["**"]),
|
||||||
sy.TextToken(["test"]), sy.EtUnderlineToken(["__"]),
|
sy.TextToken(["test"]), sy.EtUnderlineToken(["__"]),
|
||||||
sy.TextToken(["test"]), sy.EtStrikethroughToken(["~~"]),), __GL()),
|
sy.TextToken(["test"]), sy.EtStrikethroughToken(["~~"]),), __GLk()),
|
||||||
("Test text with a link [link_name]('link')", (
|
("Test text with a link [link_name]('link')", (
|
||||||
sy.TextToken(["Test text with a link"]),
|
sy.TextToken(["Test text with a link"]),
|
||||||
sy.HyperlinkToken(["[link_name]('link')"]),
|
sy.HyperlinkToken(["[link_name]('link')"]),
|
||||||
), __GL()),
|
), __GLk()),
|
||||||
("Test text with a link [link_name](\"link\") and a *bold* text", (
|
("Test text with a link [link_name](\"link\") and a *bold* text", (
|
||||||
sy.TextToken(["Test text with a link"]),
|
sy.TextToken(["Test text with a link"]),
|
||||||
sy.HyperlinkToken(['[link_name]("link")']),
|
sy.HyperlinkToken(['[link_name]("link")']),
|
||||||
|
|
@ -280,39 +280,39 @@ dict_advanced_syntax_input_and_expected_output = {
|
||||||
sy.TextToken(["bold"]),
|
sy.TextToken(["bold"]),
|
||||||
sy.EtEmToken(["*"]),
|
sy.EtEmToken(["*"]),
|
||||||
sy.TextToken(["text"]),
|
sy.TextToken(["text"]),
|
||||||
), __GL()),
|
), __GLk()),
|
||||||
("Reverse order (#123) Span __ Underline ~~ Strikethrough", (
|
("Reverse order (#123) Span __ Underline ~~ Strikethrough", (
|
||||||
sy.TextToken(["Reverse order"]),
|
sy.TextToken(["Reverse order"]),
|
||||||
sy.EtCustomSpanToken(["123"]), sy.TextToken(["Span"]),
|
sy.EtCustomSpanToken(["123"]), sy.TextToken(["Span"]),
|
||||||
sy.EtUnderlineToken(["__"]), sy.TextToken(["Underline"]),
|
sy.EtUnderlineToken(["__"]), sy.TextToken(["Underline"]),
|
||||||
sy.EtStrikethroughToken(["~~"]), sy.TextToken(["Strikethrough"]),
|
sy.EtStrikethroughToken(["~~"]), sy.TextToken(["Strikethrough"]),
|
||||||
), __GL()),
|
), __GLk()),
|
||||||
],
|
],
|
||||||
"html_insert": [
|
"html_insert": [
|
||||||
# Match an HTML insert
|
# Match an HTML insert
|
||||||
("{azer='\"}", (
|
("{azer='\"}", (
|
||||||
"azer='\"",
|
"azer='\"",
|
||||||
), __GL()),
|
), __GLk()),
|
||||||
],
|
],
|
||||||
"class_insert": [
|
"class_insert": [
|
||||||
# Match a class insert
|
# Match a class insert
|
||||||
("{{azer='\"}}", (
|
("{{azer='\"}}", (
|
||||||
"azer='\"",
|
"azer='\"",
|
||||||
), __GL()),
|
), __GLk()),
|
||||||
],
|
],
|
||||||
# Structural Elements
|
# Structural Elements
|
||||||
"se_start": [
|
"se_start": [
|
||||||
# Matches a start of a structural element
|
# Matches a start of a structural element
|
||||||
("<<div", (sy.StructuralElementStartToken(["div"]),), __GL()),
|
("<<div", (sy.StructuralElementStartToken(["div"]),), __GLk()),
|
||||||
("<<aside", (sy.StructuralElementStartToken(["aside"]),), __GL()),
|
("<<aside", (sy.StructuralElementStartToken(["aside"]),), __GLk()),
|
||||||
("<<article", (sy.StructuralElementStartToken(["article"]),), __GL()),
|
("<<article", (sy.StructuralElementStartToken(["article"]),), __GLk()),
|
||||||
("<<section", (sy.StructuralElementStartToken(["section"]),), __GL()),
|
("<<section", (sy.StructuralElementStartToken(["section"]),), __GLk()),
|
||||||
],
|
],
|
||||||
"se_end": [
|
"se_end": [
|
||||||
("div>>", (sy.StructuralElementEndToken(["div"]),), __GL()),
|
("div>>", (sy.StructuralElementEndToken(["div"]),), __GLk()),
|
||||||
("aside>>", (sy.StructuralElementEndToken(["aside"]),), __GL()),
|
("aside>>", (sy.StructuralElementEndToken(["aside"]),), __GLk()),
|
||||||
("article>>", (sy.StructuralElementEndToken(["article"]),), __GL()),
|
("article>>", (sy.StructuralElementEndToken(["article"]),), __GLk()),
|
||||||
("section>>", (sy.StructuralElementEndToken(["section"]),), __GL()),
|
("section>>", (sy.StructuralElementEndToken(["section"]),), __GLk()),
|
||||||
],
|
],
|
||||||
"se": [
|
"se": [
|
||||||
# Matches a div element, must be at the beginning of the line, the closing div can be with arguments
|
# Matches a div element, must be at the beginning of the line, the closing div can be with arguments
|
||||||
|
|
@ -325,7 +325,7 @@ dict_advanced_syntax_input_and_expected_output = {
|
||||||
]),
|
]),
|
||||||
sy.OptionalInsertToken(["var='test', number=11"]),
|
sy.OptionalInsertToken(["var='test', number=11"]),
|
||||||
]),
|
]),
|
||||||
), __GL(),),
|
), __GLk(),),
|
||||||
("div>> [class='blue', 123]", (
|
("div>> [class='blue', 123]", (
|
||||||
sy.StructuralElementEndToken(["div"]),
|
sy.StructuralElementEndToken(["div"]),
|
||||||
sy.OptionalToken([
|
sy.OptionalToken([
|
||||||
|
|
@ -334,56 +334,56 @@ dict_advanced_syntax_input_and_expected_output = {
|
||||||
sy.BeValueToken([123.0]),
|
sy.BeValueToken([123.0]),
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
), __GL(),),
|
), __GLk(),),
|
||||||
|
|
||||||
("div>> {var='test', number=11}", (
|
("div>> {var='test', number=11}", (
|
||||||
sy.StructuralElementEndToken(["div"]),
|
sy.StructuralElementEndToken(["div"]),
|
||||||
sy.OptionalToken([
|
sy.OptionalToken([
|
||||||
sy.OptionalInsertToken(["var='test', number=11"]),
|
sy.OptionalInsertToken(["var='test', number=11"]),
|
||||||
]),
|
]),
|
||||||
), __GL(),),
|
), __GLk(),),
|
||||||
],
|
],
|
||||||
|
|
||||||
# List Elements
|
# List Elements
|
||||||
"one_olist": [
|
"one_olist": [
|
||||||
# Matches a one-level ordered list element, must be at the beginning of the line
|
# Matches a one-level ordered list element, must be at the beginning of the line
|
||||||
# Drop the "." from the match
|
# Drop the "." from the match
|
||||||
("#. Text", (sy.EtOlistToken([sy.TextToken(["Text"])]),), __GL()),
|
("#. Text", (sy.EtOlistToken([sy.TextToken(["Text"])]),), __GLk()),
|
||||||
],
|
],
|
||||||
"one_ulist": [
|
"one_ulist": [
|
||||||
# Matches a one-level unordered list element, must be at the beginning of the line
|
# Matches a one-level unordered list element, must be at the beginning of the line
|
||||||
# Drop the "-" from the match
|
# Drop the "-" from the match
|
||||||
("- Text", (sy.EtUlistToken([sy.TextToken(["Text"])]),), __GL()),
|
("- Text", (sy.EtUlistToken([sy.TextToken(["Text"])]),), __GLk()),
|
||||||
],
|
],
|
||||||
|
|
||||||
# Headers
|
# Headers
|
||||||
"one_header": [
|
"one_header": [
|
||||||
# Matches a one-level header element, must be at the beginning of the line
|
# Matches a one-level header element, must be at the beginning of the line
|
||||||
("# Text1 #", (sy.HeaderToken(["#", "Text1 "]),), __GL()),
|
("# Text1 #", (sy.HeaderToken(["#", "Text1 "]),), __GLk()),
|
||||||
("## Text2 ##", (sy.HeaderToken(["##", "Text2 "]),), __GL()),
|
("## Text2 ##", (sy.HeaderToken(["##", "Text2 "]),), __GLk()),
|
||||||
("### Text3 ###", (sy.HeaderToken(["###", "Text3 "]),), __GL()),
|
("### Text3 ###", (sy.HeaderToken(["###", "Text3 "]),), __GLk()),
|
||||||
("#### Text4 ####", (sy.HeaderToken(["####", "Text4 "]),), __GL()),
|
("#### Text4 ####", (sy.HeaderToken(["####", "Text4 "]),), __GLk()),
|
||||||
("##### Text5 #####", (sy.HeaderToken(["#####", "Text5 "]),), __GL()),
|
("##### Text5 #####", (sy.HeaderToken(["#####", "Text5 "]),), __GLk()),
|
||||||
("###### Text6 ######", (sy.HeaderToken(["######", "Text6 "]),), __GL()),
|
("###### Text6 ######", (sy.HeaderToken(["######", "Text6 "]),), __GLk()),
|
||||||
],
|
],
|
||||||
|
|
||||||
# One-line display elements
|
# One-line display elements
|
||||||
"one_display": [
|
"one_display": [
|
||||||
# Matches a one-level display element, must be at the beginning of the line
|
# Matches a one-level display element, must be at the beginning of the line
|
||||||
("! Display1 !", (sy.DisplayToken(["!", "Display1 "]),), __GL()),
|
("! Display1 !", (sy.DisplayToken(["!", "Display1 "]),), __GLk()),
|
||||||
("!! Display2 !!", (sy.DisplayToken(["!!", "Display2 "]),), __GL()),
|
("!! Display2 !!", (sy.DisplayToken(["!!", "Display2 "]),), __GLk()),
|
||||||
("!!! Display3 !!!", (sy.DisplayToken(["!!!", "Display3 "]),), __GL()),
|
("!!! Display3 !!!", (sy.DisplayToken(["!!!", "Display3 "]),), __GLk()),
|
||||||
],
|
],
|
||||||
|
|
||||||
# One-line elements
|
# One-line elements
|
||||||
"one_line": [
|
"one_line": [
|
||||||
# Matches a one-line element, must be at the beginning of the line
|
# Matches a one-line element, must be at the beginning of the line
|
||||||
("- Text1", (sy.EtUlistToken([sy.TextToken(["Text1"])]),), __GL()),
|
("- Text1", (sy.EtUlistToken([sy.TextToken(["Text1"])]),), __GLk()),
|
||||||
("#. Text2", (sy.EtOlistToken([sy.TextToken(["Text2"])]),), __GL()),
|
("#. Text2", (sy.EtOlistToken([sy.TextToken(["Text2"])]),), __GLk()),
|
||||||
("! Display3 !", (sy.DisplayToken(["!", "Display3 "]),), __GL()),
|
("! Display3 !", (sy.DisplayToken(["!", "Display3 "]),), __GLk()),
|
||||||
("!! Display4 !!", (sy.DisplayToken(["!!", "Display4 "]),), __GL()),
|
("!! Display4 !!", (sy.DisplayToken(["!!", "Display4 "]),), __GLk()),
|
||||||
("### Text5 ###", (sy.HeaderToken(["###", "Text5 "]),), __GL()),
|
("### Text5 ###", (sy.HeaderToken(["###", "Text5 "]),), __GLk()),
|
||||||
("#### Text6 ####", (sy.HeaderToken(["####", "Text6 "]),), __GL()),
|
("#### Text6 ####", (sy.HeaderToken(["####", "Text6 "]),), __GLk()),
|
||||||
("- Text7 [class='blue', 123]{var='test', number=11}", (
|
("- Text7 [class='blue', 123]{var='test', number=11}", (
|
||||||
sy.EtUlistToken([
|
sy.EtUlistToken([
|
||||||
sy.TextToken(["Text7"]),
|
sy.TextToken(["Text7"]),
|
||||||
|
|
@ -395,7 +395,7 @@ dict_advanced_syntax_input_and_expected_output = {
|
||||||
sy.OptionalInsertToken(["var='test', number=11"]),
|
sy.OptionalInsertToken(["var='test', number=11"]),
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
), __GL()),
|
), __GLk()),
|
||||||
("#. Text8 [class='blue', 123]{var='test', number=11}", (
|
("#. Text8 [class='blue', 123]{var='test', number=11}", (
|
||||||
sy.EtOlistToken([
|
sy.EtOlistToken([
|
||||||
sy.TextToken(["Text8"]),
|
sy.TextToken(["Text8"]),
|
||||||
|
|
@ -407,11 +407,12 @@ dict_advanced_syntax_input_and_expected_output = {
|
||||||
sy.OptionalInsertToken(["var='test', number=11"]),
|
sy.OptionalInsertToken(["var='test', number=11"]),
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
), __GL()),
|
), __GLk()),
|
||||||
("! Display9 ! [class='blue', 123]{var='test', number=11}", (
|
("! Display9 ! [class='blue', 123]{var='test', number=11}", (
|
||||||
sy.DisplayToken([
|
sy.DisplayToken([
|
||||||
"!",
|
"!",
|
||||||
"Display9 ",
|
"Display9 ",
|
||||||
|
]),
|
||||||
sy.OptionalToken([
|
sy.OptionalToken([
|
||||||
sy.OptionalVarToken([
|
sy.OptionalVarToken([
|
||||||
sy.BeAssignToken([["class", "blue"]]),
|
sy.BeAssignToken([["class", "blue"]]),
|
||||||
|
|
@ -419,12 +420,12 @@ dict_advanced_syntax_input_and_expected_output = {
|
||||||
]),
|
]),
|
||||||
sy.OptionalInsertToken(["var='test', number=11"]),
|
sy.OptionalInsertToken(["var='test', number=11"]),
|
||||||
]),
|
]),
|
||||||
]),
|
), __GLk(1)), # Bad optional implementation
|
||||||
), __GL()), # Bad optional implementation
|
|
||||||
("## Text10 ## [class='blue', 123]{var='test', number=11}", (
|
("## Text10 ## [class='blue', 123]{var='test', number=11}", (
|
||||||
sy.HeaderToken([
|
sy.HeaderToken([
|
||||||
"##",
|
"##",
|
||||||
"Text10 ",
|
"Text10 ",
|
||||||
|
]),
|
||||||
sy.OptionalToken([
|
sy.OptionalToken([
|
||||||
sy.OptionalVarToken([
|
sy.OptionalVarToken([
|
||||||
sy.BeAssignToken([["class", "blue"]]),
|
sy.BeAssignToken([["class", "blue"]]),
|
||||||
|
|
@ -432,8 +433,7 @@ dict_advanced_syntax_input_and_expected_output = {
|
||||||
]),
|
]),
|
||||||
sy.OptionalInsertToken(["var='test', number=11"]),
|
sy.OptionalInsertToken(["var='test', number=11"]),
|
||||||
]),
|
]),
|
||||||
]),
|
), __GLk(1)), # Bad optional implementation
|
||||||
), __GL()), # Bad optional implementation
|
|
||||||
],
|
],
|
||||||
|
|
||||||
# Tables
|
# Tables
|
||||||
|
|
@ -442,27 +442,27 @@ dict_advanced_syntax_input_and_expected_output = {
|
||||||
("| Text1 | Text2 |", (sy.TableRowToken([
|
("| Text1 | Text2 |", (sy.TableRowToken([
|
||||||
sy.TableCellToken([sy.TextToken(["Text1 "])]),
|
sy.TableCellToken([sy.TextToken(["Text1 "])]),
|
||||||
sy.TableCellToken([sy.TextToken(["Text2 "])]),
|
sy.TableCellToken([sy.TextToken(["Text2 "])]),
|
||||||
]), ), __GL()),
|
]), ), __GLk()),
|
||||||
("| Text1 | Text2 | Text3 |", (
|
("| Text1 | Text2 | Text3 |", (
|
||||||
sy.TableRowToken([
|
sy.TableRowToken([
|
||||||
sy.TableCellToken([sy.TextToken(["Text1 "])]),
|
sy.TableCellToken([sy.TextToken(["Text1 "])]),
|
||||||
sy.TableCellToken([sy.TextToken(["Text2 "])]),
|
sy.TableCellToken([sy.TextToken(["Text2 "])]),
|
||||||
sy.TableCellToken([sy.TextToken(["Text3 "])]),
|
sy.TableCellToken([sy.TextToken(["Text3 "])]),
|
||||||
]),
|
]),
|
||||||
), __GL()),
|
), __GLk()),
|
||||||
("| 2 Text1 | Text2 |", (
|
("| 2 Text1 | Text2 |", (
|
||||||
sy.TableRowToken([
|
sy.TableRowToken([
|
||||||
sy.TableCellToken([sy.TextToken(["2 Text1 "])]),
|
sy.TableCellToken([sy.TextToken(["2 Text1 "])]),
|
||||||
sy.TableCellToken([sy.TextToken(["Text2 "])]),
|
sy.TableCellToken([sy.TextToken(["Text2 "])]),
|
||||||
]),
|
]),
|
||||||
), __GL()),
|
), __GLk()),
|
||||||
("|2 Text1 | Text2 |", (
|
("|2 Text1 | Text2 |", (
|
||||||
sy.TableRowToken([
|
sy.TableRowToken([
|
||||||
'2',
|
'2',
|
||||||
sy.TableCellToken([sy.TextToken(["Text1 "])]),
|
sy.TableCellToken([sy.TextToken(["Text1 "])]),
|
||||||
sy.TableCellToken([sy.TextToken(["Text2 "])]),
|
sy.TableCellToken([sy.TextToken(["Text2 "])]),
|
||||||
]),
|
]),
|
||||||
), __GL()),
|
), __GLk()),
|
||||||
("|2 Text1 |3 Text2 |", (
|
("|2 Text1 |3 Text2 |", (
|
||||||
sy.TableRowToken([
|
sy.TableRowToken([
|
||||||
'2',
|
'2',
|
||||||
|
|
@ -470,7 +470,7 @@ dict_advanced_syntax_input_and_expected_output = {
|
||||||
'3',
|
'3',
|
||||||
sy.TableCellToken([sy.TextToken(["Text2 "])]),
|
sy.TableCellToken([sy.TextToken(["Text2 "])]),
|
||||||
]),
|
]),
|
||||||
), __GL()),
|
), __GLk()),
|
||||||
("|2 Text1 |3 Text2 |4 Text3 |", (
|
("|2 Text1 |3 Text2 |4 Text3 |", (
|
||||||
sy.TableRowToken([
|
sy.TableRowToken([
|
||||||
'2',
|
'2',
|
||||||
|
|
@ -480,7 +480,7 @@ dict_advanced_syntax_input_and_expected_output = {
|
||||||
'4',
|
'4',
|
||||||
sy.TableCellToken([sy.TextToken(["Text3 "])]),
|
sy.TableCellToken([sy.TextToken(["Text3 "])]),
|
||||||
]),
|
]),
|
||||||
), __GL()),
|
), __GLk()),
|
||||||
("|3 Text1 | Text2 | {var='test', number=11}", (
|
("|3 Text1 | Text2 | {var='test', number=11}", (
|
||||||
sy.TableRowToken([
|
sy.TableRowToken([
|
||||||
'3',
|
'3',
|
||||||
|
|
@ -492,19 +492,19 @@ dict_advanced_syntax_input_and_expected_output = {
|
||||||
"var='test', number=11",
|
"var='test', number=11",
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
), __GL()),
|
), __GLk()),
|
||||||
],
|
],
|
||||||
|
|
||||||
"table_separator": [
|
"table_separator": [
|
||||||
# Matches a table element, must be at the beginning of the line
|
# Matches a table element, must be at the beginning of the line
|
||||||
("|---|---|", (sy.TableSeparatorToken(["---", "---"]),), __GL()),
|
("|---|---|", (sy.TableSeparatorToken(["---", "---"]),), __GLk()),
|
||||||
("|---|---|---|", (sy.TableSeparatorToken(["---", "---", "---"]),), __GL()),
|
("|---|---|---|", (sy.TableSeparatorToken(["---", "---", "---"]),), __GLk()),
|
||||||
("|:--|-:-|--:|--:|", (sy.TableSeparatorToken([":--", "-:-", "--:", "--:"]),), __GL()),
|
("|:--|-:-|--:|--:|", (sy.TableSeparatorToken([":--", "-:-", "--:", "--:"]),), __GLk()),
|
||||||
],
|
],
|
||||||
|
|
||||||
"line": [
|
"line": [
|
||||||
# Match any line parsed by the parser (can match header, list table etc...) this is the main syntax element
|
# Match any line parsed by the parser (can match header, list table etc...) this is the main syntax element
|
||||||
("# Text1 #", (sy.HeaderToken(["#", "Text1 "]),), __GL()),
|
("# Text1 #", (sy.HeaderToken(["#", "Text1 "]),), __GLk()),
|
||||||
("Text *em __underline__ still em*", (
|
("Text *em __underline__ still em*", (
|
||||||
sy.TextToken(["Text"]),
|
sy.TextToken(["Text"]),
|
||||||
sy.EtEmToken(["*"]),
|
sy.EtEmToken(["*"]),
|
||||||
|
|
@ -514,17 +514,19 @@ dict_advanced_syntax_input_and_expected_output = {
|
||||||
sy.EtUnderlineToken(["__"]),
|
sy.EtUnderlineToken(["__"]),
|
||||||
sy.TextToken(["still em"]),
|
sy.TextToken(["still em"]),
|
||||||
sy.EtEmToken(["*"]),
|
sy.EtEmToken(["*"]),
|
||||||
), __GL(),),
|
), __GLk(),),
|
||||||
("|2 Text1 | Text2 |", (
|
("|2 Text1 | Text2 |", (
|
||||||
sy.TableRowToken([
|
sy.TableRowToken([
|
||||||
"2",
|
"2",
|
||||||
sy.TableCellToken([sy.TextToken(["Text1 "])]),
|
sy.TableCellToken([sy.TextToken(["Text1 "])]),
|
||||||
sy.TableCellToken([sy.TextToken(["Text2 "])]),
|
sy.TableCellToken([sy.TextToken(["Text2 "])]),
|
||||||
]),
|
]),
|
||||||
), __GL()),
|
), __GLk()),
|
||||||
("|---|---|", (sy.TableSeparatorToken(["---", "---"]),), __GL()),
|
("|---|---|", (sy.TableSeparatorToken(["---", "---"]),), __GLk()),
|
||||||
("- Text", (sy.EtUlistToken([sy.TextToken(["Text"])]),), __GL()),
|
("- Text", (sy.EtUlistToken([sy.TextToken(["Text"])]),), __GLk()),
|
||||||
("div>>", (sy.StructuralElementEndToken(["div"]),), __GL()),
|
(" - Non ulist", (sy.TextToken(["- Non ulist"]),), __GLk()),
|
||||||
|
("div>>", (sy.StructuralElementEndToken(["div"]),), __GLk()),
|
||||||
|
("body>>", (sy.StructuralElementEndToken(["body"]),), __GLk()),
|
||||||
("#. Text with *em* and __underline__ and {arguments}{{super-arguments}}[a=1, c=2,'ui']", (
|
("#. Text with *em* and __underline__ and {arguments}{{super-arguments}}[a=1, c=2,'ui']", (
|
||||||
sy.EtOlistToken([
|
sy.EtOlistToken([
|
||||||
sy.TextToken(["Text with"]),
|
sy.TextToken(["Text with"]),
|
||||||
|
|
@ -550,11 +552,11 @@ dict_advanced_syntax_input_and_expected_output = {
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
), __GL(),),
|
), __GLk(),),
|
||||||
("```Code```", (sy.CodeToken(["```"]), sy.TextToken(["Code"]), sy.CodeToken(["```"])), __GL()),
|
("```Code```", (sy.CodeToken(["```"]), sy.TextToken(["Code"]), sy.CodeToken(["```"])), __GLk()),
|
||||||
],
|
],
|
||||||
"blockquote": [
|
"blockquote": [
|
||||||
("> Text", (sy.BlockQuoteToken([sy.TextToken(["Text"])]),), __GL()),
|
("> Text", (sy.BlockQuoteToken([sy.TextToken(["Text"])]),), __GLk()),
|
||||||
("> Text with *em* and __underline__", (
|
("> Text with *em* and __underline__", (
|
||||||
sy.BlockQuoteToken([
|
sy.BlockQuoteToken([
|
||||||
sy.TextToken(["Text with"]),
|
sy.TextToken(["Text with"]),
|
||||||
|
|
@ -566,15 +568,15 @@ dict_advanced_syntax_input_and_expected_output = {
|
||||||
sy.TextToken(["underline"]),
|
sy.TextToken(["underline"]),
|
||||||
sy.EtUnderlineToken(["__"]),
|
sy.EtUnderlineToken(["__"]),
|
||||||
]),
|
]),
|
||||||
), __GL()),
|
), __GLk()),
|
||||||
],
|
],
|
||||||
"blockquote_author": [
|
"blockquote_author": [
|
||||||
("> -- Author Name", (
|
("> -- Author Name", (
|
||||||
sy.BlockQuoteAuthorToken(["Author Name"]),
|
sy.BlockQuoteAuthorToken(["Author Name"]),
|
||||||
), __GL()),
|
), __GLk()),
|
||||||
],
|
],
|
||||||
"quotation": [
|
"quotation": [
|
||||||
("> Text", (sy.BlockQuoteToken([sy.TextToken(["Text"])]),), __GL()),
|
("> Text", (sy.BlockQuoteToken([sy.TextToken(["Text"])]),), __GLk()),
|
||||||
("> Text with *em* and __underline__", (
|
("> Text with *em* and __underline__", (
|
||||||
sy.BlockQuoteToken([
|
sy.BlockQuoteToken([
|
||||||
sy.TextToken(["Text with"]),
|
sy.TextToken(["Text with"]),
|
||||||
|
|
@ -586,14 +588,14 @@ dict_advanced_syntax_input_and_expected_output = {
|
||||||
sy.TextToken(["underline"]),
|
sy.TextToken(["underline"]),
|
||||||
sy.EtUnderlineToken(["__"]),
|
sy.EtUnderlineToken(["__"]),
|
||||||
]),
|
]),
|
||||||
), __GL()),
|
), __GLk()),
|
||||||
("> -- Author Name", (
|
("> -- Author Name", (
|
||||||
sy.BlockQuoteAuthorToken(["Author Name"]),
|
sy.BlockQuoteAuthorToken(["Author Name"]),
|
||||||
), __GL()),
|
), __GLk()),
|
||||||
],
|
],
|
||||||
"code": [
|
"code": [
|
||||||
("```\nText\n```", (sy.CodeToken(["```"]),), __GL()),
|
("```\nText\n```", (sy.CodeToken(["```"]),), __GLk()),
|
||||||
("```\nText\nText\n```", (sy.CodeToken(["```"]),), __GL()),
|
("```\nText\nText\n```", (sy.CodeToken(["```"]),), __GLk()),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -666,6 +668,7 @@ list_of_text_input_and_readable_output = [
|
||||||
|
|
||||||
# Other Mostly for testing and coverage
|
# Other Mostly for testing and coverage
|
||||||
("'", "quotes", "'"),
|
("'", "quotes", "'"),
|
||||||
|
(" -", "line", "-"),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -824,7 +827,7 @@ def test_advanced_expression_and_token_creation(markup_element, to_parse, expect
|
||||||
result = expr.parse_string(to_parse)
|
result = expr.parse_string(to_parse)
|
||||||
print()
|
print()
|
||||||
print(f"Parsing string: '{to_parse}'")
|
print(f"Parsing string: '{to_parse}'")
|
||||||
print("Defined at %(filename)s:%(lineno)d" % {'filename': __file__, 'lineno': line_test})
|
print(line_test)
|
||||||
print(f"With expression: '{markup_element}'")
|
print(f"With expression: '{markup_element}'")
|
||||||
print("Defined at %(filename)s:%(lineno)d" % {'filename': __syntax_file,
|
print("Defined at %(filename)s:%(lineno)d" % {'filename': __syntax_file,
|
||||||
'lineno': __definition_of_syntax_elements[markup_element]})
|
'lineno': __definition_of_syntax_elements[markup_element]})
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ def test_counterpart_container(type_n, expected_counterpart, expected_container,
|
||||||
try:
|
try:
|
||||||
token = type_n(["test"]) # noqa
|
token = type_n(["test"]) # noqa
|
||||||
token.line_number = 1
|
token.line_number = 1
|
||||||
|
token.index = 1
|
||||||
assert token.counterpart() == expected_counterpart
|
assert token.counterpart() == expected_counterpart
|
||||||
if expected_container == "error":
|
if expected_container == "error":
|
||||||
with pytest.raises(error_mngr.MismatchedContainerError):
|
with pytest.raises(error_mngr.MismatchedContainerError):
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from bootstraparse.modules import syntax, error_mngr, tools, context_mngr
|
from bootstraparse.modules import syntax # , error_mngr, tools, context_mngr
|
||||||
from bootstraparse.modules.tools import __GL, __module_path, find_variables_in_file
|
# from bootstraparse.modules.tools import __GL, __module_path, find_variables_in_file
|
||||||
|
|
||||||
__XF = pytest.mark.xfail
|
__XF = pytest.mark.xfail
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue