Skip to content

Commit

Permalink
Change indentation for error sections (#9)
Browse files Browse the repository at this point in the history
* Option to have error section one leven more indented

* Allow VAR in parameter definitions
  • Loading branch information
OdysseasKr authored Nov 19, 2024
1 parent 1bc7972 commit 037bbf6
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
1 change: 1 addition & 0 deletions rapidchecker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
7 changes: 6 additions & 1 deletion rapidchecker/parser/grammar.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rapidchecker/parser/identifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions tests/test_identifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 037bbf6

Please sign in to comment.