Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
gboml
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
smart_grids
public
gboml
Commits
edf0c3d4
Commit
edf0c3d4
authored
2 years ago
by
Derval Guillaume
Browse files
Options
Downloads
Patches
Plain Diff
Let users define functions
parent
bad5bb5a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/gboml/ast/__init__.py
+1
-1
1 addition, 1 deletion
src/gboml/ast/__init__.py
src/gboml/ast/variables.py
+21
-1
21 additions, 1 deletion
src/gboml/ast/variables.py
src/gboml/gboml.lark
+1
-1
1 addition, 1 deletion
src/gboml/gboml.lark
src/gboml/parsing.py
+10
-1
10 additions, 1 deletion
src/gboml/parsing.py
with
33 additions
and
4 deletions
src/gboml/ast/__init__.py
+
1
−
1
View file @
edf0c3d4
...
...
@@ -7,7 +7,7 @@ __all__ = [
"
HyperEdge
"
,
"
NodeDefinition
"
,
"
NodeImport
"
,
"
HyperEdgeDefinition
"
,
"
HyperEdgeImport
"
,
"
ExpressionOp
"
,
"
GBOMLGraph
"
,
"
ImplicitLoop
"
,
"
RValue
"
,
"
RValueWithGen
"
,
"
GeneratedRValue
"
,
"
Range
"
,
"
MultiLoop
"
,
"
DictEntry
"
,
"
Dictionary
"
,
"
NodeGenerator
"
,
"
HyperEdgeGenerator
"
,
"
DefinitionType
"
"
DefinitionType
"
,
"
FunctionDefinition
"
,
"
ConstantDefinition
"
,
"
ExpressionDefinition
"
]
from
gboml.ast.arrays
import
*
...
...
This diff is collapsed.
Click to expand it.
src/gboml/ast/variables.py
+
21
−
1
View file @
edf0c3d4
...
...
@@ -22,10 +22,30 @@ class DefinitionType(Enum):
constant
=
"
=
"
expression
=
"
<-
"
@dataclass
class
Definition
(
GBOMLObject
):
pass
@dataclass
class
ConstantDefinition
(
Definition
):
name
:
str
value
:
RValue
tags
:
list
[
str
]
=
field
(
default_factory
=
list
)
@dataclass
class
ExpressionDefinition
(
Definition
):
name
:
str
value
:
RValue
tags
:
list
[
str
]
=
field
(
default_factory
=
list
)
@dataclass
class
FunctionDefinition
(
Definition
):
name
:
str
type
:
DefinitionType
args
:
list
[
str
]
value
:
RValue
tags
:
list
[
str
]
=
field
(
default_factory
=
list
)
...
...
This diff is collapsed.
Click to expand it.
src/gboml/gboml.lark
+
1
−
1
View file @
edf0c3d4
...
...
@@ -92,7 +92,7 @@ bool_expression_comparison: expression (COMPARISON_OPERATOR | CTR_OPERATOR) expr
COMPARISON_OPERATOR: "<" | ">" | "!="
// DEFINITIONS
definition: ID DEF_TYPE rvalue tags ";"
definition: ID
["(" separated_list{ID, ","} ")"]
DEF_TYPE rvalue tags ";"
DEF_TYPE: "=" | "<-"
// ARRAYS
...
...
This diff is collapsed.
Click to expand it.
src/gboml/parsing.py
+
10
−
1
View file @
edf0c3d4
...
...
@@ -64,7 +64,6 @@ def _lark_to_gboml(tree: Tree, filename: Optional[str] = None) -> GBOMLGraph:
#
to_obj
=
{
"
hyperedge_import
"
:
HyperEdgeImport
,
"
definition
"
:
Definition
,
"
var_or_param_leaf
"
:
VarOrParamLeaf
,
"
var_or_param
"
:
VarOrParam
,
"
constraint_std
"
:
StdConstraint
,
...
...
@@ -195,4 +194,14 @@ def _lark_to_gboml(tree: Tree, filename: Optional[str] = None) -> GBOMLGraph:
return
Array
(
entries
,
meta
=
meta
)
raise
Exception
(
"
An array cannot contain dictionary entries (and conversely)
"
)
def
definition
(
self
,
meta
:
Meta
,
name
:
str
,
args
:
Optional
[
list
[
str
]],
typ
:
DefinitionType
,
val
:
RValue
,
tags
:
list
[
str
]):
if
args
is
not
None
:
if
typ
!=
DefinitionType
.
expression
:
raise
Exception
(
"
Functions can only be defined as expressions (use `<-` instead of `=`)
"
)
return
FunctionDefinition
(
name
,
args
,
val
,
tags
,
meta
=
meta
)
elif
typ
==
DefinitionType
.
expression
:
return
ExpressionDefinition
(
name
,
val
,
tags
,
meta
=
meta
)
else
:
return
ConstantDefinition
(
name
,
val
,
tags
,
meta
=
meta
)
return
GBOMLLarkTransformer
().
transform
(
tree
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment