Source code for ironic.common.trait_based_networking.grammar.parser
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import ironic.common.trait_based_networking.base as tbn_base
import lark
FILTER_EXPRESSION_GRAMMAR = r"""
filter_expression: single_expression
| compound_expression
| paren_expression
| function_expression
function_expression: function
single_expression: variable_name comparator string_literal
compound_expression: filter_expression ( boolean_operator filter_expression )+
paren_expression: "(" filter_expression ")"
boolean_operator: "&&" -> op_and
| "||" -> op_or
comparator: "==" -> equality
| "!=" -> inequality
| ">=" -> gt_or_eq
| ">" -> gt
| "<=" -> lt_or_eq
| "<" -> lt
| "=~" -> prefix_match
function: "port.is_port" -> port_is_port
| "port.is_portgroup" -> port_is_portgroup
string_literal: /\'[A-Za-z0-9_\-\.]*\'/
variable_name: /[a-z]+\.[a-z\_]+/
%import common.WS
%ignore WS
"""
FILTER_EXPRESSION_GRAMMAR_START_RULE = 'filter_expression'
FilterExpressionParser = lark.Lark(FILTER_EXPRESSION_GRAMMAR,
start=FILTER_EXPRESSION_GRAMMAR_START_RULE)