def get_key_value_pattern(self, ctx: ParserRuleContext): """ returns the key/value pattern of the context It is assumed, that the context has 5 children, that represent the k/v: '0' left parenthesis '1' key '2' equals '3' value '4' right parenthesis :param ctx: the ParserRuleContext :return formatted key value string :rtype str """ _count = ctx.getChildCount() # count==5 indicates Key/Value context if _count == 5: _key = str(ctx.getChild(1)) if not self._ignore_keyword_case: if self._uppercase_keywords: _key = _key.upper() else: _key = _key.lower() _value = str(ctx.getChild(3)) if not self._ignore_value_case: if self._uppercase_values: _value = _value.upper() else: _value = _value.lower() _ret_string = str(ctx.getChild(0)) + _key + str( ctx.getChild(2)) + _value + str(ctx.getChild(4)) return _ret_string raise Exception("Not a key value ctx: " + ctx.getText())
def get_key_value_pattern(self, ctx: ParserRuleContext): """ returns the key/value pattern of the context It is assumed, that the context has 5 children, that represent the k/v: '0' left parenthesis '1' key '2' equals '3' value '4' right parenthesis :param ctx: the ParserRuleContext :return formatted key value string :rtype str """ _count = ctx.getChildCount() # count==5 indicates Key/Value context if _count == 5: _key = str(ctx.getChild(1)) if not self._ignore_keyword_case: if self._uppercase_keywords: _key = _key.upper() else: _key = _key.lower() _value = str(ctx.getChild(3)) if not self._ignore_value_case: if self._uppercase_values: _value = _value.upper() else: _value = _value.lower() _ret_string = str(ctx.getChild(0)) + _key + str(ctx.getChild(2)) + _value + str(ctx.getChild(4)) return _ret_string raise Exception("Not a key value ctx: " + ctx.getText())
def get_value_pattern(self, ctx: ParserRuleContext): """ :param ctx: the ParserRuleContext :return formatted key closing string :rtype str """ _count = ctx.getChildCount() if _count != 1: raise Exception("Not a value ctx: " + ctx.getText()) _key = str(ctx.getText()) if not self._ignore_value_case: if self._uppercase_values: _key = _key.upper() else: _key = _key.lower() _ret_string = _key return _ret_string
def __get_namespace_prefix(self, ctx: ParserRuleContext): prefix = "" while not isinstance(ctx.parentCtx, DynabuffersParser.CompilationContext): ctx = ctx.parentCtx if isinstance(ctx, DynabuffersParser.NamespaceTypeContext): prefix = "{}.{}".format(ctx.getText(), prefix) return prefix
def fun_wrapper(self, ctx: antlr4.ParserRuleContext) -> str: if PRINT_TREE: self.tree_depth += 1 print(' ' * self.tree_depth + ctx.getText().replace('\n', '; ')) ret_val = fun(self, ctx) self.tree_depth -= 1 return ret_val else: return fun(self, ctx)
def __init__(self, parent_node, filename: str, ctx: ParserRuleContext): """ :param parent_node: :param filename: :param ctx: ParserRuleContextNode """ super().__init__(parent_node) start = ctx.start self._filename = filename self._line = start.line self._column = start.column self._value = ctx.getText()
def get_key_opening_pattern(self, ctx: ParserRuleContext): """ returns the key opening pattern, like (address= :param ctx: the ParserRuleContext :return formatted key opening string :rtype str """ _count = ctx.getChildCount() if _count < 5: raise Exception("Not a key opening ctx: " + ctx.getText()) _key = str(ctx.getChild(1)) if not self._ignore_keyword_case: if self._uppercase_keywords: _key = _key.upper() else: _key = _key.lower() _ret_string = str(ctx.getChild(0)) + _key + str(ctx.getChild(2)) return _ret_string
def visitTerminal(self, ctx: ParserRuleContext) -> Terminal: """Converts case insensitive keywords and identifiers to lowercase""" text = ctx.getText() return Terminal.from_text(text, ctx)