From 037bbf6def9ac5219ff444805eb26b8a28051b71 Mon Sep 17 00:00:00 2001 From: "Odysseas (Ody) Krystalakos" Date: Tue, 19 Nov 2024 17:37:42 +0100 Subject: [PATCH] Change indentation for error sections (#9) * Option to have error section one leven more indented * Allow VAR in parameter definitions --- pyproject.toml | 2 +- rapidchecker/config.py | 1 + rapidchecker/parser/grammar.py | 7 ++++++- rapidchecker/parser/identifiers.py | 2 +- tests/test_grammar.py | 2 +- tests/test_identifiers.py | 1 + uv.lock | 2 +- 7 files changed, 12 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9523d41..f8f12f7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "rapidchecker" -version = "0.1.1" +version = "0.1.2" description = " Grammar and format checker for ABB RAPID code. " readme = "README.md" requires-python = ">=3.10" diff --git a/rapidchecker/config.py b/rapidchecker/config.py index 9b18939..48ccca9 100644 --- a/rapidchecker/config.py +++ b/rapidchecker/config.py @@ -11,6 +11,7 @@ class Config: max_empty_lines: int = 2 require_new_line_eof: bool = True allow_trailing_space: bool = False + indent_error_section: bool = False @classmethod def read_config(cls, config_file: Path) -> "Config": diff --git a/rapidchecker/parser/grammar.py b/rapidchecker/parser/grammar.py index 159a73d..e031676 100644 --- a/rapidchecker/parser/grammar.py +++ b/rapidchecker/parser/grammar.py @@ -1,5 +1,7 @@ import pyparsing as pp +from rapidchecker.config import CONFIG + from . import tokens as T from .identifiers import datatype, identifier, parameter_list, variable from .indent import ( @@ -149,7 +151,10 @@ ) # Proc definition -error_section = T.ERROR - stmt_block +if CONFIG.indent_error_section: + error_section = T.ERROR - INDENT - stmt_block - UNDENT +else: + error_section = INDENT_CHECKPOINT + T.ERROR - stmt_block proc_def = ( T.PROC - identifier diff --git a/rapidchecker/parser/identifiers.py b/rapidchecker/parser/identifiers.py index 8f741f4..b9b4072 100644 --- a/rapidchecker/parser/identifiers.py +++ b/rapidchecker/parser/identifiers.py @@ -16,7 +16,7 @@ parameter = ( pp.Optional("\\") - + pp.Optional(T.INOUT | T.PERS) + + pp.Optional(T.INOUT | T.PERS | T.VAR) + datatype + identifier + elem_index diff --git a/tests/test_grammar.py b/tests/test_grammar.py index 5199d41..a35d495 100644 --- a/tests/test_grammar.py +++ b/tests/test_grammar.py @@ -307,7 +307,7 @@ def test_func_def(input_str: str) -> None: [ "PROC procName()\nENDPROC", "PROC procName(num arg1, \\num arg2, \\switch aa)\n statement;\n statement2;\nENDPROC", - "PROC procName(num arg1, \\num arg2, \\switch aa)\n statement;\n ERROR\n statement2;\nENDPROC", + "PROC procName(num arg1, \\num arg2, \\switch aa)\n statement;\nERROR\n statement2;\nENDPROC", ], ) def test_proc_def(input_str: str) -> None: diff --git a/tests/test_identifiers.py b/tests/test_identifiers.py index 3eef98b..d74a2a4 100644 --- a/tests/test_identifiers.py +++ b/tests/test_identifiers.py @@ -53,6 +53,7 @@ def test_invalid_variable(invalid_variable: str) -> None: "\\INOUT string name{100}", "string name", "\\robtarget target", + "VAR signaldo signal", ], ) def test_parameter(valid_parameter: str) -> None: diff --git a/uv.lock b/uv.lock index 78514fc..123d44a 100644 --- a/uv.lock +++ b/uv.lock @@ -286,7 +286,7 @@ wheels = [ [[package]] name = "rapidchecker" -version = "0.1.1" +version = "0.1.2" source = { virtual = "." } dependencies = [ { name = "click" },