c9ea9be579
In Python 3 __ne__ by default delegates to __eq__ and inverts the result, but in Python 2 they urge you to define __ne__ when you define __eq__ for it to work properly [1].There are no implied relationships among the comparison operators. The truth of x==y does not imply that x!=y is false. Accordingly, when defining __eq__(), one should also define __ne__() so that the operators will behave as expected. [1]https://docs.python.org/2/reference/datamodel.html#object.__ne_ Change-Id: I52633a8a4b19c5e0c0d7d786f21770496e128c7a |
||
---|---|---|
.. | ||
README.md | ||
__init__.py | ||
ast.py | ||
base_ast.py | ||
config.py | ||
const.py |
README.md
Grammar
This folder is all about the definition of the banana
grammar.
The grammar purpose is to convert the input, text, into an
abstract syntax tree (AST).
This is the first step of the pipeline:
+--------+ +---------+
| | | |
| Text | --- grammar ---> | AST | --->
| | | |
+--------+ +---------+
The module ast.py
contains all the possible ASTNode
which
itself is defined in base_ast.py
.
Current status
- Parsing connections such as
a -> b
,a -> [b, c]
,[a, b] -> [c, d]
- Parsing numbers
- Parsing string literals
- Parsing booleans
- Parsing assignments where the left hand side can be a property or an identifier.
- Parsing assignments where the right hand side is a number, a string literal, a property or an identifier.
- Parsing components arguments using a constructor-like syntax.
- Parsing ingestors generators (for JSON dialect)
- Parsing imports such as
from ldp.monasca import *
- Parsing disconnections such as
a !-> b
(requires imports)
Tests
All test regarding the grammar (i.e. the syntax and the way
the AST is built) is defined in test/banana/grammar
.
This folder looks like this:
test/banana/grammar
├── should_fail
│ ├── ...
│ └── file.banana
├── should_pass
│ ├── ...
│ └── file.banana
└── test_config.py
The test_config
generates one test for each file in the
should_pass
and should_fail
directories.
Test can assert various things using instructions below.
Available instruction
# RAISE <exception-name>
: Check thatexception-name
is raised.# STMT_EQ <ast-of-statements>
Check the AST of statements.# AST_EQ <full-ast>
Check the full AST.# CONN_EQ <ast-of-connections>
Check the AST of connections.