コード例 #1
0
ファイル: util.py プロジェクト: bloff/rmtc-parsing
def has_head_element(opening_delimiter:Element):
    """
    Returns ``True`` if the given element is preceeded by an element with no whitespace in between.
    """
    possible_head_element = opening_delimiter.prev
    return (is_not_none(possible_head_element, ".code.range.position_after.index") and
            possible_head_element.code.range.position_after.index == opening_delimiter.range.first_position.index)
コード例 #2
0
def indented_lisp_printer(code_or_element, current_line = None) -> str:
    if current_line is None:
        current_line = [0]

    if isinstance(code_or_element, list):
        return (u"\n".join(lisp_printer(elm) for elm in code_or_element)) + u"\n"

    line_prefix = ""
    if is_not_none(code_or_element, ".range.first_position.line") and code_or_element.range.first_position.line > current_line[0]:
        current_line[0] = code_or_element.range.first_position.line
        line_prefix = "\n" + " " * (code_or_element.range.first_position.column - 1)

    if code_or_element.__class__ in _delimiters:
        left, right, comma_separated = _delimiters[code_or_element.__class__]
        lisp_form = left
        elms = [indented_lisp_printer(elm, current_line) for elm in code_or_element]
        lisp_form += (", " if comma_separated else  " ").join(elms)
        lisp_form += right
        return line_prefix + lisp_form
    elif isinstance(code_or_element, Token):
        if code_or_element.code is not None:
            return line_prefix + indented_lisp_printer(code_or_element.code, current_line)
        else:
            ret = code_or_element.print()
        return line_prefix + ret
    elif isinstance(code_or_element, Node):
        node_elms = [indented_lisp_printer(elm, current_line) for elm in code_or_element]
        return line_prefix + "\n".join(node_elms) + "\n"
    elif isinstance(code_or_element, Element):
        return line_prefix +indented_lisp_printer(code_or_element.code, current_line)
    else:
        return line_prefix + str(code_or_element)
 def applies(self, element:Element):
     return (
         not element.is_first() and
         is_token(element, Tokens.CONSTITUENT) and
         identifier_in(element.value, self.sym_vals) and
         is_not_none(element.prev, ".code.range.position_after.index", element, ".range.first_position.index") and
         element.prev.code.range.position_after.index == element.range.first_position.index
     )
 def applies(self, element: Element):
     return (not element.is_first()
             and is_token(element, Tokens.CONSTITUENT)
             and identifier_in(element.value, self.sym_vals) and
             is_not_none(element.prev, ".code.range.position_after.index",
                         element, ".range.first_position.index")
             and element.prev.code.range.position_after.index
             == element.range.first_position.index)
コード例 #5
0
ファイル: magicmirror.py プロジェクト: bloff/rmtc-parsing
 def extract_colorized_tokens(element):
     nonlocal colorized_tokens
     if element.color is not None and is_not_none(
             element,
             ".range.first_position.index") and is_not_none(
                 element, ".range.position_after.index"):
         token_color = element.color
         token_first = element.range.first_position.index
         token_after = element.range.position_after.index
         if not isinstance(token_color, int):
             return error(
                 'Colorization request: color of token "%s" was not int!'
                 % element.text)
         colorized_tokens.append(
             [token_color, token_first, token_after])
     if isinstance(element.code, Node):
         for subelement in element.code:
             extract_colorized_tokens(subelement)
コード例 #6
0
ファイル: util.py プロジェクト: bloff/rmtc-parsing
def has_head_element(opening_delimiter: Element):
    """
    Returns ``True`` if the given element is preceeded by an element with no whitespace in between.
    """
    possible_head_element = opening_delimiter.prev
    return (is_not_none(possible_head_element,
                        ".code.range.position_after.index")
            and possible_head_element.code.range.position_after.index
            == opening_delimiter.range.first_position.index)
コード例 #7
0
 def applies(self, element: Element):
     next = element.next
     return (next is not None
             and (not (element.is_first() and is_form(element.parent))
                  or not next.is_last()) and is_identifier(element)
             and element.code.name in self.token_vals
             and is_not_none(element, ".range.position_after.index", next,
                             ".range.first_position.index")
             and element.code.range.position_after.index
             == next.code.range.first_position.index)
コード例 #8
0
 def applies(self, element:Element):
     next = element.next
     return (
         next is not None and
         (not (element.is_first() and is_form(element.parent)) or not next.is_last()) and
         is_identifier(element) and
         element.code.name in self.token_vals and
         is_not_none(element, ".range.position_after.index", next, ".range.first_position.index") and
         element.code.range.position_after.index == next.code.range.first_position.index
     )
コード例 #9
0
ファイル: magicmirror.py プロジェクト: bloff/rmtc-parsing
 def extract_colorized_tokens(element):
     nonlocal colorized_tokens
     if element.color is not None and is_not_none(element, ".range.first_position.index") and is_not_none(
             element, ".range.position_after.index"):
         token_color = element.color
         token_first = element.range.first_position.index
         token_after = element.range.position_after.index
         if not isinstance(token_color, int):
             return error('Colorization request: color of token "%s" was not int!' % element.text)
         colorized_tokens.append([token_color, token_first, token_after])
     if isinstance(element.code, Node):
         for subelement in element.code:
             extract_colorized_tokens(subelement)
    def applies(self, element:Element):
        def _is_identifier_or_literal_immediately_after(next, element):
            return ((is_identifier(next) or is_literal(next)) and
                is_not_none(next, ".code.range.first_position.index") and
                element.code.range.position_after.index == next.code.range.first_position.index)

        def _is_begin_macro_token_immediately_after(next, element):
            return (is_token(next, Tokens.BEGIN_MACRO) and
                is_not_none(next, ".range.first_position.index") and
                element.code.range.position_after.index == next.range.first_position.index)

        next = element.next
        return (
            next is not None and
            (not (element.is_first() and is_form(element.parent)) or not next.is_last()) and
            is_identifier(element) and
            identifier_in(element.code, self.sym_vals) and
            is_not_none(element, ".code.range.position_after.index") and
            (_is_identifier_or_literal_immediately_after(next, element) or
             _is_begin_macro_token_immediately_after(next, element))
        )
    def applies(self, element: Element):
        def _is_identifier_or_literal_immediately_after(next, element):
            return ((is_identifier(next) or is_literal(next))
                    and is_not_none(next, ".code.range.first_position.index")
                    and element.code.range.position_after.index
                    == next.code.range.first_position.index)

        def _is_begin_macro_token_immediately_after(next, element):
            return (is_token(next, Tokens.BEGIN_MACRO)
                    and is_not_none(next, ".range.first_position.index")
                    and element.code.range.position_after.index
                    == next.range.first_position.index)

        next = element.next
        return (next is not None
                and (not (element.is_first() and is_form(element.parent))
                     or not next.is_last()) and is_identifier(element)
                and identifier_in(element.code, self.sym_vals)
                and is_not_none(element, ".code.range.position_after.index")
                and
                (_is_identifier_or_literal_immediately_after(next, element)
                 or _is_begin_macro_token_immediately_after(next, element)))
 def _is_begin_macro_token_immediately_after(next, element):
     return (is_token(next, Tokens.BEGIN_MACRO) and
         is_not_none(next, ".range.first_position.index") and
         element.code.range.position_after.index == next.range.first_position.index)
 def _is_identifier_or_literal_immediately_after(next, element):
     return ((is_identifier(next) or is_literal(next)) and
         is_not_none(next, ".code.range.first_position.index") and
         element.code.range.position_after.index == next.code.range.first_position.index)
 def _is_begin_macro_token_immediately_after(next, element):
     return (is_token(next, Tokens.BEGIN_MACRO)
             and is_not_none(next, ".range.first_position.index")
             and element.code.range.position_after.index
             == next.range.first_position.index)
 def _is_identifier_or_literal_immediately_after(next, element):
     return ((is_identifier(next) or is_literal(next))
             and is_not_none(next, ".code.range.first_position.index")
             and element.code.range.position_after.index
             == next.code.range.first_position.index)