Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions blark/iec.lark
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ _library_element_declaration: data_type_declaration
| ";"

// B.1.1
IDENTIFIER: /[A-Za-z_][A-Za-z0-9_]*/i
// Identifiers need to ignore certain keywords, but NOT typenames, as those may be used
// 'as values' with SIZEOF for example
IDENTIFIER: /\b(?!(ABSTRACT|ACTION|AND|AND_THEN|AT|BY|CASE|CONTINUE|DO|ELSE|ELSIF|END_ACTION|END_CASE|END_FOR|END_FUNCTION|END_FUNCTIONBLOCK|END_FUNCTION_BLOCK|END_IF|END_INTERFACE|END_METHOD|END_PROGRAM|END_PROPERTY|END_REPEAT|END_STRUCT|END_TYPE|END_UNION|END_VAR|END_WHILE|EXIT|EXTENDS|FINAL|FOR|FUNCTION|FUNCTIONBLOCK|FUNCTION_BLOCK|IF|IMPLEMENTS|INTERFACE|INTERNAL|JMP|METHOD|MOD|NOT|OF|OR|OR_ELSE|PERSISTENT|PRIVATE|PROGRAM|PROPERTY|PROTECTED|PUBLIC|READ_ONLY|READ_WRITE|REFERENCE|REPEAT|RETURN|STRUCT|THEN|TO|TYPE|UNION|UNTIL|VAR|VAR_ACCESS|VAR_EXTERNAL|VAR_GLOBAL|VAR_INPUT|VAR_INST|VAR_IN_OUT|VAR_OUTPUT|VAR_STAT|VAR_TEMP|WHILE|XOR)\b)[A-Za-z_][A-Za-z0-9_]*\b/i

// B.1.2
constant.1: time_literal
Expand Down Expand Up @@ -346,7 +348,7 @@ _array_initial_element: expression
| enumerated_value
| array_initialization

structure_type_declaration: structure_type_name_declaration [ extends ] ":" [ indirection_type ] _STRUCT ( structure_element_declaration ";"+ )* _END_STRUCT
structure_type_declaration: structure_type_name_declaration [ extends ] ":" [ indirection_type ] _STRUCT ";"* ( structure_element_declaration ";"+ )* _END_STRUCT

initialized_structure: structure_type_name ":=" structure_initialization

Expand Down Expand Up @@ -445,7 +447,7 @@ fb_decl: fb_decl_name_list ":" function_block_type_name [ ":=" structure_initial

fb_decl_name_list: fb_name ( "," fb_name )*

var_body: ( var_init_decl ";"+ )*
var_body: ";"* ( var_init_decl ";"+ )*

array_var_declaration: var1_list ":" array_specification

Expand Down Expand Up @@ -562,7 +564,7 @@ ACCESS_SPECIFIER: _ABSTRACT
| _INTERNAL
| _FINAL
access_specifier: ACCESS_SPECIFIER+
extends: _EXTENDS DOTTED_IDENTIFIER
extends: _EXTENDS DOTTED_IDENTIFIER ("," DOTTED_IDENTIFIER)*
implements: _IMPLEMENTS DOTTED_IDENTIFIER ("," DOTTED_IDENTIFIER)*

function_block_type_declaration: FUNCTION_BLOCK [ access_specifier ] derived_function_block_name [ extends ] [ implements ] fb_var_declaration* [ function_block_body ] END_FUNCTION_BLOCK ";"*
Expand All @@ -578,6 +580,7 @@ END_FUNCTION_BLOCK: _END_FUNCTION_BLOCK
| input_output_declarations
| external_var_declarations
| var_declarations
| var_inst_declaration
| temp_var_decls
| static_var_declarations
| incomplete_located_var_declarations
Expand All @@ -600,7 +603,7 @@ function_block_method_declaration: _METHOD [ access_specifier ] DOTTED_IDENTIFIE

?property_return_type: _located_var_spec_init

function_block_property_declaration: _PROPERTY [ access_specifier ] DOTTED_IDENTIFIER [ ":" property_return_type ] ";"* property_var_declaration* [ function_block_body ] _END_PROPERTY ";"*
function_block_property_declaration: _PROPERTY [ access_specifier ] DOTTED_IDENTIFIER [ ":" property_return_type ] [ access_specifier ] ";"* property_var_declaration* [ function_block_body ] _END_PROPERTY ";"*

// B.1.5.3
?program_type_name: IDENTIFIER
Expand Down Expand Up @@ -638,7 +641,7 @@ program_access_decl: access_name ":" symbolic_variable ":" non_generic_type_name
| external_var_declarations
| var_declarations

interface_declaration: _INTERFACE IDENTIFIER [ extends ] interface_var_declaration* _END_INTERFACE ";"*
interface_declaration: _INTERFACE IDENTIFIER [ extends ] interface_var_declaration* _END_INTERFACE? ";"*

// B.2.1, B.3.1
LOGICAL_OR: _OR
Expand Down
4 changes: 2 additions & 2 deletions blark/plain.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .input import (BlarkCompositeSourceItem, BlarkSourceItem,
register_input_handler)
from .output import OutputBlock, register_output_handler
from .util import AnyPath, SourceType, find_pou_type_and_identifier
from .util import AnyPath, SourceType, find_pou_type_and_identifier_plain


@dataclasses.dataclass
Expand Down Expand Up @@ -40,7 +40,7 @@ def load(
with open(filename, "rt") as fp:
contents = fp.read()

source_type, identifier = find_pou_type_and_identifier(contents)
source_type, identifier = find_pou_type_and_identifier_plain(contents)
# if source_type is None:
# return []
source_type = SourceType.general
Expand Down
18 changes: 10 additions & 8 deletions blark/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,7 @@ def from_xml(
) -> Self:
declaration = get_child_located_text(xml, "Declaration", filename=filename)
if declaration is not None:
source_type, identifier = util.find_pou_type_and_identifier(
declaration.value
)
source_type, identifier = util.find_pou_type_and_identifier_xml(xml)
else:
source_type, identifier = None, None

Expand All @@ -366,7 +364,7 @@ def from_xml(
implementation=get_child_located_text(
xml, "Implementation/ST", filename=filename
),
metadata=xml.attrib,
metadata=dict(xml.attrib),
source_type=source_type,
filename=filename,
)
Expand Down Expand Up @@ -948,7 +946,11 @@ def to_blark(self) -> list[Union[BlarkCompositeSourceItem, BlarkSourceItem]]:
property_ident = Identifier.from_string(base_decl.identifier)

parts = []
for get_or_set, obj in (("get", self.get), ("set", self.set)):
get_set = [
("get", SourceType.property_get, self.get),
("set", SourceType.property_set, self.set),
]
for get_or_set, source_type, obj in get_set:
if obj is None:
continue

Expand All @@ -961,7 +963,7 @@ def to_blark(self) -> list[Union[BlarkCompositeSourceItem, BlarkSourceItem]]:
parts=[*property_ident.parts, get_or_set],
decl_impl="declaration",
).to_string(),
type=SourceType.property,
type=source_type,
lines=base_decl.lines + decl.lines,
grammar_rule=SourceType.property.get_grammar_rule(),
implicit_end="END_PROPERTY",
Expand All @@ -977,7 +979,7 @@ def to_blark(self) -> list[Union[BlarkCompositeSourceItem, BlarkSourceItem]]:
parts=[*property_ident.parts, get_or_set],
decl_impl="implementation",
).to_string(),
type=SourceType.property,
type=source_type,
lines=impl.lines,
grammar_rule=SourceType.statement_list.get_grammar_rule(),
implicit_end="",
Expand Down Expand Up @@ -1020,7 +1022,7 @@ def from_xml(
xml: lxml.etree.Element,
parent: TcSource,
) -> Self:
return cls(metadata=xml.attrib, xml=xml, parent=parent)
return cls(metadata=dict(xml.attrib), xml=xml, parent=parent)


@dataclasses.dataclass
Expand Down
Loading
Loading