Page MenuHome

Manual tool: kbd to regex
ClosedPublic

Authored by Tobias Heinke (TobiasH) on Feb 11 2018, 4:48 PM.

Details

Summary

adds possibility to check the order.
removes editing (and the dependency).

removes code (line 88) which i'm not sure what it does:
getting the line number in a complex way?

Diff Detail

Repository
rBM Blender Manual

Event Timeline

Tobias Heinke (TobiasH) edited the summary of this revision. (Show Details)Feb 11 2018, 4:53 PM
tools_rst/rst_check_syntax.py
99–117

Is it necessary to replace this with a regex? - AFAICS - this is a complete set of valid keys - why complicate things. (Regex, while powerful is harder to debug than a set of values)

108–155

String concatenation isn't efficient in Python, best build a list, then join it.

In this case it doesn't matter so much, but it's not a good habit, prefer to use conventions that don't backfire later on.

See: https://stackoverflow.com/questions/3055477

tools_rst/rst_check_syntax.py
99–117

Checking the order with a logic & sets/lists is way more complex.
The kbd should match the UI. Too many false negatives (e.g. "A-A-A")

108–155

Readability would suffer too much (brackets are also in the strings).
The time it takes to compile makes anything else than executed it once impractical.
String concating compared to compiling is insignificant.

tiny fix, all wheel

Campbell Barton (campbellbarton) added inline comments.
tools_rst/rst_check_syntax.py
108–155

I don't think this is less readable, in fact think its preferable.

pattern_str = ''.join((
    # Modifier
    r"^(Shift(?:\-|\Z))?(Ctrl(?:\-|\Z))?(Alt(?:\-|\Z))?(Cmd(?:\-|\Z))?",

    # Alphanumeric
    r"((?:",
    r"[A-Z0-9]|",
    r"(?:[\[\]<>/~!?'\"=]|\\\\)|",

    # Named
    '|'.join((
        "Comma", "Period", "Slash", "Backslash", "Plus", "Minus",
        # Editing
        "Tab", "Backspace", "Delete", "Return", "Spacebar",
        # Navigation
        "Esc", "PageUp", "PageDown", "Home", "End",
        "Up", "Down", "Left", "Right",
    )), '|',
    #   Numpad
    r"(?:Numpad(?:[0-9]|Plus|Minus|Delete|Slash|Period|Asterix))|",
    #   Function
    r"(?:F[1-9]|F1[0-2])" ,
    r")(?:\-|\Z))",
    r"{0,2}" if regular_as_mod else r"?",

    # Mouse
    r"(",
    #   Wheel
    r"(?:Wheel(Up|Down|In|Out)?)|",
    #   Buttons
    r"(?:(?:L|M|R)MB)|",
    #   Stylus
    r"(?:Pen|Eraser)",
    r")?$",
))
This revision is now accepted and ready to land.Feb 13 2018, 3:06 AM
This revision was automatically updated to reflect the committed changes.