raesl.compile
¶
ESL compiler.
Compiles ESL documents and workspaces, meaning:
- Parsing lines
- Typechecking
- Building an AST
- Instantiating components, variables and requirements.
- Deriving dependencies from these to build an output graph (network).
EslCompilationError
¶
Bases: Exception
Error during ESL compilation.
to_graph
¶
to_graph(
*paths: Union[str, Path],
output: Optional[Union[str, Path]] = None,
force: bool = False
) -> Graph
Convert ESL file(s) into a :obj:ragraph.graph.Graph
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
paths
|
Union[str, Path]
|
Paths to resolve into ESL files. May be any number of files and directories to scan. |
()
|
output
|
Optional[Union[str, Path]]
|
Optional output file (JSON) to write the graph to. |
None
|
force
|
bool
|
Whether to overwrite the output file or raise an error if it the file already exists. |
False
|
Returns:
Type | Description |
---|---|
Graph
|
Instantiated graph. |
Source code in src/raesl/compile/__init__.py
ast
¶
Abstract Syntax Tree elements for ESL.
comment_storage
¶
Code for handling documentation comments in AST objects.
The code has two main concepts, namely DocStore which expresses the capability to find elements that can store doc comments, and DocAddElement which expresses the capability to actually store such comments.
In general thus, storing a doc comment thus involves two steps. First the correct element is searched based on a supplied (possibly dotted) name, then the comment is actually stored if an element could be found.
As the above is pretty minimal, several additional classes exist. - The DocElement can both store comments and also provide them again. (Compound element can't store comments, but forward them to their children and thus have no way to retrieve the comments given to them.) - The DefaultDocElement implements DocElement. - The DefaultDocStore implements a DocStore as well as DocElement for non-dotted names, providing a simple way to add doc comment storage to many of the language elements.
Internally, some more classes exist.
-
The ProxyDocStore that acts as DocStore elsewhere in the specification. Its primary use is in comment sections, pointing to the actual elements to receive the doc comments of the section.
-
The DummyElement acts as a DocStore for any doc comment, and reports a warning about them being ignored. These elements act as barrier and guard against doc comments being added to a previous element where that should not happen. For example, doc comments after a 'define type' line, should not be added to the definitions above that line.
-
Finally, DocCommentDistributor implements the distribution of doc comments to all elements of the specification after type-checking has been performed.
DefaultDocElement
¶
Bases: DocElement
Default implementation for storing and retrieving doc comments.
Attributes:
Name | Type | Description |
---|---|---|
comments |
List[str]
|
The comments themselves, non-empty text after dropping the leading '#<' and surrounding white-space. |
Source code in src/raesl/compile/ast/comment_storage.py
DefaultDocStore
¶
DefaultDocStore(doc_tok: Optional[Token])
Bases: DocStore
, DefaultDocElement
Class that can store and retrieve doc-comments for non-dotted names.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
doc_tok
|
Optional[Token]
|
Token defining the position of the element in the input for documenting. Documentation comments after this position and before any other existing DocStore.doc_tok will be attached to this element. |
required |
Source code in src/raesl/compile/ast/comment_storage.py
DocAddElement
¶
DocCommentDistributor
¶
DocCommentDistributor(diag_store: DiagnosticStore)
Class for assigning documentation comments to relevant elements in the specification.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
diag_store
|
DiagnosticStore
|
Storage for reported diagnostics. |
required |
Attributes:
Name | Type | Description |
---|---|---|
elements |
List[DocStore]
|
Elements interested in receiving documentation comments. |
dummy_elements |
List[DummyElement]
|
Elements that catch documentation comments without a proper home, for warning the user about such comments. |
Source code in src/raesl/compile/ast/comment_storage.py
add_dummy_element
¶
add_dummy_element(
doc_tok: Token, report_errors: bool = True
)
Insert a dummy element based on the provided token.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
doc_tok
|
Token
|
Token that defines the position of the dummy element. |
required |
report_errors
|
bool
|
Whether to report errors for comments that get attached to the dummy element. |
True
|
Source code in src/raesl/compile/ast/comment_storage.py
add_element
¶
add_element(element: DocStore)
Add the provided element to the elements interested in getting doc comments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
element
|
DocStore
|
Element to add. |
required |
resolve
¶
resolve(doc_comments: List[Token])
Distribute the provided documentation comments to the interested elements, and report any documentation comments that get assigned in a DummyElement, as those are at the wrong spot in the specification.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
doc_comments
|
List[Token]
|
Documentation comments found in the input specification. |
required |
Source code in src/raesl/compile/ast/comment_storage.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 |
|
DocElement
¶
Bases: DocAddElement
Interface class of an element that can store and retrieve doc comments.
DocStore
¶
DocStore(doc_tok: Optional[Token])
Interface class that can find where to store doc comments for a given name. If doc_tok is None, the element does not get any documentation comments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
doc_tok
|
Optional[Token]
|
Token defining the position of the element in the input for documenting. Documentation comments after this position and before any other existing DocStore.doc_tok will be attached to this element. |
required |
Source code in src/raesl/compile/ast/comment_storage.py
get_error_position
¶
Return the index in the given string where an error occurs in resolving the name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the element to find. |
required |
Returns:
Type | Description |
---|---|
int
|
Approximated index in the string where matching the element fails. Returned value has no meaning if resolving succeeds. |
Source code in src/raesl/compile/ast/comment_storage.py
resolve_element
¶
resolve_element(name: str) -> Optional[DocAddElement]
Try to find the documentation element indicated by its (dotted) name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the element to find. |
required |
Returns:
Type | Description |
---|---|
Optional[DocAddElement]
|
The documentation element associated with the provided name if it can be resolved. |
Source code in src/raesl/compile/ast/comment_storage.py
DummyElement
¶
DummyElement(doc_tok: Token, report_errors: bool = True)
Bases: DocStore
, DocElement
Class for catching documentation elements that have no proper owner. Used for reporting warnings that such documentation is ignored.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
doc_tok
|
Token
|
Token defining the position of the element in the input for documenting. Documentation comments after this position and before any other existing DocStore.doc_tok will be attached to this element. |
required |
report_errors
|
bool
|
Whether to add errors to the problem storage. |
True
|
Source code in src/raesl/compile/ast/comment_storage.py
report
¶
report(diag_store: DiagnosticStore)
Report a warning about all received documentation comments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
diag_store
|
DiagnosticStore
|
Storage for reported diagnostics. |
required |
Source code in src/raesl/compile/ast/comment_storage.py
ProxyDocStore
¶
Bases: DocStore
Proxy element that represents a real DocStore element except at a different position in the specification. This is useful in 'comment' sections where names of elements are provided that exist elsewhere in the component.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
doc_tok
|
Token
|
Token defining the position of the element in the input for documenting. Documentation comments after this position and before any other existing DocStore.doc_tok will be attached to this element. |
required |
real_element
|
DocStore
|
Real element which is symbolically at the 'doc_tok' position, too. |
required |
Source code in src/raesl/compile/ast/comment_storage.py
decode_doc_comments
¶
decode_doc_comments(comment_tok: Token) -> List[str]
Convert a doc comment token to the containing description text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comment_tok
|
Token
|
Token with the documentation comment. |
required |
Returns:
Type | Description |
---|---|
List[str]
|
The text (for as far as it exists). |
Source code in src/raesl/compile/ast/comment_storage.py
components
¶
Component definitions with their contents.
BehaviorCase
¶
BehaviorCase(
name_tok: Token,
conditions: List[BehaviorCondition],
results: List[BehaviorResult],
)
A set of desired behavioral results given a set of conditions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_tok
|
Token
|
Name of the behavior case. |
required |
conditions
|
List[BehaviorCondition]
|
Conditions that should hold for the case to apply. |
required |
results
|
List[BehaviorResult]
|
Results that should hold when the case applies. |
required |
Source code in src/raesl/compile/ast/components.py
BehaviorCondition
¶
BehaviorCondition(
name_tok: Token,
comparison: Union[Disjunction, RelationComparison],
)
BehaviorFunction
¶
BehaviorFunction(behavior_kind: str, name_tok: Token)
Bases: DefaultDocStore
One function specifying some behavior.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
behavior_kind
|
str
|
Kind of behavior. Either 'requirement' or 'constraint'. |
required |
name_tok
|
Token
|
Name of the behavior. |
required |
Attributes:
Name | Type | Description |
---|---|---|
cases |
List[BehaviorCase]
|
Behavior cases. |
default_results |
Optional[List[BehaviorResult]]
|
Results that hold when none of the cases applies. None means there is no default result. |
Source code in src/raesl/compile/ast/components.py
BehaviorResult
¶
BehaviorResult(name_tok: Token, result: Comparison)
ComponentDefinition
¶
Bases: DefaultDocStore
ESL component definition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pos_tok
|
Token
|
Position of the definition. Either the name token or the 'world' token. |
required |
name_tok
|
Optional[Token]
|
Token with the name of the component definition, None means 'world'. |
required |
Attributes:
Name | Type | Description |
---|---|---|
variables |
List[VarParam]
|
Variables of the component definition. |
parameters |
List[VarParam]
|
Parameters of the component definition. |
var_groups |
List[VariableGroup]
|
Groups of variables with a name. |
component_instances |
List[ComponentInstance]
|
Component instances of the component definition. |
needs |
List[Need]
|
Needs of the component definition. |
goals |
List[Goal]
|
Goals of the component definition. |
transforms |
List[Transformation]
|
Transformations of the component definition. |
designs |
List[Design]
|
Designs of the component definition. |
relations |
List[RelationInstance]
|
Relation instances of the component definition. |
behaviors |
List[BehaviorFunction]
|
Behavior functions of the component definition. |
Source code in src/raesl/compile/ast/components.py
ComponentInstance
¶
Bases: DefaultDocStore
ESL component instance in a component definition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inst_name_tok
|
Token
|
Token with the name of the component instance. |
required |
def_name_tok
|
Token
|
Token withe the name of the component definition to apply. |
required |
Attributes:
Name | Type | Description |
---|---|---|
arguments |
List[InstanceArgument]
|
Arguments of the instance. |
compdef |
Optional[ComponentDefinition]
|
Component definition matching the name in 'def_name_tok', if it exists. Set during type checking. |
Source code in src/raesl/compile/ast/components.py
Design
¶
Design(label_tok: Token, expr: Expression)
Bases: DefaultDocStore
Design rule in a component.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
label_tok
|
Token
|
Name of the design rule. |
required |
expr
|
Expression
|
Condition expressed in the design. |
required |
Attributes:
Name | Type | Description |
---|---|---|
design_kind |
Optional[str]
|
Kind of the design, filled in after construction. Contains either 'requirement' or 'constraint'. |
sub_clauses |
List[SubClause]
|
Sub-clauses of the design. |
Source code in src/raesl/compile/ast/components.py
Flow
¶
Flow(name_tok: Token)
Goal
¶
Goal(
label_tok: Token,
active: Token,
doesaux: Token,
verb: Token,
flows: List[Flow],
prepos: Token,
passive: Token,
)
Bases: DefaultDocStore
Goal in an ESL component definition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
label_tok
|
Token
|
Label name of the goal. |
required |
active
|
Token
|
Token with the name of the active component. |
required |
doesaux
|
Token
|
'does' or auxiliary word token. |
required |
verb
|
Token
|
Verb of the goal. |
required |
flows
|
List[Flow]
|
Flows of the goal. |
required |
prepos
|
Token
|
Token with the preposition word. |
required |
passive
|
Token
|
Token with the name of the passive component. |
required |
Attributes:
Name | Type | Description |
---|---|---|
goal_kind |
Optional[str]
|
Kind of goal, filled after construction. Either 'requirement' or 'constraint' string. |
sub_clauses |
List[SubClause]
|
Sub-clauses of the goal. |
active_comp |
Optional[ComponentInstance]
|
If not None, resolved active component instance of the goal. |
passive_comp |
Optional[ComponentInstance]
|
If not None, resolved passive component instance of the goal. |
Source code in src/raesl/compile/ast/components.py
InstanceArgument
¶
Need
¶
Bases: DefaultDocStore
Informal need in ESL.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
label_tok
|
Token
|
Token with the name of the label. |
required |
subject_tok
|
Token
|
Token with the name of the subject of the need. |
required |
description
|
str
|
Description of the need. |
required |
Attributes:
Name | Type | Description |
---|---|---|
subject |
Optional[NeedSubjectTypes]
|
If not None, subject of the need. |
Source code in src/raesl/compile/ast/components.py
RelationInstance
¶
RelationInstance(
inst_name_tok: Token,
def_name_tok: Token,
arguments: List[List[InstanceArgument]],
reldef: Optional[RelationDefinition],
)
Bases: DefaultDocStore
ESL relation instance in a component definition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inst_name_tok
|
Token
|
Token with the name of the relation instance. |
required |
def_name_tok
|
Token
|
Token withe the name of the relation definition to apply. |
required |
arguments
|
List[List[InstanceArgument]]
|
Arguments of the instance. One element for each parameter, where one element may have several arguments due to the 'one or more' feature. |
required |
reldef
|
Optional[RelationDefinition]
|
Relation definition of this instance. |
required |
Source code in src/raesl/compile/ast/components.py
SubClause
¶
SubClause(label_tok: Token, expr: Expression)
Subclause in a goal, transformation, or behavior.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
label_tok
|
Token
|
Name of the subclause. |
required |
expr
|
Expression
|
Expression describing the subclause. |
required |
Source code in src/raesl/compile/ast/components.py
Transformation
¶
Transformation(
label_tok: Token,
doesaux_tok: Token,
verb_tok: Token,
in_flows: List[Flow],
prepos_tok: Token,
out_flows: List[Flow],
)
Bases: DefaultDocStore
Transformation in a component.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
label_tok
|
Token
|
Label name of the transformation. |
required |
doesaux_tok
|
Token
|
'does' or aux word token. |
required |
verb_tok
|
Token
|
Verb of the transformation. |
required |
in_flows
|
List[Flow]
|
Inputs required for the transformation. |
required |
prepos_tok
|
Token
|
Preposition of the transformation. |
required |
out_flows
|
List[Flow]
|
Outputs resulting from the transformation. |
required |
Attributes:
Name | Type | Description |
---|---|---|
transform_kind |
Optional[str]
|
Kind of transformation, filled after construction. Either 'requirement' or 'constraint' string. |
sub_clauses |
List[SubClause]
|
Sub-clauses of the transformation. |
Source code in src/raesl/compile/ast/components.py
VarParam
¶
Bases: DocStore
ESL component definition variable or parameter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
is_variable
|
bool
|
Whether the object represents a variable. |
required |
name_tok
|
Token
|
Token with the name of the variable being defined. |
required |
type_tok
|
Token
|
Token with the name of the type of the variable being defined. |
required |
is_property
|
bool
|
Whether the parameter is a property. |
False
|
Attributes:
Name | Type | Description |
---|---|---|
type |
Optional[BaseType]
|
Type of the variable, if it exists. Set during type checking. |
Source code in src/raesl/compile/ast/components.py
get_error_position
¶
Return the index in the given string where an error occurs in resolving the node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the element to find. |
required |
Returns:
Type | Description |
---|---|
int
|
Approximated index in the string where matching the element fails. |
int
|
Returned value has no meaning if resolving a node succeeds. |
Source code in src/raesl/compile/ast/components.py
resolve_node
¶
resolve_node(name: str) -> Optional[VarNode]
Find the varparam (sub) node that matches the dotted 'name'.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Possibly dotted name that should point at an existing sub-node. The empty string denotes 'self'. |
required |
Returns:
Type | Description |
---|---|
Optional[VarNode]
|
The node that matches the name, or None if no such node exists. In the latter case, use 'self.get_error_position(name)' to get an indication where the match fails in the name. |
Source code in src/raesl/compile/ast/components.py
VariableGroup
¶
One variable group in ESL (a named group of variables).
It has no documentation comment, as its only purpose is to enable interfacing to child components.
As a variable group doesn't need to contain uniquely named variables, their names cannot be used to build a Compound type. Therefore, it just stays a group, and it gets dealt with in component instantiation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_tok
|
Token
|
Token with the name of the group being defined. |
required |
variablepart_names
|
List[Token]
|
Tokens with possibly dotted name of variable parts in the group. |
required |
Attributes:
Name | Type | Description |
---|---|---|
node |
Optional[Node]
|
Node representing the group, if available. |
Source code in src/raesl/compile/ast/components.py
get_doc_comment_comp_elements
¶
get_doc_comment_comp_elements(
comp: ComponentDefinition,
) -> Generator[DocStore, None, None]
Retrieve the component elements interested in getting documentation comments from the input. This includes the component itself, so you can add documentation to it in its 'comments' section.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comp
|
ComponentDefinition
|
Component definition to search. |
required |
Returns:
Type | Description |
---|---|
None
|
Generator yielding interested elements. |
Source code in src/raesl/compile/ast/components.py
exprs
¶
Expressions to store and reason about values and boundaries.
Comparison
¶
Bases: Expression
Class storing a comparison.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
is_constraint
|
bool
|
Whether the comparison is considered to be a constraint rather than a requirement. |
required |
Source code in src/raesl/compile/ast/exprs.py
DataValue
¶
Some kind of data value. Do not use this, but use a derived class instead.
get_units
¶
Obtain the units of the value. Gives a set of names without square brackets where lack of units results in the empty set, and not supporting units gives None.
Returns:
Type | Description |
---|---|
Optional[Set[str]]
|
Names of the available units without square brackets or None. |
Source code in src/raesl/compile/ast/exprs.py
Disjunction
¶
Disjunction(childs: Sequence[Expression])
Bases: Expression
Disjunctive expression (also known as 'or' expression). It is true iff at least one of it child expressions is true.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
childs
|
Sequence[Expression]
|
Child expressions of the disjunction. It is recommended to have at least two children in an object. |
required |
Source code in src/raesl/compile/ast/exprs.py
Expression
¶
Base class of an expression.
ObjectiveComparison
¶
ObjectiveComparison(
lhs_var: VariableValue, aux_tok: Token, maximize: bool
)
Bases: Comparison
An intended direction for a variable. Note that the 'maximize' parameter controls both the 'maximize' and 'minimize' desires.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lhs_var
|
VariableValue
|
Variable with the objective. |
required |
aux_tok
|
Token
|
One of the auxiliary verbs expressing strength of the objective. |
required |
maximize
|
bool
|
If set the comparison expresses the desire to maximize the variable. |
required |
Attributes:
Name | Type | Description |
---|---|---|
minimize |
bool
|
Opposite of maximize. |
Source code in src/raesl/compile/ast/exprs.py
RelationComparison
¶
RelationComparison(
is_constraint: bool,
lhs_var: VariableValue,
isaux_tok: Token,
cmp_tok: Token,
rhs_varval: DataValue,
)
Bases: Comparison
A relation between a variable and either a value or a variable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
is_constraint
|
bool
|
Whether the comparison is considered to be a constraint rather than a requirement. |
required |
lhs_var
|
VariableValue
|
Left hand side variable being compared. |
required |
isaux_tok
|
Token
|
'is' for a constraint, else the aux word for expressing strength of the comparison. |
required |
cmp_tok
|
Token
|
One of the key words that expression the comparison to perform. |
required |
rhs_varval
|
DataValue
|
Right hand side variable or value. |
required |
Attributes:
Name | Type | Description |
---|---|---|
math_compare |
Translated 'cmp_tok', with the ascii math text. |
Source code in src/raesl/compile/ast/exprs.py
Value
¶
Bases: DataValue
A value with an optional unit. Don't modify these objects in-place, create a new object instead.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
Token
|
Stored value as text. |
required |
unit
|
Optional[Token]
|
Either None or text describing the unit. Treat as read-only, as changing it may break the cache. |
None
|
Attributes:
Name | Type | Description |
---|---|---|
_unit_cache |
Optional[Set[str]]
|
Units of the literal after normalizing self.unit. Computed on demand. |
Source code in src/raesl/compile/ast/exprs.py
VariableValue
¶
VariableValue(var_tok: Token)
Bases: DataValue
Class representing a variable or parameter as value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
var_tok
|
Token
|
Token stating the possibly dotted name of the variable. |
required |
Attributes:
Name | Type | Description |
---|---|---|
var_node |
Optional[VarNode]
|
If not None, the node represented by the object. Set during type checking. |
Source code in src/raesl/compile/ast/exprs.py
nodes
¶
Node classes representing elementary and combined flows.
CompoundVarNode
¶
Bases: VarNode
, DocAddElement
Grouped variable/parameter node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_tok
|
Token
|
Token with the name/position of the variable or parameter. |
required |
the_type
|
BaseType
|
Type of the variable or parameter. |
required |
child_nodes
|
List[VarNode]
|
Child nodes of the group. |
required |
Attributes:
Name | Type | Description |
---|---|---|
name_index |
Mapping of name to the associated VarNode instance. |
Source code in src/raesl/compile/ast/nodes.py
ElementaryVarNode
¶
Bases: VarNode
, DocElement
Elementary variable/parameter node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_tok
|
Token
|
Token with the name/position of the variable or parameter. |
required |
the_type
|
BaseType
|
Type of the variable or parameter. |
required |
counter
|
Counter
|
Object to give out unique identification numbers, yet be resistant against re-use of imported modules. |
required |
Attributes:
Name | Type | Description |
---|---|---|
id |
Unique number of the node, mostly useful for dumps and debugging. |
|
comments |
List[str]
|
Stored comments of the node. |
Source code in src/raesl/compile/ast/nodes.py
GroupNode
¶
Bases: Node
Class describing content of a variable group. Unlike the VarNode above, a group node has no type of its own.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_tok
|
Token
|
Name of the group node. |
required |
child_nodes
|
List[Node]
|
Elements of the group. |
required |
Source code in src/raesl/compile/ast/nodes.py
VarNode
¶
Bases: Node
Abstract base class of a variable or parameter node that can be shared with variable groups and other users such as transformations and goals.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_tok
|
Token
|
Token with the name/location of the variable or parameter. |
required |
the_type
|
BaseType
|
Type of the variable or parameter. |
required |
Source code in src/raesl/compile/ast/nodes.py
add_comment
¶
add_comment(comment_tok: Token)
Add found documentation comment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comment_tok
|
Token
|
The raw documentation token to add. |
required |
get_error_position
¶
Return the index in the given string where an error occurs in resolving the node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the element to find. |
required |
Returns:
Type | Description |
---|---|
int
|
Approximated index in the string where matching the element fails. Returned value has no meaning if resolving a node succeeds. |
Source code in src/raesl/compile/ast/nodes.py
resolve_node
¶
resolve_node(name: str) -> Optional[VarNode]
Find the varparam (sub)node that matches the provided dotted 'name'.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Possibly dotted name that should point at an existing sub-node. The empty string denotes 'self'. |
required |
Returns:
Type | Description |
---|---|
Optional[VarNode]
|
The node that matches the name, or None if no such node exists. In the latter case, use 'self.get_error_position(name)' to get an indication where the match fails in the name. |
Source code in src/raesl/compile/ast/nodes.py
relations
¶
Relation definition and instantiation.
RelationDefParameter
¶
Parameter of a relation definition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
Token
|
Name of the parameter. |
required |
type_name
|
Token
|
Name of the type of the parameter. |
required |
direction
|
str
|
Direction of the parameter. |
required |
multi
|
bool
|
If set, parameter may be specified more than once. |
required |
Attributes:
Name | Type | Description |
---|---|---|
type |
Optional[BaseType]
|
Actual type of the parameter. |
Source code in src/raesl/compile/ast/relations.py
RelationDefinition
¶
RelationDefinition(name: Token)
Bases: DefaultDocStore
Relation definition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
Token
|
Name of the relation definition. |
required |
Attributes:
Name | Type | Description |
---|---|---|
params |
List[RelationDefParameter]
|
Parameters of the definition. |
Source code in src/raesl/compile/ast/relations.py
specification
¶
Overall output specification.
Specification
¶
Main class.
Attributes:
Name | Type | Description |
---|---|---|
types |
Dict[str, TypeDef]
|
Types of the specification. |
verb_prepos |
List[VerbPreposDef]
|
Verbs and pre-positions. |
rel_defs |
List[RelationDefinition]
|
Relation definitions. |
comp_defs |
List[ComponentDefinition]
|
Component definitions. |
world |
Optional[ComponentDefinition]
|
Root component. |
Source code in src/raesl/compile/ast/specification.py
dump
¶
dump(
spec: Specification,
output_stream: Optional[TextIO] = None,
)
Dump the provided specification to an output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spec
|
Specification
|
Specification to dump. |
required |
output_stream
|
Optional[TextIO]
|
Stream to write to, None means stdout. |
None
|
Source code in src/raesl/compile/ast/specification.py
get_doc_comment_spec_elements
¶
get_doc_comment_spec_elements(
spec: Specification,
) -> Generator[DocStore, None, None]
Retrieve the specification elements interested in getting documentation comments from the input.
Component definitions are added through components
get_doc_comment_comp_elements
The implementation is highly knowledgeable about data structure here with
respect to the implementation.
Source code in src/raesl/compile/ast/specification.py
unfold_disjunction
¶
unfold_disjunction(expr: Expression) -> List[Expression]
Convert the child expressions of top-level disjunction expressions to a list.
Source code in src/raesl/compile/ast/specification.py
types
¶
AST storage of types.
BaseType
¶
Base class of a type.
get_units
¶
Retrieve the units that may be used with values of the type.
Returns:
Type | Description |
---|---|
Optional[Set[str]]
|
Set of unit names, set(['-']) if it has no units specified, or None if the type doesn't support units. |
Source code in src/raesl/compile/ast/types.py
Compound
¶
Compound(fields: List[CompoundField])
Bases: BaseType
A collection of named typed values. Note that a Compound cannot have parents, units, or intervals.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fields
|
List[CompoundField]
|
Fields of the compound. |
required |
Source code in src/raesl/compile/ast/types.py
CompoundField
¶
ElementaryType
¶
ElementaryType(
parent: Optional[ElementaryType],
units: List[Token],
intervals: Optional[
List[Tuple[Optional[Value], Optional[Value]]]
],
)
Bases: BaseType
A type of a singular value in ESL. The allowed values in a parent type always have priority over the allowed values in a child type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parent
|
Optional[ElementaryType]
|
Parent elementary type if specified. |
required |
units
|
List[Token]
|
Allowed units of the type, should not have square brackets around the text. |
required |
intervals
|
Optional[List[Tuple[Optional[Value], Optional[Value]]]]
|
Disjunction of allowed ranges of the type, pairs of (lowerbound, upperbound) where one of the bounds may be None. Constants and enumerations are expressed as intervals with the same lower and upper bound. |
required |
Source code in src/raesl/compile/ast/types.py
verbs
¶
Verb / preposition definitions in ESL.
VerbPreposDef
¶
Bases: DefaultDocStore
A verb and a pre-position definition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
verb
|
Token
|
Verb token. |
required |
prepos
|
Token
|
Pre-position token. |
required |
Source code in src/raesl/compile/ast/verbs.py
cli
¶
ESL compiler Command Line Interface.
compile
¶
Run the ESL compiler.
Source code in src/raesl/compile/cli.py
run
¶
run(
*paths: Union[str, Path],
output: Optional[Union[str, Path]] = None,
force: bool = False,
files: Optional[Union[List[str], List[Path]]] = None
) -> Tuple[
DiagnosticStore,
Optional[Specification],
Optional[Graph],
]
Run the compiler on ESL files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
paths
|
Union[str, Path]
|
Paths to resolve into ESL files. May be any number of files and directories to scan. |
()
|
output
|
Optional[Union[str, Path]]
|
Optional output file (JSON) to write the graph to. |
None
|
force
|
bool
|
Whether to overwrite the output file or raise an error if the file already exists. |
False
|
files
|
Optional[Union[List[str], List[Path]]]
|
Optional paths argument (deprecated). |
None
|
Returns:
Type | Description |
---|---|
DiagnosticStore
|
Diagnostic storage. |
Optional[Specification]
|
Specification object (if successfully parsed). |
Optional[Graph]
|
Instantiated graph (if successfully instantiated). |
Source code in src/raesl/compile/cli.py
diagnostics
¶
ESL compiler Diagnostics.
Diagnostic code scheme:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
DiagnosticStore
¶
Storage of found diagnostics.
Attributes:
Name | Type | Description |
---|---|---|
diagnostics |
List[EslDiagnostic]
|
Stored diagnostics. |
severity |
What diagnostics to log. |
|
exit |
Exit on error. |
Source code in src/raesl/compile/diagnostics.py
dump
¶
Dump all stored diagnostics to the given stream.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
test
|
bool
|
Whether to output in test mode (otherwise: user-friendly). |
False
|
stream
|
Optional[IO[str]]
|
Output stream to use. Defaults to stdout. |
None
|
Source code in src/raesl/compile/diagnostics.py
has_severe
¶
report
¶
report(diagnostic: EslDiagnostic)
Report a single diagnostic.
Source code in src/raesl/compile/diagnostics.py
EslDiagnostic
¶
EslDiagnostic(
message: str,
location: Location = get_location(),
severity: DiagnosticSeverity = ERROR,
code: str = "E100",
source: str = "RaESL compiler",
related_information: List[
DiagnosticRelatedInformation
] = None,
)
Bases: Diagnostic
An unscoped diagnostic as ESL works with multiple text documents at once.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message
|
str
|
The diagnostic's message. |
required |
location
|
Location
|
The location at which the message applies. |
get_location()
|
severity
|
DiagnosticSeverity
|
The diagnostic's severity. Can be omitted. If omitted it is up to the client to interpret diagnostics as error, warning, info or hint. |
ERROR
|
code
|
str
|
The diagnostic's code, which might appear in the user interface. |
'E100'
|
source
|
str
|
A human-readable string describing the source of this diagnostic, e.g. 'esl', or 'esl compiler'. |
'RaESL compiler'
|
related_information
|
List[DiagnosticRelatedInformation]
|
A list of related diagnostic information, e.g. when symbol-names within a scope collide you can mark all definitions via this property. |
None
|
Attributes:
Name | Type | Description |
---|---|---|
range |
The range at which the message applies. |
Source code in src/raesl/compile/diagnostics.py
E100
¶
E100(location: Location = get_location()) -> EslDiagnostic
Unexpected end of the specification.
Source code in src/raesl/compile/diagnostics.py
E101
¶
E101(
acceptors: Iterable[str],
location: Location = get_location(),
) -> EslDiagnostic
Best line match is ambiguous. Found multiple acceptors: {ambi_acceptors}. This is an internal error.
Source code in src/raesl/compile/diagnostics.py
E102
¶
E102(location: Location = get_location()) -> EslDiagnostic
E200
¶
E200(
name: str,
kind: str,
location: Location = get_location(),
dupes: Optional[List[Location]] = None,
) -> EslDiagnostic
Multiple {kind} named '{name}'.
Source code in src/raesl/compile/diagnostics.py
E201
¶
E201(
section: str,
context: str,
location: Location = get_location(),
) -> EslDiagnostic
This '{section}' section is not allowed in the '{context}' context.
Source code in src/raesl/compile/diagnostics.py
E202
¶
E202(
kind: str,
name: Optional[str] = None,
location: Location = get_location(),
) -> EslDiagnostic
Missing {kind} for '{name}'.
Source code in src/raesl/compile/diagnostics.py
E203
¶
E203(
kind: str,
name: Optional[str] = None,
location: Location = get_location(),
) -> EslDiagnostic
Unknown {kind} named '{name}'.
Source code in src/raesl/compile/diagnostics.py
E204
¶
E204(
name: str,
kind: str,
location: Location = get_location(),
cycle: Optional[List[Location]] = None,
)
Cyclically dependent {kind} named '{name}'.
Source code in src/raesl/compile/diagnostics.py
E205
¶
E205(
name: str,
context: str,
location: Location = get_location(),
) -> EslDiagnostic
Cannot find {name} in {context}.
Source code in src/raesl/compile/diagnostics.py
E206
¶
E206(
name: str,
kind: str,
location: Location = get_location(),
blocks: Optional[List[Location]] = None,
) -> EslDiagnostic
Found {kind} block(s), but the relation definition {name} has no such parameters.
Source code in src/raesl/compile/diagnostics.py
E207
¶
E207(
name: str,
kind: str,
location: Location = get_location(),
definition: Location = get_location(),
) -> EslDiagnostic
Relation instance '{name}' is missing a '{kind}' parameters section.
Source code in src/raesl/compile/diagnostics.py
E208
¶
E208(
name: str,
kind: str,
num: int,
location: Location = get_location(),
definition: Location = get_location(),
) -> EslDiagnostic
Relation instance '{name}' is missing at least {num} '{kind}' parameters.
Source code in src/raesl/compile/diagnostics.py
E209
¶
E209(
name: str,
kind: str,
other_kind: str,
location: Location = get_location(),
others: Optional[List[Location]] = None,
) -> EslDiagnostic
'{name}' is both a {kind} and a {other_kind}.
Source code in src/raesl/compile/diagnostics.py
E210
¶
E210(
lhs: Location,
rhs: Location,
reason: str = "are not compatible",
) -> EslDiagnostic
Values cannot be compared, they {reason}.
Source code in src/raesl/compile/diagnostics.py
E211
¶
E211(
verb: str,
preposition: str,
location: Location = get_location(),
) -> EslDiagnostic
Unsupported verb-preposition combination '{verb} {preposition}'.
Source code in src/raesl/compile/diagnostics.py
E212
¶
E212(
kind: str,
value: str,
allowed: str,
name: Optional[str] = None,
location: Location = get_location(),
) -> EslDiagnostic
{kind.capitalize()} '{name}' uses '{value}', but should use {allowed}.
Source code in src/raesl/compile/diagnostics.py
E213
¶
E213(
kind: str,
num: int,
allowed: str,
location: Location = get_location(),
occurrences: Optional[List[Location]] = None,
) -> EslDiagnostic
Found {num} {kind}(s), but there should be {allowed}.
Source code in src/raesl/compile/diagnostics.py
E214
¶
E214(
name: str,
location: Location = get_location(),
def_location: Optional[Location] = None,
) -> EslDiagnostic
Definition of type '{name}' failed with an error.
Source code in src/raesl/compile/diagnostics.py
E215
¶
E215(
name: str, location: Location = get_location()
) -> EslDiagnostic
Type name '{name}' must be the name of an elementary type.
Source code in src/raesl/compile/diagnostics.py
E216
¶
E216(
name: str, location: Location = get_location()
) -> EslDiagnostic
Unit '{name}' should not have square brackets around it's name.
Source code in src/raesl/compile/diagnostics.py
E217
¶
E217(location: Location = get_location()) -> EslDiagnostic
The dimensionless unit '-' is not allowed to be specified explicitly.
Source code in src/raesl/compile/diagnostics.py
E218
¶
E218(
name: str, location: Location = get_location()
) -> EslDiagnostic
Standard type '{name}' cannot be overridden.
Source code in src/raesl/compile/diagnostics.py
E219
¶
E219(
name: str, location: Location = get_location()
) -> EslDiagnostic
Unit '{name}' is not allowed here.
Source code in src/raesl/compile/diagnostics.py
E220
¶
E220(
name: str,
kind: str,
location: Location = get_location(),
) -> EslDiagnostic
Element '{name}' does not match with a {kind}.
Source code in src/raesl/compile/diagnostics.py
E221
¶
E221(
kind: str,
num: int,
expected: int,
location: Location = get_location(),
references: Optional[List[Location]] = None,
) -> EslDiagnostic
Number of {kind}s does not match. Found {num}, expected {expected}.
Source code in src/raesl/compile/diagnostics.py
E222
¶
E222(
name: str,
other: str,
location: Location = get_location(),
other_loc: Location = get_location(),
) -> EslDiagnostic
Value '{name}' has additional value restrictions relative to '{other}'.
Source code in src/raesl/compile/diagnostics.py
E223
¶
E223(
name: str,
other: str,
kind: str,
location: Location = get_location(),
other_loc: Optional[Location] = None,
) -> EslDiagnostic
'{name}' is not a {kind} of {other}.
Source code in src/raesl/compile/diagnostics.py
E224
¶
E224(
kind: str,
unsupported: str,
location: Location = get_location(),
) -> EslDiagnostic
{kind.capitalize()}s do not support {unsupported}.
Source code in src/raesl/compile/diagnostics.py
E225
¶
E225(
part: str,
first_part: str,
kind: str,
location: Location = get_location(),
) -> EslDiagnostic
Cannot resolve '.{part}' part of the '{first_part}' {kind}.
Source code in src/raesl/compile/diagnostics.py
E226
¶
E226(
name: str, location: Location = get_location()
) -> EslDiagnostic
Need '{name}' is not allowed to reference a bundle.
Source code in src/raesl/compile/diagnostics.py
E227
¶
E227(
name: str,
scope: str,
location: Location = get_location(),
dupes: Optional[List[Location]] = None,
) -> EslDiagnostic
Multiple identifier '{name}' within '{cdef_name}'.
Source code in src/raesl/compile/diagnostics.py
E228
¶
E228(
lhs: Location,
rhs: Location,
reason: str = "are not compatible",
) -> EslDiagnostic
Values cannot be compared, design rule {reason}.
Source code in src/raesl/compile/diagnostics.py
E400
¶
E400(
name: str,
location: Location = get_location(),
owners: Optional[List[Location]] = None,
) -> EslDiagnostic
Elementary variable value '{name}' has more than one property owner.
Source code in src/raesl/compile/diagnostics.py
W200
¶
W200(
name: str,
kind: str,
location: Location = get_location(),
dupes: Optional[List[Location]] = None,
) -> EslDiagnostic
{kind.capitalize()} '{name}' has been specified multiple times.
Source code in src/raesl/compile/diagnostics.py
W300
¶
W300(
element: Optional[str] = None,
location: Location = get_location(),
comments: Optional[List[Location]] = None,
) -> EslDiagnostic
Documentation comment(s) could not be assigned to '{element}'.
Source code in src/raesl/compile/diagnostics.py
esl_lines
¶
State machines to recognize lines of ESL.
get_all_line_machines
¶
get_all_line_machines() -> List[StateMachine]
get_line_machine
¶
get_line_machine(name: str) -> ProcessingStateMachine
Retrieve a line matcher state machine by name.
get_line_machine_names
¶
instantiating
¶
Instantiating module to build the output graph.
edge_building
¶
Edge building for the instantiated output graph.
Reference: https://ratio-case.gitlab.io/docs/reference/esl_reference/dependency-derivations.html
EdgeFactory
¶
EdgeFactory(
diag_store: DiagnosticStore,
node_store: Optional[NodeStore] = None,
)
Source code in src/raesl/compile/instantiating/edge_building.py
make_edges
¶
Derive edges from a :obj:NodeStore
object.
Source code in src/raesl/compile/instantiating/edge_building.py
EdgeStore
¶
Edge storage with multiple categories for quicker access to specific subsets.
Source code in src/raesl/compile/instantiating/edge_building.py
graph_building
¶
Functions for instantiating the component tree.
GraphFactory
¶
GraphFactory(
diag_store: DiagnosticStore,
spec: Optional[Specification] = None,
)
Graph factory class.
Converts a specification into a graph containing a node hierarchy and edges for derived dependencies between nodes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
diag_store
|
DiagnosticStore
|
Storage for found diagnostics during the process. |
required |
Attributes:
Name | Type | Description |
---|---|---|
node_factory |
Factory that parses spec into Node objects. |
|
edge_factory |
Factory that derives edges from found Node objects. |
Source code in src/raesl/compile/instantiating/graph_building.py
make_graph
¶
make_graph(
spec: Optional[Specification] = None,
) -> Optional[Graph]
Instantiate the tree defined in the specification, and build a graph for it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spec
|
Optional[Specification]
|
Specification object holding parsed ESL data. |
None
|
Returns:
Type | Description |
---|---|
Optional[Graph]
|
None if no root is available, else the constructed graph. |
Note
Problems may be reported during instantiation and added to self.diag_store.
Source code in src/raesl/compile/instantiating/graph_building.py
graph_data
¶
Classes for the instantiated component graph.
InstNode
¶
InstNode(name: str, variable: VarParam)
Instance node that connects one or more elementary nodes that are connected through parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Dotted variable name of the associated elementary type. |
required |
variable
|
VarParam
|
Variable that created the node. |
required |
Attributes:
Name | Type | Description |
---|---|---|
number |
Unique number for each instance nodes, mostly useful for debugging. |
|
params |
List[VarParam]
|
Parameters connected to the variable through this node. |
comments |
List[str]
|
Comments from the connected variable and parameters. |
Source code in src/raesl/compile/instantiating/graph_data.py
node_building
¶
Methods for casting ESL AST into ragraph.node.Node objects.
NodeFactory
¶
NodeFactory(
diag_store: DiagnosticStore,
spec: Optional[Specification] = None,
)
Node factory. Creates :obj:Node
objects from a :obj:Specification
.
Source code in src/raesl/compile/instantiating/node_building.py
make_nodes
¶
make_nodes(
spec: Optional[Specification] = None,
) -> Dict[str, Node]
Instantiate AST and create :obj:Node
objects accordingly.
Source code in src/raesl/compile/instantiating/node_building.py
NodeStore
¶
Node storage with multiple catagories for quicker access to specific subsets.
Source code in src/raesl/compile/instantiating/node_building.py
make_behavior_node
¶
make_behavior_node(
b: BehaviorFunction,
inst_name: str,
inst_map: Dict[ElementaryVarNode, InstNode],
) -> Node
Behavior spec node creation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
b
|
BehaviorFunction
|
The behavior specification for which a node must be created. |
required |
inst_name
|
str
|
The instantiation name of the component. |
required |
inst_map
|
Dict[ElementaryVarNode, InstNode]
|
Dictionary containing the instantiated variables. |
required |
Returns:
Type | Description |
---|---|
Node
|
Node of kind "behavior_spec". |
Source code in src/raesl/compile/instantiating/node_building.py
make_component_node
¶
make_component_node(
c: ComponentInstance,
inst_name: str,
params: Dict[ElementaryVarNode, InstNode],
) -> Node
Node creation for a component.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
c
|
ComponentInstance
|
The component for which a node is created. |
required |
inst_name
|
str
|
The instantiation name of the node. |
required |
params
|
Dict[ElementaryVarNode, InstNode]
|
List of parameters of the component. |
required |
Returns:
Type | Description |
---|---|
Node
|
Node of kind "component" |
Source code in src/raesl/compile/instantiating/node_building.py
make_design_node
¶
make_design_node(
d: Design,
inst_name: str,
inst_map: Dict[ElementaryVarNode, InstNode],
) -> Node
Design spec node creation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
d
|
Design
|
The design specification for which a node must be created. |
required |
inst_name
|
str
|
The instantiation name of the component. |
required |
inst_map
|
Dict[ElementaryVarNode, InstNode]
|
Dictionary containing the instantiated variables. |
required |
Returns:
Type | Description |
---|---|
Node
|
Node of kind "design_spec". |
Source code in src/raesl/compile/instantiating/node_building.py
make_goal_node
¶
make_goal_node(
g: Goal,
inst_name: str,
inst_map: Dict[ElementaryVarNode, InstNode],
) -> Node
Goal node creation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g
|
Goal
|
The goal for which a node must be created. |
required |
inst_name
|
str
|
The instantiation name of the component. |
required |
inst_map
|
Dict[ElementaryVarNode, InstNode]
|
Dictionary containing the instantiated variables. |
required |
Returns:
Type | Description |
---|---|
Node
|
Node of kind "function". |
Source code in src/raesl/compile/instantiating/node_building.py
make_need_node
¶
Node creation for a component.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n
|
Need
|
The need for which a node must be created. |
required |
inst_name
|
str
|
The instation name of the need. |
required |
Returns:
Type | Description |
---|---|
Node
|
Node of kind "need" |
Source code in src/raesl/compile/instantiating/node_building.py
make_parameter_instmap
¶
make_parameter_instmap(
param: VarParam,
param_node: VarNode,
arg_node: VarNode,
parent_inst_map: Dict[ElementaryVarNode, InstNode],
) -> Dict[ElementaryVarNode, InstNode]
Construct an inst node map for a parameter of a child component instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
param
|
VarParam
|
Parameter definition in the child component definition. |
required |
param_node
|
VarNode
|
VarNode within the parameter in the child component definition. Note these are like variables in the child. |
required |
arg_node
|
VarNode
|
Node in the parent that must match with param_node. These nodes exist in the parent component, and may contain part of a variable group. |
required |
parent_inst_map
|
Dict[ElementaryVarNode, InstNode]
|
Variable instance map of the parent. As component instantiation is recursive, this may also include nodes from the grand-parent or higher. Should not be modified. |
required |
Returns:
Type | Description |
---|---|
Dict[ElementaryVarNode, InstNode]
|
Instance node map for a parameter. |
Source code in src/raesl/compile/instantiating/node_building.py
make_relation_node
¶
make_relation_node(
r: RelationInstance,
inst_name: str,
inst_map: Dict[ElementaryVarNode, InstNode],
) -> Node
Relation spec node creation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
r
|
RelationInstance
|
The relation specification for which a node must be created. |
required |
inst_name
|
str
|
The instantiation name of the component. |
required |
inst_map
|
Dict[ElementaryVarNode, InstNode]
|
Dictionary containing the instantiated variables. |
required |
Returns:
Type | Description |
---|---|
Node
|
Node of kind "relation_spec". |
Source code in src/raesl/compile/instantiating/node_building.py
make_transform_node
¶
make_transform_node(
t: Transformation,
inst_name: str,
inst_map: Dict[ElementaryVarNode, InstNode],
) -> Node
Transformation node creation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t
|
Transformation
|
The transformation for which a node must be created. |
required |
inst_name
|
str
|
The instantiation name of the component. |
required |
inst_map
|
Dict[ElementaryVarNode, InstNode]
|
Dictionary containing the instantiated variables. |
required |
Returns:
Type | Description |
---|---|
Node
|
Node of kind "function_spec". |
Source code in src/raesl/compile/instantiating/node_building.py
make_type_node
¶
Node creation for a type definition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tdef
|
TypeDef
|
Type definition for which a node most be created. |
required |
Returns:
Type | Description |
---|---|
Node
|
Node of kind |
Source code in src/raesl/compile/instantiating/node_building.py
make_variable_instmap
¶
make_variable_instmap(
var: VarParam, varname: List[str], node: VarNode
) -> Dict[ElementaryVarNode, InstNode]
Construct instance nodes for the provided variable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
var
|
VarParam
|
Variable represented by the node. |
required |
varname
|
List[str]
|
Collected prefixes of the dotted name so far. |
required |
node
|
VarNode
|
Node to associate with one or more inst nodes. |
required |
Returns:
Type | Description |
---|---|
Dict[ElementaryVarNode, InstNode]
|
Map of the elementary variable nodes to their associated instance nodes. |
Source code in src/raesl/compile/instantiating/node_building.py
make_variable_node
¶
make_variable_node(
v: InstNode,
type_inst_map: Dict[ElementaryType, TypeDef],
) -> Node
Node creation for a variable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
v
|
InstNode
|
The variable for which a nodes must be created. |
required |
Returns:
Type | Description |
---|---|
Node
|
Node of kind "variable". |
Source code in src/raesl/compile/instantiating/node_building.py
post_process_comments
¶
post_process_comments(nodes: List[Node]) -> None
Post-processing comments attached to nodes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nodes
|
List[Node]
|
List of nodes for which the comments must be post-processed. |
required |
Note
This is a simple implementation to process documentation tags as described in LEP0008.
Source code in src/raesl/compile/instantiating/node_building.py
machine_files
¶
State machine files for recognizing lines and ESL.
collect_line_machines
¶
collect_line_machines() -> (
Dict[str, ProcessingStateMachine]
)
Construct and collect all available line machine, and return them.
Source code in src/raesl/compile/machine_files/__init__.py
argument_list
¶
Line matcher for argument lists.
Note this file is imported from other machine files rather than providing argument list processing itself.
process_argument_list_line
¶
behavior
¶
Line matchers for the behavior section.
builder
¶
Code to construct line matching state machines.
The entry point to create a state machine is calling 'create' on a StateMachineBuilder instance.
A state machine has locations and edges.
One location in a machine may have an 'initial' option denoting it is the first location of the machine. Locations may also be accepting, denoting it is a proper end state. The accepting option takes a name, making it possible to distinguish which end location of the state machine was reached.
Edges start at a location and end at a location. Edges have a token-name, and may only be chosen when the input has a token with the same name. An edge may also have a tag option. The tag-name represents what kind of relevant token it is. When an edge is taken with a tag-name, the token matching with the edge is appended to a list associated with the tag-name. In this way, it is possible to extract relevant information from the matched sentence afterwards.
State machine execution assumes the machine is deterministic. From a location, each outgoing edge must have a different token-name. Note that a scanner may not map unique text to a token. The latter is resolved by sorting the edges from most specific token-name to least specific token-name.
In general, writing code to build locations and edges is bulky and hard to understand. Instead a text format is defined to allow writing the state machines as text, and let the computer build the state machine from the description. The text format accepted by the builder is:
1 2 3 4 5 6 7 8 |
|
Locations in 'loc-def' must not exist already. Missing locations in 'edge-def' are silently created. Token names are defined in parsing/scanner.py.
ProcessingStateMachine
¶
Bases: StateMachine
Extended StateMachine that also holds a callback function to add extracted parsing information into the ast.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the state machine, also the name of the matched sequence. |
required |
processing_func
|
Optional[ProcessingFunc]
|
If not None, function that inserts relevant information from the matched line into the ast that is constructed. |
None
|
Source code in src/raesl/compile/machine_files/builder.py
StateMachineBuilder
¶
Class for easily constructing a state machine from a textual description.
Attributes:
Name | Type | Description |
---|---|---|
lexer |
Lexer to tokenize the input text. |
|
parser |
Parser to interpret the tokens. |
|
machine |
State machine to be built. |
|
locs |
Temporary location map filled while building the state machine. |
Source code in src/raesl/compile/machine_files/builder.py
create
¶
create(
machine_text: str,
processing_func: Optional[ProcessingFunc] = None,
) -> ProcessingStateMachine
Create a state machine by interpreting the provided state machine text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
machine_text
|
str
|
Description of the state machine as defined by StateMachineLexer and StateMachineParser. |
required |
processing_func
|
Optional[ProcessingFunc]
|
Optional processing function to copy relevant information into the abstract syntax tree. |
None
|
Returns:
Type | Description |
---|---|
ProcessingStateMachine
|
The state machine that implements the description. |
Source code in src/raesl/compile/machine_files/builder.py
create_loc
¶
create_loc(
name: str,
opts: List[Union[Tuple[str], Tuple[str, str]]],
) -> Location
Create a new location.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the location to create. |
required |
opts
|
List[Union[Tuple[str], Tuple[str, str]]]
|
Location options, list of ('initial',) and/or ('accept', str) . |
required |
Returns:
Type | Description |
---|---|
Location
|
The created location. |
Source code in src/raesl/compile/machine_files/builder.py
ensure_loc
¶
ensure_loc(name: str) -> Location
Make sure a location with the provided name exists. If it doesn't, create it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the location to ensure. |
required |
Returns:
Type | Description |
---|---|
Location
|
The location with the provided name. |
Source code in src/raesl/compile/machine_files/builder.py
StateMachineLexer
¶
Bases: Lexer
Lexer for tokenizing state machine descriptions.
Note that SLY and pylint are known not to like each other.
comments
¶
Line matcher state machines for comments.
component_definitions
¶
Line matcher state machines for transformations.
component_instances
¶
Line matchers for component instances within world or a component definition.
designs
¶
Line matcher state machines for designs.
goals
¶
Line matcher state machines for goals.
groups
¶
Line matching state machines for groups.
machine_parts
¶
Library with common parts of line matchers.
get_argument_references_part
¶
get_argument_references_part(
start_loc: str,
end_1locs: List[str],
tagname: str,
prefix: str = "",
) -> str
State machine part implementing the 'argument-references' rule.
argument-references ::= argument-name { and-connector argument-name }
and-connector ::= "and" | "," | "," "and"
Source code in src/raesl/compile/machine_files/machine_parts.py
get_auxiliary_verb_part
¶
Part implementing the 'auxiliary-verb' rule.
auxiliary-verb ::= "shall" | "must" | "should" | "could" | "won't"
Source code in src/raesl/compile/machine_files/machine_parts.py
get_compare_op_part
¶
State machine part implementing the 'compare-op' rule.
compare-op ::= "smaller" "than" | "greater" "than" | "not" "equal" "to" | "equal" "to" | "at" "least" | "at" "most" | "approximately"
Source code in src/raesl/compile/machine_files/machine_parts.py
get_disjunctive_comparison_part
¶
State machine part implementing the 'comparison-rule-line' comparisons.
comparison-rule-line ::= comparison { "or" comparison }
comparison ::= argument-name ( constraint-rule-literal | requirement-rule-literal )
constraint-rule-literal ::= "is" compare-op bound
requirement-rule-literal ::= auxiliary-verb "be" ( compare-op bound | objective )
compare-op ::= "smaller" "than" | "greater" "than" | "not" "equal" "to" | "equal" "to" | "at" "least" | "at" "most" | "approximately"
bound ::= argument-name | VALUE [ UNIT ] | "t.b.d." [ UNIT ]
objective ::= "maximized" | "minimized"
Source code in src/raesl/compile/machine_files/machine_parts.py
get_does_auxiliary_verb_part
¶
State machine part that implements:
"does" | auxiliary-verb
Source code in src/raesl/compile/machine_files/machine_parts.py
get_is_auxiliary_verb_part
¶
get_is_auxiliary_verb_part(
start_loc: str,
end_1locs: List[str],
tagname: str,
prefix: str = "",
) -> str
State machine part implementing:
"is" | auxiliary-verb "be"
Source code in src/raesl/compile/machine_files/machine_parts.py
needs
¶
Line matcher state machines needs.
parameters
¶
Line matcher state machines for parameters.
relation_definitions
¶
Line matcher state machines of relation definitions.
relation_instances
¶
Line matcher state machines for relation instances.
sub_clause
¶
Line matcher for sub-clause lines.
decode_disjunctive_comparisons
¶
decode_disjunctive_comparisons(
tags: Dict[str, List[Token]]
) -> Expression
Decode tags of a matched 'machine_parts.get_disjunctive_comparison_part' part to an disjunction with comparisons.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tags
|
Dict[str, List[Token]]
|
Extracted data from a match of the machine defined in 'machine_parts.get_disjunctive_comparison_part'. |
required |
Returns:
Type | Description |
---|---|
Expression
|
The expression equivalent to the matched text. |
Source code in src/raesl/compile/machine_files/sub_clause.py
decode_subclause
¶
Decode tags of a matched subclauses line to one or more disjunctive equations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tags
|
Dict[str, List[Token]]
|
Extracted data from a match of the machine defined in SUB_CLAUSE_SPEC. |
required |
Returns:
Type | Description |
---|---|
SubClause
|
The found subclause. |
Source code in src/raesl/compile/machine_files/sub_clause.py
guess_is_var
¶
guess_is_var(varvalue: Token) -> bool
Guess whether the provided token is a variable or a value. (Answer: If it is not "t.b.d." and starts with a letter it's a variable.)
Source code in src/raesl/compile/machine_files/sub_clause.py
transforms
¶
Line matcher state machines for transformations.
type_defs
¶
Line matcher state machines for type definitions.
get_constant_specification_part
¶
State machine part implementing the 'constant-specification' rule.
constant-specification ::= "equal" "to" VALUE [ UNIT ]
Source code in src/raesl/compile/machine_files/type_defs.py
get_enumeration_specification_part
¶
State machine part implementing the 'enumeration-specification' rule.
enumeration-specification ::= "is" "an" "enumeration" "of" VALUE [ UNIT ] { "," VALUE [ UNIT ]}
Source code in src/raesl/compile/machine_files/type_defs.py
get_interval_specification_part
¶
State machine part implementing the 'interval-specification' rule.
interval-specification ::= "of" interval { "or" interval }
Source code in src/raesl/compile/machine_files/type_defs.py
get_short_enumeration_specification_part
¶
get_short_enumeration_specification_part(
start_loc: str, end_2locs: List[str], prefix: str = ""
) -> str
State machine part implementing the short 'enumeration-specification' rule.
short-enumeration-specification ::= "enumeration" "of" VALUE [ UNIT ] { "," VALUE [ UNIT ]}
Source code in src/raesl/compile/machine_files/type_defs.py
get_unit_specification_part
¶
State machine part implementing the 'unit-specification' rule.
unit-specification ::= "with" ( "unit" | "units" ) UNIT-NAME { "," UNIT-NAME }
Source code in src/raesl/compile/machine_files/type_defs.py
typing
¶
Typing support for the machines data.
utils
¶
Utility functions.
get_one
¶
Filter tokens on the provided start and end offsets, and return the only token between the positions.
Source code in src/raesl/compile/machine_files/utils.py
get_optional
¶
get_optional(
tokens: List[Token],
start_offset: Optional[int],
end_offset: Optional[int],
) -> Optional[Token]
Filter tokens on the provided start and end offsets, and return the only token between the positions.
Source code in src/raesl/compile/machine_files/utils.py
make_loc_names
¶
Make a dict with 'count' names by combining the prefix, name, and a number.
Source code in src/raesl/compile/machine_files/utils.py
variables
¶
Line matcher state machines for variable declarations.
verb_defs
¶
Line matcher state machines for verb and pre-position definitions.
parser
¶
Parsing the Elephant Specification Language.
LineMachineStepper
¶
LineMachineStepper(
machine: ProcessingStateMachine,
lexer: Lexer,
dest_loc: Location,
)
Class managing parsing of a line in ESL.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
machine
|
ProcessingStateMachine
|
Line matching machine to use for recognizing the line. |
required |
lexer
|
Lexer
|
Lexer to use in the matching process. |
required |
dest_loc
|
Location
|
New specification location if a match was found. |
required |
Attributes:
Name | Type | Description |
---|---|---|
current_loc |
Optional[Location]
|
Current location in the line machine. |
tags |
Dict[str, List[Token]]
|
Relevant data extracted from the text line during the parsing process. |
matched_tokens |
List[Token]
|
Tokens used for matching the line thus far. |
Source code in src/raesl/compile/parser.py
get_accept_name
¶
Get the acceptance name associated with the accepting location.
Returns:
Type | Description |
---|---|
str
|
Name of the accepted 'rule'. |
Source code in src/raesl/compile/parser.py
is_accepting
¶
try_step
¶
Try to match the next token.
Returns:
Type | Description |
---|---|
bool
|
Whether progress was made. |
Source code in src/raesl/compile/parser.py
collect_locations
¶
Collect the set reachable states from 'spec_state' without taking only 'epsilon' transitions.
Source code in src/raesl/compile/parser.py
parse_lexer
¶
parse_lexer(
lexer: Lexer,
diag_store: Optional[DiagnosticStore],
builder: Optional[AstBuilder],
doc_comments: Optional[List[Token]],
) -> Tuple[DiagnosticStore, AstBuilder, List[Token], bool]
Parse an ESL lexer, storing collected information in the builder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lexer
|
Lexer
|
Lexer pointing at the start of the specification text. |
required |
diag_store
|
Optional[DiagnosticStore]
|
Diagnostic store if one already has been created. |
required |
builder
|
Optional[AstBuilder]
|
Builder if one already has been created. |
required |
doc_comments
|
Optional[List[Token]]
|
Doc comments if any have been found yet. |
required |
Returns:
Type | Description |
---|---|
DiagnosticStore
|
Diagnostic store instance. |
AstBuilder
|
Builder instance. |
List[Token]
|
Found doc comments. |
bool
|
Whether there has been an error. |
Source code in src/raesl/compile/parser.py
parse_line
¶
parse_line(
spec_state: Location,
lexer: Lexer,
builder: AstBuilder,
diag_store: DiagnosticStore,
) -> Tuple[Optional[Location], Optional[Lexer]]
Parse a text-line in ESL.
For debugging line selection, set scanner.PARSER_DEBUG to True, which enables printing debug information to the std output. For best results, use a small input specification, output is quite verbose.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spec_state
|
Location
|
Location in the ESL language state machine. |
required |
lexer
|
Lexer
|
Lexer pointing at the start of the next line to match. |
required |
builder
|
AstBuilder
|
Class storing extracted parse data. |
required |
diag_store
|
DiagnosticStore
|
Storage for reported diagnostics. |
required |
Returns:
Type | Description |
---|---|
Optional[Location]
|
Next state in the ESL state machine unless successfully finished, next lexer to |
Optional[Lexer]
|
use if next step can be performed. |
Source code in src/raesl/compile/parser.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
|
parse_spec
¶
parse_spec(
lexers: Iterable[Lexer],
diag_store: Optional[DiagnosticStore] = None,
) -> Tuple[DiagnosticStore, Optional[Specification]]
Parse an ESL specification, storing collected information in the builder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lexers
|
Iterable[Lexer]
|
Lexers pointing at the start of their respective texts (e.g. per-file). |
required |
Returns:
Type | Description |
---|---|
Tuple[DiagnosticStore, Optional[Specification]]
|
The found diagnostics, and if successful, the type-checked output. |
Source code in src/raesl/compile/parser.py
scanner
¶
Lexer for on-demand recognition of tokens.
As the language has unrestrained text in its needs, lexing beforehand is not going to work in all cases. Instead, the scanner tries to match tokens on demand.
Also there is overlap in matching between tokens (a NONSPACE expression matches almost all other tokens as well, and a NAME expression matches all keywords). The rule applied here (by means of sorting edges in the state machines) is that specific wins from generic. For example, if at some point both the OR_KW and the NONSPACE token may be used, and the text is "or", the OR_KW token is chosen.
Lexer
¶
Lexer(
fname: Optional[str],
text: str,
offset: int,
line_offset: int,
line_num: int,
doc_comments: List[Token],
)
On-demand scanner.
For debugging token matching, enable the PARSER_DEBUG flag near the top of the file. That also enables debug output in the parser.parse_line to understand what line is being tried, and which line match steppers are running.
Arguments; fname: Name of the file containing the text, may be None. text: Input text. length: Length of the text. offset: Offset of the current position in the text. line_offset: Offset of the first character of the current line in the input text. line_num: Line number of the current line. doc_comments: Documentation comments found so far, shared between all scanners.
Source code in src/raesl/compile/scanner.py
find
¶
find(tok_type: str) -> Optional[Token]
Try to find the requested token.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tok_type
|
str
|
Type name of the token. |
required |
Returns:
Type | Description |
---|---|
Optional[Token]
|
Found token, or None. |
Source code in src/raesl/compile/scanner.py
get_linecol
¶
Get line and column information of the next token. Note that as new-lines are significant, such a position may be at an unexpected place, for example at the end of a comment.
Returns:
Type | Description |
---|---|
Tuple[int, int]
|
Line and column information of the next token. |
Source code in src/raesl/compile/scanner.py
get_location
¶
get_location() -> Location
Get location information of the next token. Note that such a position may be at an unexpected place since new-lines are significant. For example, it may be at the end of a comment.
Returns:
Type | Description |
---|---|
Location
|
Location information of the next token. |
Source code in src/raesl/compile/scanner.py
skip_white
¶
Skip white space, triple dots, newlines, and comments. Implements the following Graphviz diagram:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
is a significant token, so it is not skipped everywhere.
Source code in src/raesl/compile/scanner.py
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 |
|
Token
¶
Token(
tok_type: str,
tok_text: str,
fname: Optional[str],
offset: int,
line_offset: int,
line_num: int,
)
Data of a matched token.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tok_type
|
str
|
Type name of the token. |
required |
tok_text
|
str
|
Text of the token. |
required |
fname
|
Optional[str]
|
Name of the file containing the text. |
required |
offset
|
int
|
Offset of the current position in the input text. |
required |
line_offset
|
int
|
Offset of the first character of the current line in the input text. |
required |
line_num
|
int
|
Line number of the current line. |
required |
Source code in src/raesl/compile/scanner.py
get_location
¶
get_location(offset: int = 0) -> Location
Get this token's Location.
Source code in src/raesl/compile/scanner.py
get_token_priority
¶
Priority of the tokens. Higher value is less specific.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tok_type
|
str
|
Name of the token type. |
required |
Returns:
Type | Description |
---|---|
int
|
Priority of the token. |
Source code in src/raesl/compile/scanner.py
state_machine
¶
State machine classes to describe an allowed sequences of tokens.
A state machine is a DFA (deterministic finite automaton, always at most one edge that matches). An edge is associated with a matched token, locations are decision points between tokens.
An edge may tag occurrences of tokens to simplify extraction of relevant information for future compiler phases. A location may record matching of a valid sequence of tokens by accepting.
Edge
¶
Edge(
dest: Location,
tok_type: str,
tag_name: Optional[str] = None,
)
Edge to a next location.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dest
|
Location
|
Destination of the edge. |
required |
tok_type
|
str
|
The value of the 'tok_type' attribute of a token that can trigger this transition. |
required |
tag_name
|
Optional[str]
|
If not None, the name to use for recording the transition in the state machine. |
None
|
Source code in src/raesl/compile/state_machine.py
Location
¶
Location in a state machine.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
accept
|
Optional[str]
|
Name of the rule that could be accepted at this location. If None, no such rule exists. |
None
|
name
|
str
|
Name of the location, mostly for identifying purposes. |
required |
Attributes:
Name | Type | Description |
---|---|---|
out_edges |
List[Edge]
|
Outgoing edges, initially empty. |
Source code in src/raesl/compile/state_machine.py
MatchResult
¶
Result data of a matching process in StateMachine.match().
Parameters:
Name | Type | Description | Default |
---|---|---|---|
accepted_name
|
Optional[str]
|
Acceptance name from the last visited accepting location. |
required |
accepted_tags
|
Dict[str, List[Token]]
|
Collected tag data at the point of accepting. |
required |
lexer
|
Lexer
|
Lexer at the time of the last fail or at the time of the last accept |
required |
Source code in src/raesl/compile/state_machine.py
StateMachine
¶
State machine containing locations and edges.
Note that it only stores the initial location, all other locations and edges are reachable from it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the state machine, also the name of the matched sequence. |
required |
Attributes:
Name | Type | Description |
---|---|---|
initial_loc |
Optional[Location]
|
Initial location of the state machine. Set after construction. |
Source code in src/raesl/compile/state_machine.py
dump
¶
Dump the state machine to a file in Graphviz format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fname
|
Optional[str]
|
If not None, name of the file to write, else a filename is constructed from the name of the state machine. |
None
|
Source code in src/raesl/compile/state_machine.py
match
¶
match(lexer: Lexer) -> Optional[MatchResult]
Try to match the machine against tokens from the scanner.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lexer
|
Lexer
|
Token stream to match. Instance is useless afterwards, make a copy beforehand if you need it again. |
required |
Returns:
Type | Description |
---|---|
Optional[MatchResult]
|
Result of the matching process. |
Note
This routine is currently only used for testing.
Source code in src/raesl/compile/state_machine.py
single_step
¶
single_step(
lexer: Lexer,
current_loc: Location,
tags: Dict[str, List[Token]],
) -> Optional[Tuple[Location, Token]]
Try to perform a single step in the state machine.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lexer
|
Lexer
|
Token stream to match. Instance is modified in-place if a transition is taken. |
required |
current_loc
|
Location
|
Location to use for finding edges to try. |
required |
tags
|
Dict[str, List[Token]]
|
Collected tags so far, may be updated in-place if transition was performed. |
required |
Returns:
Type | Description |
---|---|
Optional[Tuple[Location, Token]]
|
New location and the matching token if a transition could be performed, |
Optional[Tuple[Location, Token]]
|
else None. |
Source code in src/raesl/compile/state_machine.py
sort_edges
¶
Sort edges of the state machine to get specific tokens checked first.
Source code in src/raesl/compile/state_machine.py
typechecking
¶
Type checking for ESL.
ast_builder
¶
Classes to collect and store information from the parsing process, perform checking on the information for being correct, and construct an AST as result along with a log of found diagnostics.
The AstBuilder operates at top section level (types, verbs, relation definitions, and component definitions). It leaves all the details of each section to dedicated child builders (thus creating a highly modular checker), and acts as call dispatcher and global controller in the type-checking and ast building process once parsing has finished.
Notable parts in the class are - Child builders for each top section part. - Diagnostics store shared with all the child builders. - Storage of doc-comments in the input for attaching them to the correct parts of the produced specification after parsing. - Call dispatcher for the child builders that a new top or sub-section has been found, allowing them to clean up processing if needed. - Entry points for the parser to push found information to the child builders. - The 'finish_parse' entry point to perform all type checking, and produce the AST and found diagnostics.
AstBuilder
¶
AstBuilder(diag_store: DiagnosticStore)
Builder to collect information from the parse process, perform type checking, and produce an AST and reported diagnostics.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
diag_store
|
DiagnosticStore
|
Storage for diagnostics while building the AST. |
required |
Attributes:
Name | Type | Description |
---|---|---|
doc_distributor |
Object that distributes doc comments to interested elements of the specification. |
|
section_notify_list |
List[Union[TypeBuilder, RelationDefBuilder, ComponentDefBuilder]]
|
Builders to notify of a new section. |
type_builder |
Builder for constructing types. |
|
verb_builder |
Builder for constructing verb/prepositions. |
|
reldef_builder |
Builder for constructing relations. |
|
compdef_builder |
Builder for constructing components. |
Source code in src/raesl/compile/typechecking/ast_builder.py
add_bundle_field
¶
add_typedef
¶
add_typedef(
type_name: Token,
parent_name: Optional[Token],
enum_spec: Optional[List[Value]],
unit_spec: Optional[List[Token]],
ival_spec: Optional[
List[Tuple[Optional[Value], Optional[Value]]]
],
cons_spec: Optional[Value],
)
Forward call to type builder.
Source code in src/raesl/compile/typechecking/ast_builder.py
add_verbdef
¶
finish_parse
¶
finish_parse(
doc_comments: List[Token],
) -> Optional[Specification]
Finish processing the collected information, that is, perform type checking.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
doc_comments
|
List[Token]
|
Raw documentation comments rescued from the scanner. |
required |
Source code in src/raesl/compile/typechecking/ast_builder.py
notify_new_section
¶
notify_new_section(
tok: Optional[Token], new_top_section: bool
)
Parser has started a new section, finish all 'in-progress' definitions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tok
|
Optional[Token]
|
Token indicating the position of the new section. None is used for EOF. |
required |
new_top_section
|
bool
|
If set, a new type, verbs, or component definition has been found, else a new section within a component has been detected. |
required |
Source code in src/raesl/compile/typechecking/ast_builder.py
register_new_section
¶
Entry point for a child builder to declare interest in receiving notifications about new sections in the file.
reldef_add_param
¶
Forward call to relation definition builder.
compdef_behavior_builder
¶
Code for collecting and adding behavior sections to component definitions.
CompDefBehaviorBuilder
¶
CompDefBehaviorBuilder(
comp_child_builders: CompDefChildBuilders,
)
Class for constructing and checking behavior functions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comp_child_builders
|
CompDefChildBuilders
|
Storage of child builders for a component definition. |
required |
Attributes:
Name | Type | Description |
---|---|---|
behavior_kind |
Optional[str]
|
Last seen kind of behavior ('requirement' or 'constraint'). |
expect_conds |
Whether the builder should allow conditions to be received from the parser. |
|
expect_results |
Whether the builder should allow results to be received from the parser. |
|
pbehaviors |
List[ParsedBehavior]
|
Collected behaviors. |
Source code in src/raesl/compile/typechecking/compdef_behavior_builder.py
behavior_case
¶
behavior_case(case_label_tok: Token)
A new case of the last started behavior functionality was found.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
case_label_tok
|
Token
|
Name of the case. |
required |
Source code in src/raesl/compile/typechecking/compdef_behavior_builder.py
behavior_default_when
¶
behavior_default_when(when_tok: Token)
The start of a default condition block was found.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
when_tok
|
Token
|
Position of the start of the new block. |
required |
Source code in src/raesl/compile/typechecking/compdef_behavior_builder.py
behavior_normal_then
¶
behavior_normal_then(then_tok: Token)
The start of a 'then' result block was found.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
then_tok
|
Token
|
Position of the start of the new block. |
required |
Source code in src/raesl/compile/typechecking/compdef_behavior_builder.py
behavior_normal_when
¶
behavior_normal_when(when_tok: Token)
The start of a normal 'when' condition block was found.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
when_tok
|
Token
|
Position of the start of the new block. |
required |
Source code in src/raesl/compile/typechecking/compdef_behavior_builder.py
behavior_then_result
¶
behavior_then_result(name_tok: Token, result: Comparison)
A new result was found, add it to the last 'then' block.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_tok
|
Token
|
Name of the result. |
required |
result
|
Comparison
|
Result to add. |
required |
Source code in src/raesl/compile/typechecking/compdef_behavior_builder.py
behavior_when_condition
¶
behavior_when_condition(
name_tok: Token,
condition: Union[Disjunction, RelationComparison],
)
A new condition was found, add it to the last 'when' block.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_tok
|
Token
|
Name of the condition. |
required |
condition
|
Union[Disjunction, RelationComparison]
|
Condition to add. |
required |
Source code in src/raesl/compile/typechecking/compdef_behavior_builder.py
finish_comp
¶
finish_comp(
comp_def: ComponentDefinition, _spec: Specification
)
Verify correctness of the collected behavior and store good behavior in
:obj:comp_def
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comp_def
|
ComponentDefinition
|
Surrounding component definition supplying variables and parameters. Checked designs should be added to it after checking. |
required |
_spec
|
Specification
|
Specification being constructed, source for types and verbs. |
required |
Source code in src/raesl/compile/typechecking/compdef_behavior_builder.py
new_behavior_function
¶
new_behavior_function(label_tok: Token)
A new behavior functionality was found.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
label_tok
|
Token
|
Name of the new behavior. |
required |
Source code in src/raesl/compile/typechecking/compdef_behavior_builder.py
new_behavior_header
¶
new_behavior_header(kind_tok: Token)
A new 'behavior' section header was found.
Source code in src/raesl/compile/typechecking/compdef_behavior_builder.py
ParsedBehavior
¶
ParsedBehavior(
name: Token, kind: str, cases: List[ParsedCase]
)
Temporary storage of a behavior. This allows catching multiple default cases (these cannot be expressed in the AST). Also, it allows checking for receiving a sane order of calls from the parser.
Source code in src/raesl/compile/typechecking/compdef_behavior_builder.py
ParsedCase
¶
ParsedCase(
name: Token,
when_tok: Optional[Token],
then_tok: Optional[Token],
whens: WhensType,
thens: ThensType,
)
Temporary storage for storing a case in a behavior while collecting the cases.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
Token
|
Name of the case. |
required |
when_tok
|
Optional[Token]
|
Position of the 'when' line. |
required |
then_tok
|
Optional[Token]
|
Position of the 'then' line. |
required |
whens
|
WhensType
|
Collected conditions. Will be empty for the default behavior. None means the variable should not be accessed at all. |
required |
thens
|
ThensType
|
Collected results. |
required |
Source code in src/raesl/compile/typechecking/compdef_behavior_builder.py
compdef_builder
¶
Builder for collecting and building component definitions.
CompDefChildBuilders
¶
CompDefChildBuilders(
compdef_builder: ComponentDefBuilder,
pos_tok: Token,
name_tok: Optional[Token],
varparam_counter: Counter,
)
Class storing child builders for all sections of a component definition.
As type checking cannot be done until the entire specification has been parsed (global types, verbs, and relation definitions may not exist at the time of the end of a component definition, and definitions of instantiated component may be defined further down in the specification), child builders for each definition must be kept around until the end.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
compdef_builder
|
ComponentDefBuilder
|
Parent component definition builder. |
required |
pos_tok
|
Token
|
Position of the start of the component definition. |
required |
name_tok
|
Optional[Token]
|
Name of the component definition if it exists |
required |
varparam_counter
|
Counter
|
Object for handing out unique numbers to elementary var/param nodes. |
required |
Source code in src/raesl/compile/typechecking/compdef_builder.py
add_compinst
¶
Forward call to component instance builder.
add_need
¶
add_transform
¶
add_transform(transform: Transformation)
behavior_then_result
¶
behavior_then_result(name_tok: Token, result: Comparison)
behavior_when_condition
¶
behavior_when_condition(
name_tok: Token,
condition: Union[Disjunction, RelationComparison],
)
Forward call to behavior builder.
Source code in src/raesl/compile/typechecking/compdef_builder.py
finish
¶
finish(
spec: Specification,
doc_distributor: DocCommentDistributor,
)
Parsing is finished, component child instances have been checked already. Check the collected component data, and add the component definition to the specification.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spec
|
Specification
|
Specification to use as source for types, verbs relation definitions, and other component definitions, and to fill with the type-checked component. |
required |
doc_distributor
|
DocCommentDistributor
|
Object that accepts the found doc comments for distributing them to the elements of the specification. |
required |
Source code in src/raesl/compile/typechecking/compdef_builder.py
get_child_compdefnames
¶
Get the names of component definitions that are needed for child instances.
Returns:
Type | Description |
---|---|
Set[str]
|
Names of the components being instantiated in this component. |
Source code in src/raesl/compile/typechecking/compdef_builder.py
new_relinst
¶
notify_parameter_section
¶
notify_parameter_section(pos_tok: Token)
A parameter section was found, check if it is allowed.
Source code in src/raesl/compile/typechecking/compdef_builder.py
notify_transform_section
¶
notify_transform_section(pos_tok: Token)
A transform section was found, check if it is allowed.
Source code in src/raesl/compile/typechecking/compdef_builder.py
ComponentDefBuilder
¶
ComponentDefBuilder(ast_builder: AstBuilder)
Builder to construct component definitions of the entire specification. The builder keeps a list of component child builders, one for each component definition. The latter do all the work for each component definition.
Source code in src/raesl/compile/typechecking/compdef_builder.py
finish
¶
finish(
spec: Specification,
doc_distributor: DocCommentDistributor,
)
Parsing has finished, complete type checking.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spec
|
Specification
|
Specification already containing types, verb-prepositions, and relation definitions. Must be filled with component definitions and world component. |
required |
doc_distributor
|
DocCommentDistributor
|
Object that accepts the found doc comments for distributing them to the elements of the specification. |
required |
Source code in src/raesl/compile/typechecking/compdef_builder.py
new_componentdef
¶
New component definition started.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pos_tok
|
Token
|
Token defining the start position of the component definition. |
required |
name_tok
|
Optional[Token]
|
Token with the name of the definition if it exists. Non-existing name means the component represents 'world'. |
required |
Source code in src/raesl/compile/typechecking/compdef_builder.py
notify_new_section
¶
Notification for self and possibly the child builders if a new component definition is under construction.
Counter
¶
Class for handing out unique numeric values.
Normally, a static class variable would do, except testing more than one specification at a time doesn't reset the counter, leading to different output depending on what is being tested together.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
first_free_value
|
int
|
First free value to set the counter to. |
required |
Attributes:
Name | Type | Description |
---|---|---|
counter |
Next free value. |
Source code in src/raesl/compile/typechecking/compdef_builder.py
compdef_comment_builder
¶
Deal with the comment sections in a component definition.
CompDefCommentBuilder
¶
CompDefCommentBuilder(
comp_child_builders: CompDefChildBuilders,
)
Collect the names in the 'comments' section, and hook them into the doc comments distributor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comp_child_builders
|
CompDefChildBuilders
|
Component definition's section builders storage. |
required |
Attributes:
Name | Type | Description |
---|---|---|
diag_store |
Diagnostics storage of component definition child builders. |
|
name_toks |
List[Token]
|
Names occurring in a comment section, collected during parsing. |
Source code in src/raesl/compile/typechecking/compdef_comment_builder.py
add_comment
¶
add_comment(name_tok: Token)
Parser found a name in a comments section, store it for future processing.
finish_comp
¶
finish_comp(
comp_def: ComponentDefinition,
doc_distributor: DocCommentDistributor,
)
Process all collected names. This method should be the final step in processing a component definition, as it needs all elements that take doc comments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comp_def
|
ComponentDefinition
|
Component definition to finish. |
required |
doc_distributor
|
DocCommentDistributor
|
Object that distributes doc comments to interested elements of the specification. |
required |
Source code in src/raesl/compile/typechecking/compdef_comment_builder.py
compdef_compinst_builder
¶
Builder to add child component instances to a component definition.
CompDefCompInstBuilder
¶
CompDefCompInstBuilder(
comp_child_builders: CompDefChildBuilders,
)
Collect and check child component instances of a component definition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comp_child_builders
|
CompDefChildBuilders
|
Storage of child builder for a component definition. |
required |
Attributes:
Name | Type | Description |
---|---|---|
diag_store |
Child builders problem store. |
|
instances |
List[ComponentInstance]
|
Collected component instances. |
last_instance |
Optional[ComponentInstance]
|
Link to last added instance, to allow adding instance arguments to it. |
Source code in src/raesl/compile/typechecking/compdef_compinst_builder.py
add_compinst
¶
Store a new child component instance line.
Source code in src/raesl/compile/typechecking/compdef_compinst_builder.py
add_compinst_arguments
¶
add_compinst_arguments(arguments: List[Token])
Store a line of component instance argument names.
Source code in src/raesl/compile/typechecking/compdef_compinst_builder.py
finish_comp
¶
finish_comp(
comp_def: ComponentDefinition, spec: Specification
)
Finish checking and adding child component instances to the component.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comp_def
|
ComponentDefinition
|
Used as 'my' component definition. |
required |
spec
|
Specification
|
Used as source for types. |
required |
Source code in src/raesl/compile/typechecking/compdef_compinst_builder.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
|
get_compdef_names
¶
Get the names of used definitions.
compdef_design_builder
¶
Code for collecting and type checking designs.
CompDefDesignBuilder
¶
CompDefDesignBuilder(
comp_child_builders: CompDefChildBuilders,
)
Class for collecting and type checking designs in a component definition.
Source code in src/raesl/compile/typechecking/compdef_design_builder.py
add_design_subclause
¶
add_design_subclause(sub: SubClause)
Subclause of the last design has been found, append it to the last design.
finish_comp
¶
finish_comp(
comp_def: ComponentDefinition, _spec: Specification
)
Check the found designs in the context of 'comp_def', and add them after verification.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comp_def
|
ComponentDefinition
|
Surrounding component definition supplying variables and parameters. Checked designs should be added to it after checking. |
required |
_spec
|
Specification
|
Specification being constructed, source for types and verbs. |
required |
Source code in src/raesl/compile/typechecking/compdef_design_builder.py
compdef_goal_builder
¶
Code for collecting and adding goals to component definitions.
CompDefGoalBuilder
¶
CompDefGoalBuilder(
comp_child_builders: CompDefChildBuilders,
)
Bases: GoalTransformBaseBuilder
Collect goals of a component from the parser, check them, and eventually add them to the surrounding component definition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comp_child_builders
|
CompDefChildBuilders
|
Child builders as retrieved from the parser. |
required |
Source code in src/raesl/compile/typechecking/compdef_goal_builder.py
add_goal
¶
add_goal(goal: Goal)
New goal has been found by the parser, add it to the found goals.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
goal
|
Goal
|
Goal to add. |
required |
Source code in src/raesl/compile/typechecking/compdef_goal_builder.py
add_goal_subclause
¶
add_goal_subclause(sub_clause: SubClause)
Subclause of the last goal has been found, add it to the last goal.
finish_comp
¶
finish_comp(
comp_def: ComponentDefinition, spec: Specification
)
Check the found goals, and add them to the component.
Source code in src/raesl/compile/typechecking/compdef_goal_builder.py
new_goal_header
¶
new_goal_header(goal_kind: Token)
New goal header line found.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
goal_kind
|
Token
|
Kind of goals that will follow. |
required |
Source code in src/raesl/compile/typechecking/compdef_goal_builder.py
compdef_need_builder
¶
Code for handling 'needs' in component definitions.
CompDefNeedBuilder
¶
CompDefNeedBuilder(
comp_child_builders: CompDefChildBuilders,
)
Class for handling 'need' sections.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comp_child_builders
|
CompDefChildBuilders
|
Storage of child builders for a component definition. |
required |
Attributes:
Name | Type | Description |
---|---|---|
needs |
List[Need]
|
Collected needs. |
Source code in src/raesl/compile/typechecking/compdef_need_builder.py
add_need
¶
Parser found another need, store it for future processing.
finish_comp
¶
finish_comp(
comp_def: ComponentDefinition, _spec: Specification
)
Check the collected needs, and store them in the component definition.
Source code in src/raesl/compile/typechecking/compdef_need_builder.py
compdef_relinst_builder
¶
Relation instance type-checking in a component definition.
CompDefRelInstBuilder
¶
CompDefRelInstBuilder(
comp_child_builders: CompDefChildBuilders,
)
Collect and check relation instances in a component definition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comp_child_builders
|
CompDefChildBuilders
|
Storage of child builders for a component definition. |
required |
Attributes:
Name | Type | Description |
---|---|---|
relinsts |
List[RelInst]
|
Collected relation instances in the component. |
last_relinst |
Optional[RelInst]
|
Link to last added instance to allow adding instance arguments. |
Source code in src/raesl/compile/typechecking/compdef_relinst_builder.py
add_relinst_arguments
¶
add_relinst_arguments(name_toks: List[Token])
Parser found an argument of a direction-block in a relation instance, store it for future checking.
Source code in src/raesl/compile/typechecking/compdef_relinst_builder.py
finish_comp
¶
finish_comp(
comp_def: ComponentDefinition, spec: Specification
)
Check the collected relation instances, report errors, and add the instances to the given component.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comp_def
|
ComponentDefinition
|
Component definition to extend with the found relation instances. Also a source of available variables, parameters, and variable groups. |
required |
spec
|
Specification
|
Specification being constructed. Source for types and relation definitions processed previously. |
required |
Source code in src/raesl/compile/typechecking/compdef_relinst_builder.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
|
new_relinst
¶
Parser found a new relation instance, store it for future extending by the parser, and eventual type checking and adding to the surrounding component definition.
Source code in src/raesl/compile/typechecking/compdef_relinst_builder.py
RelInst
¶
RelInst(
inst_name_tok: Token,
def_name_tok: Token,
arg_blocks: Optional[List[RelInstArgsBlock]] = None,
)
Relation instance while collecting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inst_name_tok
|
Token
|
Instance name. |
required |
def_name_tok
|
Token
|
Definition name. |
required |
arg_blocks
|
Optional[List[RelInstArgsBlock]]
|
Blocks with arguments. |
None
|
Source code in src/raesl/compile/typechecking/compdef_relinst_builder.py
RelInstArgGroup
¶
RelInstArgGroup(
argkind: str,
parameters: List[RelationDefParameter],
arguments: List[Token],
)
Temporary data storage of parameters and arguments of a single kind.
Source code in src/raesl/compile/typechecking/compdef_relinst_builder.py
RelInstArgsBlock
¶
A 'block' of arguments of a relation instance. The kind of arguments, and a list of argument lines.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
argkind_tok
|
Token
|
Token indicating the kind of arguments specified in the block. |
required |
arg_name_toks
|
Optional[List[Token]]
|
Arguments of the block. |
None
|
Source code in src/raesl/compile/typechecking/compdef_relinst_builder.py
compdef_transform_builder
¶
Code for collecting and type checking of transformations.
CompDefTransformBuilder
¶
CompDefTransformBuilder(
comp_child_builders: CompDefChildBuilders,
)
Bases: GoalTransformBaseBuilder
Collect transformations of a component from the parser, check them, and add them to the component definition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comp_child_builders
|
CompDefChildBuilders
|
Storage of child builders for a component definition. |
required |
Attributes:
Name | Type | Description |
---|---|---|
transforms |
List[Transformation]
|
Collected transformations. |
transform_kind |
Optional[str]
|
Last found kind of transformation kind, either 'requirement' or 'constraint'. |
Source code in src/raesl/compile/typechecking/compdef_transform_builder.py
add_transform
¶
add_transform(transform: Transformation)
A new transformation has been found, add it to the collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transform
|
Transformation
|
Transformation to add. |
required |
Source code in src/raesl/compile/typechecking/compdef_transform_builder.py
add_transform_subclause
¶
add_transform_subclause(sub_clause: SubClause)
Add a found subclause that belongs to the last transformation.
finish_comp
¶
finish_comp(
comp_def: ComponentDefinition, spec: Specification
)
Check the found transformations, and add them to the component.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comp_def
|
ComponentDefinition
|
Component definition to extend with the found relation instances. Also a source of available variables, parameters, and variable groups. |
required |
spec
|
Specification
|
Specification being constructed. Source for types and relation definitions processed previously. |
required |
Source code in src/raesl/compile/typechecking/compdef_transform_builder.py
new_transform_header
¶
new_transform_header(transform_kind: Token)
New transform section line found.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transform_kind
|
Token
|
Kind of transformations that will follow. |
required |
Source code in src/raesl/compile/typechecking/compdef_transform_builder.py
compdef_vargroup_builder
¶
Variable groups in a component.
CollectedVarGroup
¶
CompDefVarGroupBuilder
¶
CompDefVarGroupBuilder(
comp_child_builders: CompDefChildBuilders,
)
Collect and check variable groups of a component definition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comp_child_builders
|
CompDefChildBuilders
|
Storage of child builders for a component definition. |
required |
Attributes:
Name | Type | Description |
---|---|---|
collected_var_groups |
List[CollectedVarGroup]
|
Collected var group instances in the component. |
last_vgroup |
Optional[CollectedVarGroup]
|
Link to last added instance to allow adding instance arguments. |
Source code in src/raesl/compile/typechecking/compdef_vargroup_builder.py
finish_comp
¶
finish_comp(
comp_def: ComponentDefinition, _spec: Specification
)
Check the collected variable groups, report errors, and add the instances to the given component.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comp_def
|
ComponentDefinition
|
Component definition to extend with the found variable groups. Also a source of available variables and parameters. |
required |
_spec
|
Specification
|
Specification being constructed. Source for types and relation definitions processed previously. |
required |
Source code in src/raesl/compile/typechecking/compdef_vargroup_builder.py
new_vargroup
¶
new_vargroup(name_tok: Token)
Parser found the start of a new variable group definition. Create a new group for it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_tok
|
Token
|
Name of the new variable group. |
required |
Source code in src/raesl/compile/typechecking/compdef_vargroup_builder.py
vgroup_add_vars
¶
vgroup_add_vars(varpart_name_toks: List[Token])
Parser found a line with variables that are part of the group. Store them for further processing afterwards.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
varpart_name_toks
|
List[Token]
|
Name of variable parts that should become included in the last defined variable group. |
required |
Source code in src/raesl/compile/typechecking/compdef_vargroup_builder.py
compdef_varparam_builder
¶
Variables and components in a component definition.
CompDefVarParamBuilder
¶
CompDefVarParamBuilder(
comp_child_builders: CompDefChildBuilders,
varparam_counter: Counter,
)
Collect and check variables of a component definition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comp_child_builders
|
CompDefChildBuilders
|
Storage of child builders for a component definition. |
required |
varparam_counter
|
Counter
|
Object for handing out unique numbers to elementary var/param nodes. |
required |
Attributes:
Name | Type | Description |
---|---|---|
variables |
List[VarParam]
|
Variables of the component. |
parameters |
List[VarParam]
|
Parameters of the component. |
Source code in src/raesl/compile/typechecking/compdef_varparam_builder.py
add_parameters
¶
add_parameters(new_params: List[VarParam])
Add parameters of the component definition to the collection.
add_variables
¶
add_variables(new_vars: List[VarParam])
Add variables of the component definition to the collection.
finish_comp
¶
finish_comp(
comp_def: ComponentDefinition, spec: Specification
)
Check the collected variables and parameters, report errors, and add the instances to the given component.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comp_def
|
ComponentDefinition
|
Component definition to extend with the found variables and parameters. |
required |
spec
|
Specification
|
Specification being constructed. Source for types, verbs and relation definitions processed previously. |
required |
Source code in src/raesl/compile/typechecking/compdef_varparam_builder.py
expr_checker
¶
Check that expressions comply with the language requirements.
ExprChecker
¶
ExprChecker(
vps: Dict[str, Union[VarParam]],
diag_store: DiagnosticStore,
)
Class for checking expressions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vps
|
Dict[str, Union[VarParam]]
|
Variables and parameters defined in the expression context. |
required |
diag_store
|
DiagnosticStore
|
Storage for found diagnostics. |
required |
Attributes:
Name | Type | Description |
---|---|---|
reported_names |
Set[str]
|
Names of variables and variable parts that have been reported as error, to avoid duplicate error messages. |
Source code in src/raesl/compile/typechecking/expr_checker.py
check_expr
¶
check_expr(expr: Expression) -> bool
Check whether the expression follows all rules of the ESL language.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
Expression
|
Expression to check. |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether the expression is considered to be sufficiently correct to continue checking other parts of the construct around the expression. |
Source code in src/raesl/compile/typechecking/expr_checker.py
check_relation_comparison
¶
check_relation_comparison(expr: RelationComparison) -> bool
Check the provided relation comparison.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
RelationComparison
|
Relation comparison to check. |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether the expression is considered to be sufficiently correct. |
Source code in src/raesl/compile/typechecking/expr_checker.py
goal_transform_base
¶
Base class for goal and transformation processing to improve code sharing.
GoalTransformBaseBuilder
¶
GoalTransformBaseBuilder(diag_store: DiagnosticStore)
Common base class for checking goals and transformations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
diag_store
|
DiagnosticStore
|
Storage for found diagnostics. |
required |
Attributes:
Name | Type | Description |
---|---|---|
reported_names |
Set[str]
|
Names of flows with a reported error, to avoid duplicate error generation. |
Source code in src/raesl/compile/typechecking/goal_transform_base.py
check_form
¶
Check whether the requirement or constraint form of the text is correct with respect to the containing section.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sect_name
|
str
|
Name of the section (goal or transformation). |
required |
kind
|
str
|
Kind of section containing the text (requirement or constraint). |
required |
doesaux
|
Token
|
Token in the formulation that is either 'does' or one of the auxiliary verbs. |
required |
sub_clauses
|
List[SubClause]
|
Sub clauses belong to the requirement or constraint. |
required |
Source code in src/raesl/compile/typechecking/goal_transform_base.py
resolve_component
¶
resolve_component(
compinst_tok: Token,
cinsts: Dict[str, ComponentInstance],
) -> Optional[ComponentInstance]
Find a component instance with the provided instance name. If it exists, return it, else report an error and return None, indicating failure.
Source code in src/raesl/compile/typechecking/goal_transform_base.py
verify_flows
¶
Check that each flow exists as variable or parameter. Update the link in the Flow object to point to the matching variable or parameter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
flows
|
List[Flow]
|
Flows to check. |
required |
vps
|
Dict[str, VarParam]
|
Available variables and parameters in the component. |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether all flows can be matched to a variable or parameter. |
Source code in src/raesl/compile/typechecking/goal_transform_base.py
verify_verb_prepos
¶
Verify verb and pre-position and report an error if the combination does not exist.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
verb_tok
|
Token
|
Token holding the verb text. |
required |
prepos_tok
|
Token
|
Token holding the prepos text. |
required |
vpps
|
Set[Tuple[str, str]]
|
Available combinations of verbs and prepositions. |
required |
Source code in src/raesl/compile/typechecking/goal_transform_base.py
orderer
¶
Generic class for resolving an order of checking 'things' assuming each thing has a name, and knows the names of its direct dependencies.
Orderer
¶
Class that orders entries so their 'needed_by' entries are processed first.
Attributes:
Name | Type | Description |
---|---|---|
_independent_entries |
Dict[str, OrdererEntry]
|
Entries that do not depend on other entries. |
_dependent_entries |
Dict[str, OrdererEntry]
|
Entries that depend on other entries. |
Source code in src/raesl/compile/typechecking/orderer.py
add_dependency
¶
Add a dependency where the 'provide' name depends on the 'needs' names.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
provide
|
str
|
Name of the 'thing' that this dependency provides. |
required |
needs
|
Iterable[str]
|
Names of 'things' that are required by the provide 'thing'. |
required |
data
|
TypeOfData
|
Optional data associated with 'provide'. At most one such data item should exist, class cannot handle multiple data items. |
None
|
Source code in src/raesl/compile/typechecking/orderer.py
find_entry
¶
find_entry(name: str) -> Optional[OrdererEntry]
Try to find an entry with the provided name. Useful for duplicate name detection.
Returns:
Type | Description |
---|---|
Optional[OrdererEntry]
|
The found entry (treat as read-only), or None. |
Source code in src/raesl/compile/typechecking/orderer.py
resolve
¶
resolve() -> (
Tuple[List[OrdererEntry], Optional[List[OrdererEntry]]]
)
Resolve the dependency chain by peeling away independent entries. This should cause some dependent entries to become independent, allowing them to be peeled as well.
Returns:
Type | Description |
---|---|
Tuple[List[OrdererEntry], Optional[List[OrdererEntry]]]
|
Ordered sequence of entries containing name and associated data, and optionally a cycle of entries if at least one cycle exists. Note that the Orderer returns one arbitrary cycle in such a case. |
Source code in src/raesl/compile/typechecking/orderer.py
OrdererEntry
¶
Entry in the orderer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the entry. |
required |
data
|
TypeOfData
|
Data associated with the entry. |
required |
Attributes:
Name | Type | Description |
---|---|---|
needed_by |
List[OrdererEntry]
|
List of entries that depend on this entry. May only be accessed by the Orderer. |
depend_on |
List[OrdererEntry]
|
List of entries that need this entry. May only be accessed by the Orderer. |
Source code in src/raesl/compile/typechecking/orderer.py
reldef_builder
¶
Collect and process relation definition that are found by the parser.
RelationDefBuilder
¶
RelationDefBuilder(ast_builder: AstBuilder)
Builder to construct relation definitions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ast_builder
|
AstBuilder
|
AST builder instance. |
required |
Attributes:
Name | Type | Description |
---|---|---|
diag_store |
Storage for found diagnostics. |
|
rel_defs |
Optional[List[RelationDefinition]]
|
Created relation definitions while collecting data from parsing. |
current_reldef |
Optional[RelationDefinition]
|
Reference to the entry in 'rel_defs' that is being filled. |
last_occurrences |
Dict[str, Token]
|
Map of input/output directions to token of last occurrence of that direction in the current definition. |
current_direction |
Optional[str]
|
Parameter direction to attach to a new parameter. |
Source code in src/raesl/compile/typechecking/reldef_builder.py
add_reldef
¶
add_reldef(name: Token)
Add a new relation definition. Parameters will follow.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
Token
|
Name of the relation definition. |
required |
Source code in src/raesl/compile/typechecking/reldef_builder.py
finish
¶
finish(spec: Specification)
Check the relation definitions and add them to the result specification.
Source code in src/raesl/compile/typechecking/reldef_builder.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
|
notify_new_section
¶
Parser found a new section, drop all 'in-progress' relation definition construction.
Source code in src/raesl/compile/typechecking/reldef_builder.py
reldef_add_param
¶
Add a parameter to the current relation definition.
Source code in src/raesl/compile/typechecking/reldef_builder.py
reldef_param_header
¶
reldef_param_header(header_tok: Token, direction: str)
New parameter subsection with a direction. Set the direction for the parameters that will follow.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
header_tok
|
Token
|
Token of the direction, for deriving position information if needed. |
required |
direction
|
str
|
Direction of the next parameters of the relation definition. |
required |
Source code in src/raesl/compile/typechecking/reldef_builder.py
type_builder
¶
Class for constructing types.
TempFieldDef
¶
TempTypeDef
¶
TempTypeDef(
type_name: Token,
parent_name: Optional[Token],
enum_spec: Optional[List[Value]],
unit_spec: Optional[List[Token]],
ival_spec: Optional[
List[Tuple[Optional[Value], Optional[Value]]]
],
cons_spec: Optional[Value],
)
Temporary storage of a type definition.
Source code in src/raesl/compile/typechecking/type_builder.py
TypeBuilder
¶
TypeBuilder(ast_builder: AstBuilder)
Builder to construct types of the specification.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ast_builder
|
AstBuilder
|
AST builder instance. |
required |
Attributes:
Name | Type | Description |
---|---|---|
diag_store |
Storage for found diagnostics. |
|
type_defs |
List[TempTypeDef]
|
Found type definitions in the specification, temporarily stored until all type information is available. |
bundle_defs |
List[TempBundleDef]
|
Found bundle definitions in the specification, temporarily stored until all type information is available. |
current_bundle |
Optional[TempBundleDef]
|
If not None, reference to the last opened bundle definition for adding additional fields to it. |
Source code in src/raesl/compile/typechecking/type_builder.py
add_bundle_field
¶
A new field in the current bundle has been found by the parser, add it.
Source code in src/raesl/compile/typechecking/type_builder.py
add_standard_types
staticmethod
¶
add_standard_types(resolved_types: Dict[str, TypeDef])
Add all standard types to the resolved types.
Source code in src/raesl/compile/typechecking/type_builder.py
add_typedef
¶
add_typedef(
type_name: Token,
parent_name: Optional[Token],
enum_spec: Optional[List[Value]],
unit_spec: Optional[List[Token]],
ival_spec: Optional[
List[Tuple[Optional[Value], Optional[Value]]]
],
cons_spec: Optional[Value],
)
The parser found a new type definition entry, store it.
Source code in src/raesl/compile/typechecking/type_builder.py
check_unit
¶
Check whether the unit possibly specified in 'value' is available for use. Report an error if it is not available.
Source code in src/raesl/compile/typechecking/type_builder.py
finish
¶
finish(spec: Specification)
Check the collected types and bundles, report any errors, and add them to the specification.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spec
|
Specification
|
Specification to extend with the found types. |
required |
Source code in src/raesl/compile/typechecking/type_builder.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
|
get_entry_location
staticmethod
¶
get_entry_location(entry: OrdererEntry) -> Location
Retrieve position information from a type entry.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entry
|
OrdererEntry
|
Entry to use. |
required |
Returns:
Type | Description |
---|---|
Location
|
Position information of the entry. |
Source code in src/raesl/compile/typechecking/type_builder.py
new_bundle_type
¶
new_bundle_type(bundle_name: Token)
The parser found a new bundle in the source code, create it.
Source code in src/raesl/compile/typechecking/type_builder.py
notify_new_section
¶
type_checker
¶
Type checking.
Type compatibility¶
Type 'sub_type' is compatible with type 'super_type' if - Type 'sub_type' is (possibly indirectly) derived from 'super_type'. - Type 'sub_type' has no additional value constraints in the form of enumerations, upper or lower limits, or constants relative to 'super_type'.
The former condition ensures the values are fundamentally compatible. This condition should always hold, the latter condition ensures that all possible values of 'super_type' can also be expressed in 'sub_type'. This is particularly relevant if 'sub_type' may receive data from the element with 'super_type'. If data flow is in the other direction only, the second condition seems less relevant.
Note that units are not relevant in this context. If the sub_type is a subtype of of 'super_type', the former always has all units of the latter.
Relevant code type-classes¶
Several classes have or use types, or represent data of some type. These classes are
- raesl.compile.ast.types.ElementaryType (type of a single value).
- raesl.compile.ast.types.Compound (type of a bundle of values).
- raesl.compile.ast.nodes.ElementaryVarNode (data of an elementary type).
- raesl.compile.ast.nodes.CompoundVarNode (data of a bundle).
- raesl.compile.ast.nodes.GroupNode (data of a variable group).
where an ElementaryVarNode contains an ElementaryType, a CompoundVarNode contains a Compound (type), and GroupNode eventually always points at ElementaryVarNode or CompoundVarNode instances.
The entry_point 'check_type' accepts all the above kinds of objects.
TypeData
¶
TypeData(
name_tok: Token, suffixes: List[str], value: TypeValue
)
Tuple-like class to keep type data from one side together.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_tok
|
Token
|
Initial name of the value in the source, and point of use of the type. |
required |
suffixes
|
List[str]
|
Child texts after the initial name to indicate the subtype value being examined. See 'get_name' for a description of the suffixes. |
required |
value
|
TypeValue
|
Type or node value being examined. |
required |
Source code in src/raesl/compile/typechecking/type_checker.py
drop_to_type
¶
For nodes, drop down to its type.
Source code in src/raesl/compile/typechecking/type_checker.py
expand
¶
Expand a sequence of values in 'self.value' to a sequence of child TypeData instances.
Source code in src/raesl/compile/typechecking/type_checker.py
get_name
¶
Construct a human-readable name of the point being examined.
It consists of the initial name followed by zero or more suffixes, where
a suffix can be one of the following
- ".
Returns:
Type | Description |
---|---|
str
|
The constructed name. |
Source code in src/raesl/compile/typechecking/type_checker.py
check_type
¶
check_type(
subtype: Tuple[Token, TypeValue],
supertype: Tuple[Token, TypeValue],
allow_subtype_limits: bool = False,
) -> Optional[EslDiagnostic]
Like 'check_type_unpacked', except the subtype and super-type data is packed in tuples.
Source code in src/raesl/compile/typechecking/type_checker.py
check_type_unpacked
¶
check_type_unpacked(
sub_nametok: Token,
sub_value: TypeValue,
super_nametok: Token,
super_value: TypeValue,
allow_subtype_limits: bool = False,
) -> Optional[EslDiagnostic]
Check whether sub_value is a subtype of super_value. Iff allow_subtype_limits holds, the sub_value may have additional value constraints. Returns None if the sub_value is indeed a subtype of super_value, possibly taking additional value constraints into account. Otherwise it returns a problem description of how it fails.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sub_nametok
|
Token
|
Text in the input of the sub_value, usually a variable. |
required |
sub_value
|
TypeValue
|
Type or node of the sub value. |
required |
super_nametok
|
Token
|
Text in the input of the super_value, usually a variable. |
required |
super_value
|
TypeValue
|
Type or node of the super value. |
required |
allow_subtype_limits
|
bool
|
Whether sub_value may have additional value constraints relative to super_value. |
False
|
Returns:
Type | Description |
---|---|
Optional[EslDiagnostic]
|
None if sub_value is a subtype of super_value taking allow_subtype_limits into account, else a problem description of how it fails to have the subtype relation. |
Source code in src/raesl/compile/typechecking/type_checker.py
utils
¶
Support functions.
construct_comp_instances_map
¶
construct_comp_instances_map(
comp_def: ComponentDefinition,
) -> Dict[str, ComponentInstance]
Construct a dict of child component instance names of the given component definition.
:param comp_def: Definition to search for available component instances. :return: Dictionary of component instance names to their instances.
Source code in src/raesl/compile/typechecking/utils.py
construct_relinst_goal_transform_design_behavior_map
¶
construct_relinst_goal_transform_design_behavior_map(
comp_def: ComponentDefinition,
) -> Dict[
str,
Union[
RelationInstance,
Goal,
Transformation,
Design,
BehaviorFunction,
],
]
Construct a dict to quickly find goals, transformations, designs, and behaviors by their label name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comp_def
|
ComponentDefinition
|
Definition to search. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Union[RelationInstance, Goal, Transformation, Design, BehaviorFunction]]
|
Dictionary of labels to their goals, transformations, designs, and behaviors. |
Source code in src/raesl/compile/typechecking/utils.py
construct_var_param_map
¶
construct_var_param_map(
comp_def: ComponentDefinition,
) -> Dict[str, VarParam]
Construct a dict of variable / parameter names to their definitions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comp_def
|
ComponentDefinition
|
Definition to search for available variables and parameters. |
required |
Returns:
Type | Description |
---|---|
Dict[str, VarParam]
|
Dictionary of names to their definitions. |
Source code in src/raesl/compile/typechecking/utils.py
construct_vargroup_map
¶
construct_vargroup_map(
comp_def: ComponentDefinition,
) -> Dict[str, VariableGroup]
Construct a dict of variable groups names to their definitions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comp_def
|
ComponentDefinition
|
Definition to search for available variables and parameters. |
required |
Returns:
Type | Description |
---|---|
Dict[str, VariableGroup]
|
Dictionary of group names to their definitions. |
Source code in src/raesl/compile/typechecking/utils.py
construct_verb_prepos_combis
¶
construct_verb_prepos_combis(
spec: Specification,
) -> Set[Tuple[str, str]]
Construct a set with all defined verb/prepos combinations.
Source code in src/raesl/compile/typechecking/utils.py
resolve_var_param_group_node
¶
resolve_var_param_group_node(
name_tok: Token,
avail_vps: Optional[Dict[str, VarParam]],
avail_vgroups: Optional[Dict[str, VariableGroup]],
reported_names: Set[str],
diag_store: DiagnosticStore,
) -> Optional[Node]
Resolve the provided (possibly dotted) name to a node from a variable, parameter or variable group.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_tok
|
Token
|
Name of the node to obtain, may contain a dotted name. |
required |
avail_vps
|
Optional[Dict[str, VarParam]]
|
Available variables and parameters, may be None. |
required |
avail_vgroups
|
Optional[Dict[str, VariableGroup]]
|
Available variable groups, may be None. |
required |
reported_names
|
Set[str]
|
Non-existing variables, parameters, and groups that are reported already. |
required |
diag_store
|
DiagnosticStore
|
Destination for found diagnostics. |
required |
Returns:
Type | Description |
---|---|
Optional[Node]
|
The node represented by the name. It can be a Node if the name points at a variable groups. It is always a VarNode if the nam points at a variable or parameter. |
Source code in src/raesl/compile/typechecking/utils.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
|
resolve_var_param_node
¶
resolve_var_param_node(
name_tok: Token,
avail_vps: Dict[str, VarParam],
reported_names: Set[str],
diag_store: DiagnosticStore,
) -> Optional[VarNode]
Resolve the (possibly sub)node of a variable or parameter indicated by 'name'. If it fails, report an error if necessary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_tok
|
Token
|
Name of the node to obtain, may contain a dotted name. |
required |
avail_vps
|
Dict[str, VarParam]
|
Variables and parameters available in the context. |
required |
reported_names
|
Set[str]
|
Non-existing names and prefixes that are reported already. |
required |
diag_store
|
DiagnosticStore
|
Storage for found diagnostics. |
required |
Returns:
Type | Description |
---|---|
Optional[VarNode]
|
The node represented by the name, or None if it could not be found. In the latter case, an problem exists indicating failure to find the node. |
Source code in src/raesl/compile/typechecking/utils.py
split_arguments
¶
split_arguments(
params_length: int,
multiple_index: Optional[int],
arguments: List[Token],
) -> List[List[Token]]
Given a list arguments, split them into 'params_length' pieces, where each piece has length 1, except piece 'multiple_index' if not None, which takes all the slack.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params_length
|
int
|
Number of pieces in the result. |
required |
multiple_index
|
Optional[int]
|
Index in 'arguments' where the multi-piece starts, only if multiple_index is not None. |
required |
arguments
|
List[Token]
|
Actual arguments to split in pieces. |
required |
Source code in src/raesl/compile/typechecking/utils.py
verb_builder
¶
Class to store and check verb / pre-position definitions.
VerbDefBuilder
¶
VerbDefBuilder(ast_builder: AstBuilder)
Part of the builders to deal with verbs / pre-positions.
Source code in src/raesl/compile/typechecking/verb_builder.py
add_verbdef
¶
Store the provided verb/prepos combination.
Source code in src/raesl/compile/typechecking/verb_builder.py
finish
¶
finish(spec: Specification)
Finish collecting by checking the collected verb-prepositions. Store result in the provided specification.