Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for "SINUMERIK 840D language support" package. #379

Merged
merged 6 commits into from Oct 30, 2016
Merged
24 changes: 24 additions & 0 deletions bh_core.sublime-settings
Expand Up @@ -559,6 +559,30 @@
"language_filter": "whitelist",
"language_list": ["CMake"],
"enabled": true
},
// SINUMERIK 840D SL G-Code
{
"name": "s840d_gcode",
"open": "\\b(IF(?!.*GOTO)|FOR|WHILE|REPEAT(?!.*GOTO))\\b",
"close": "\\b(END(?:IF|FOR|WHILE)|UNTIL)\\b",
"style": "tag",
"scope_exclude": ["string", "comment"],
"plugin_library": "bh_modules.s840d_gcode",
"language_filter": "whitelist",
"language_list": ["s840d_gcode"],
"enabled": true
},
// SINUMERIK 840D SL RunMyHmi
{
"name": "s840d_hmi",
"open": "^\\s*(//[ABGMS]|ACTIVATE|CHANGE|FOCUS|IF|LOAD|UNLOAD|OUTPUT|PRESS|SUB)\\b",
"close": "^\\s*(//END|END_(?:ACTIVATE|CHANGE|FOCUS|IF|LOAD|UNLOAD|OUTPUT|PRESS|SUB))\\b",
"style": "tag",
"scope_exclude": ["string", "comment"],
"plugin_library": "bh_modules.s840d_hmi",
"language_filter": "whitelist",
"language_list": ["s840d_hmi"],
"enabled": true
}
],

Expand Down
20 changes: 20 additions & 0 deletions bh_modules/s840d_gcode.py
@@ -0,0 +1,20 @@
"""
BracketHighlighter.

Copyright (c) 2013 - 2016 Deathaxe <deathaxe82@gmail.com>
License: MIT
"""


def compare(name, first, second, bfr):
"""Ensure correct open is paired with correct close."""

o = bfr[first.begin:first.end].lower()
c = bfr[second.begin:second.end].lower()

match = False
if o == "repeat" and c == "until":
match = True
elif c == "end" + o:
match = True
return match
22 changes: 22 additions & 0 deletions bh_modules/s840d_hmi.py
@@ -0,0 +1,22 @@
"""
BracketHighlighter.

Copyright (c) 2013 - 2016 Deathaxe <deathaxe82@gmail.com>
License: MIT
"""


def compare(name, first, second, bfr):
"""Ensure correct open is paired with correct close."""

o = bfr[first.begin:first.end].lower()
c = bfr[second.begin:second.end].lower()

match = False
# classes
if o in ["//a", "//b", "//g", "//m", "//s"] and c == "//end":
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of creating a new list instance every time the compare method is called, how about creating a static tuple up front?

S840D_HMI_CLASSES = ("//a", "//b", "//g", "//m", "//s")

...

if o in S840D_HMI_CLASSES and c == "//end":

See the following for reference: https://github.com/facelessuser/BracketHighlighter/blob/master/bh_modules/rubykeywords.py.

We don't really need a dynamic list and tuples are faster to assign to. And this way we only bother allocating the object when the file is loaded, after that all calls to the compare method just references the object.

Everything else looks fine.

match = True
# methods
elif c == "end_" + o:
match = True
return match