You've already forked onec_codetemplate_parser
mirror of
https://github.com/240596448/onec_codetemplate_parser.git
synced 2025-11-23 21:34:39 +02:00
комментарии, исправления
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
from .core import parse_skobkofile as parser
|
"""Программный интерфейс"""
|
||||||
|
|
||||||
|
from .core import parser as parser
|
||||||
from .core import Root
|
from .core import Root
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
|
"""Консольное приложение для вызова API библиотеки """
|
||||||
|
|
||||||
import typer
|
import typer
|
||||||
from .api import parse_to_src, render_from_src
|
from .api import parse_to_src, render_from_src
|
||||||
|
|
||||||
app = typer.Typer(help="Парсер шаблонов 1С")
|
app = typer.Typer(help="Парсер шаблонов кода 1С (*.st)")
|
||||||
|
|
||||||
@app.command()
|
@app.command()
|
||||||
def parse(path: str, src: str):
|
def parse(path: str, src: str):
|
||||||
"""Разобрать шаблон из 1с-файла *.st в исходники src"""
|
"""Разобрать шаблон из 1с-файла *.st в исходники src"""
|
||||||
result = parse_to_src(path, src)
|
parse_to_src(path, src)
|
||||||
typer.echo(result)
|
|
||||||
|
|
||||||
@app.command()
|
@app.command()
|
||||||
def render(src: str, path: str):
|
def render(src: str, path: str):
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ class Root(Node):
|
|||||||
children.append(child)
|
children.append(child)
|
||||||
return Root(len(children), children)
|
return Root(len(children), children)
|
||||||
|
|
||||||
def parse_skobkofile(text: str) -> Root:
|
def parser(text: str) -> Root:
|
||||||
pos = 0
|
pos = 0
|
||||||
|
|
||||||
def skip_ws():
|
def skip_ws():
|
||||||
@@ -291,7 +291,7 @@ if __name__ == "__main__":
|
|||||||
with open(path, "r", encoding="utf-8-sig", errors="ignore") as f:
|
with open(path, "r", encoding="utf-8-sig", errors="ignore") as f:
|
||||||
text = f.read()
|
text = f.read()
|
||||||
|
|
||||||
root = parse_skobkofile(text)
|
root = parser(text)
|
||||||
print("\n✅ Файл успешно прочитан\n")
|
print("\n✅ Файл успешно прочитан\n")
|
||||||
root.pretty_print()
|
root.pretty_print()
|
||||||
|
|
||||||
|
|||||||
@@ -7,12 +7,12 @@ class Test_Read_Skobkofile:
|
|||||||
assert test_file_path.exists()
|
assert test_file_path.exists()
|
||||||
|
|
||||||
def test_01_parse_eq_compile(self, test_data):
|
def test_01_parse_eq_compile(self, test_data):
|
||||||
root = core.parse_skobkofile(test_data)
|
root = core.parser(test_data)
|
||||||
new_data = root.compile()
|
new_data = root.compile()
|
||||||
assert new_data == test_data
|
assert new_data == test_data
|
||||||
|
|
||||||
def test_02_save_and_read(self, test_data, tmp_path):
|
def test_02_save_and_read(self, test_data, tmp_path):
|
||||||
root = core.parse_skobkofile(test_data)
|
root = core.parser(test_data)
|
||||||
new_data = root.compile()
|
new_data = root.compile()
|
||||||
|
|
||||||
tmp_file = tmp_path / 'tmp.st'
|
tmp_file = tmp_path / 'tmp.st'
|
||||||
@@ -24,7 +24,7 @@ class Test_Read_Skobkofile:
|
|||||||
class Test_Write_To_Files:
|
class Test_Write_To_Files:
|
||||||
|
|
||||||
def test_00_to_file(self, test_data, temp_src):
|
def test_00_to_file(self, test_data, temp_src):
|
||||||
root = core.parse_skobkofile(test_data)
|
root = core.parser(test_data)
|
||||||
root.to_files(temp_src)
|
root.to_files(temp_src)
|
||||||
|
|
||||||
def test_01_to_files(self, temp_src):
|
def test_01_to_files(self, temp_src):
|
||||||
|
|||||||
Reference in New Issue
Block a user