monasca-analytics/monasca_analytics/banana/grammar
Luong Anh Tuan 05f12bfffa Remove xrange for run both Python 2 and Python 3
In python 3, range() does what xrange() used to do and xrange() does not
exist. If you want to write code that will run on both Python 2 and
Python 3, you can't use xrange().

range() can actually be faster in some cases - eg. if iterating over the
same sequence multiple times. xrange() has to reconstruct the integer
object every time, but range() will have real integer objects.
(It will always perform worse in terms of memory however)

xrange() isn't usable in all cases where a real list is needed.
For instance, it doesn't support slices, or any list methods.

Change-Id: I5233438a864bb00d04ba7fb2b1688cacb0473691
2016-10-12 11:40:05 +07: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 Remove xrange for run both Python 2 and Python 3 2016-10-12 11:40:05 +07:00
base_ast.py Remove xrange for run both Python 2 and Python 3 2016-10-12 11:40:05 +07: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.