monasca-analytics/monasca_analytics/banana/grammar
Daisuke Fujita 6c7316ebbd Support python3.5 for monasca-analytics
This patch implements followings for py35 support using six(er) and 2to3.

- Python 3 map/filter returns iterator, must be converted to list
- use six.string_types instead of basestring
- use six.iteritems instead of iteritems
- use six.moves for using cPickle and SocketServer packages
- use six.assertCountEqual instead of assertItemsEqual
- remove relative imports
- update BytecodeAssembler(monasca_analytics/
  banana/bytecode/assembler.py) for python3

Can be tested with:
  tox -e py35

Change-Id: If1b92d0ffc56492950f6a02ebdbe1596d0dce368
2019-01-28 09:47:45 +00: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 Support python3.5 for monasca-analytics 2019-01-28 09:47:45 +00:00
base_ast.py Support python3.5 for monasca-analytics 2019-01-28 09:47:45 +00:00
config.py Support python3.5 for monasca-analytics 2019-01-28 09:47:45 +00: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.