Esempio n. 1
0
def test_regularexpression():
    regex = core.RegularExpression("[0-9]")
    with open("data.pkl", "wb") as jar:
        pickle.dump(regex, jar)
    with open("data.pkl", "rb") as jar:
        regex = pickle.load(jar)
    a = list(regex.matches_in_text("0a4"))
    assert len(a) == 2
Esempio n. 2
0
def test_regularexpression():
    regex = core.RegularExpression("[0-9]")
    with open("data.pkl", "wb") as jar:
        pickle.dump(regex, jar)
    with open("data.pkl", "rb") as jar:
        regex = pickle.load(jar)
    match = regex.match("123")
    assert match.span() == (0, 1)
    for match in regex.finditer("123"):
        pass
    matches = regex.findall("123")
    assert len(matches) == 3
Esempio n. 3
0
 def get_filter_regular_expression(self) -> core.RegularExpression:
     return core.RegularExpression(self.filterRegularExpression())
Esempio n. 4
0
    color = "#BC78DD"
    italic = True


class Strong(Rule):
    regex = r"(\*{2})([^\*\*]+)\1"
    color = "#D19A66"
    bold = True


class Code(Rule):
    regex = [r"`[^`]*`", r"^((?:(?:[ ]{4}|\t).*(\R|$))+)"]
    color = "grey"


TRI_SINGLE = (core.RegularExpression("```"), Code.get_format())


class MarkdownHighlighter(gui.SyntaxHighlighter):

    RULES = Rule.__subclasses__()

    def highlightBlock(self, text: str):
        super().highlightBlock(text)
        self.setCurrentBlockState(0)
        self._match_multiline(text, *TRI_SINGLE)

    def _match_multiline(
        self, text: str, delimiter: core.RegularExpression, style: gui.TextCharFormat
    ):
        # If inside triple-single quotes, start at 0
Esempio n. 5
0
class Number(Rule):
    regex = [
        r"\b[+-]?[0-9]+[lL]?\b",
        r"\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b",
        r"\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b",
    ]
    color = gui.Color(100, 150, 190)


# Multi-line strings (expression, flag, style)
# FIXME: The triple-quotes in these two lines will mess up the
# syntax highlighting from this point onward
fmt = gui.TextCharFormat()
fmt.set_foreground_color((30, 120, 110))
TRI_SINGLE = (core.RegularExpression("'''"), 1, fmt)
TRI_DOUBLE = (core.RegularExpression('"""'), 2, fmt)


class PythonHighlighter(gui.SyntaxHighlighter):
    """Syntax highlighter for the Python language."""

    RULES = Rule.__subclasses__()

    def highlightBlock(self, text: str):
        """Apply syntax highlighting to the given block of text."""
        # Do other syntax formatting
        super().highlightBlock(text)
        self.setCurrentBlockState(0)
        # Do multi-line strings
        if not self.match_multiline(text, *TRI_SINGLE):
 def set_regex(self, regex: str | core.RegularExpression, flags=0):
     if isinstance(regex, str):
         regex = core.RegularExpression(regex, flags)
     self.setRegularExpression(regex)
 def __getstate__(self):
     return dict(pattern=core.RegularExpression(self.regularExpression()))
Esempio n. 8
0
# see https://github.com/ITVRoC/SeekurJr/blob/master/seekur_12.04/packages/
# multimaster_fkie/node_manager_fkie/src/node_manager_fkie/yaml_highlighter.py

from __future__ import annotations

from prettyqt import core, gui, syntaxhighlighters

COMMENT_START = core.RegularExpression("#")
COMMENT_END = core.RegularExpression("\n|\r")  # Unused?
COMMENT_FORMAT = gui.TextCharFormat()
COMMENT_FORMAT.setFontItalic(True)
COMMENT_FORMAT.set_foreground_color("darkgray")


class Rule(syntaxhighlighters.HighlightRule):
    minimal = True


class Bool(Rule):
    regex = [r"\btrue\b", r"\bfalse\b"]
    color = "blue"
    bold = True


class Decimal(Rule):
    regex = r"\d+"
    color = "darkMagenta"


class Rule2(Rule):
    regex = r"^\s*[_.\w]*\s*:"
Esempio n. 9
0
    color = "lightgrey"


class Text(Rule):
    regex = r">(.+)(?=</)"


class Keyword(Rule):
    regex = [r"\b?xml\b", "/>", ">", "<", "</"]
    bold = True
    color = "red"


VALUE_FORMAT = gui.TextCharFormat()
VALUE_FORMAT.set_foreground_color("orange")
VALUE_START_EXPRESSION = core.RegularExpression(r"\"")
VALUE_END_EXPRESSION = core.RegularExpression(r"\"(?=[\s></])")


class XmlHighlighter(gui.SyntaxHighlighter):

    RULES = Rule.__subclasses__()

    def highlightBlock(self, text: str):
        super().highlightBlock(text)
        # HANDLE QUOTATION MARKS NOW.. WE WANT TO START WITH " AND END WITH "..
        # A THIRD " SHOULD NOT CAUSE THE WORDS INBETWEEN SECOND AND THIRD
        # TO BE COLORED
        self.setCurrentBlockState(0)
        start_index = 0
        if self.previousBlockState() != 1:
 def set_regex(self, regex: str):
     re = core.RegularExpression(regex)
     self.setRegularExpression(re)
 def __getstate__(self):
     return dict(regexp=core.RegularExpression(self.regularExpression()))