monasca-analytics/monasca_analytics/banana/grammar
gecong1973 c9ea9be579 Add __ne__ built-in function
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
2016-11-24 10:00:01 +08:00
..
README.md This commit introduces the first version of Banana configuration language. 2016-08-22 14:29:26 +01:00
__init__.py This commit introduces the first version of Banana configuration language. 2016-08-22 14:29:26 +01:00
ast.py Add __ne__ built-in function 2016-11-24 10:00:01 +08:00
base_ast.py Merge "Add Banana specific APIs to typecheck and get list of components." 2016-11-15 21:31:09 +00:00
config.py Remove xrange for run both Python 2 and Python 3 2016-10-12 11:40:05 +07:00
const.py This commit introduces the first version of Banana configuration language. 2016-08-22 14:29:26 +01:00

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 that exception-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.