Files
mercator_parser/Grammars/queries.g4
Lionel Sambuc 6ed76e485e Parser implementation
* Adaptation of the grammar to make more regular w.r.t reference space
   names placement.

 * Implemented Type check

 * Implemented prediction of the result set cardinality. This assumes:
    + A space is not infinite, this is required to compute complementary
      sets as we can compute the whole space volume.
    + Density is mostly uniform, this allows us to assume the number of
      results is related with a constant factor to the volume in space
      of the selection.
    + The prediction is approximated by using the most pessimistic
      resulting cardinality for each operator, in order to keep the
      operation simple, and fast, at the expense of the precision.

 * Implemented execution, which calls into a DB abstraction layer. That
   layer is currently mostly empty. Execution is also implemented in a
   naive way, and should most likely be optimised.
2019-09-10 14:38:31 +02:00

83 lines
1.8 KiB
ANTLR

grammar queries;
import filters;
/**********************************************************************/
/* FORMATTING DATA */
/**********************************************************************/
queries
: projection_operators?
;
projection_operators
: nifti_operator
| json_operator
;
/* If selector is not provided, one (1) will be used as the values for
* each position where there is a point in bag_expression.
*
* If it is provided, it MUST resolve to a NUMBER. */
nifti_operator
: 'nifti' '(' ( STRING ',' )? ( selector ',' )? bag_expression ')'
;
json_operator
: 'json' '(' jslt ',' bag_expression ( ',' STRING )? ')'
;
jslt
: json
;
/**********************************************************************/
/* JSON */
/**********************************************************************/
/**
* Taken and adapted from:
* https://github.com/antlr/grammars-v4/blob/master/json/JSON.g4
*
* Some of the parser / lexer rules are in the imported grammar as well.
*/
json
: json_value
;
json_obj
: '{' json_pair (',' json_pair)* '}'
| '{' '}'
;
json_pair
: STRING ':' json_value
;
json_array
: '[' json_value (',' json_value)* ']'
| '[' ']'
;
json_value
: STRING
| json_number
| json_obj
| json_array
| 'true'
| 'false'
| 'null'
/* Add support to reference values from the selected bag. */
| selector
| aggregation_expr
;
/* The bag expression is implicit here, as this is te
* second argument to the json operator */
aggregation_expr
: 'count' '(' 'distinct'? selector ')'
| 'sum' '(' selector ')'
| 'min' '(' selector ')'
| 'max' '(' selector ')'
| 'nifti' '(' selector ')'
| 'mbb' '(' ')'
;