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

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

merged 6 commits into from Oct 30, 2016

Conversation

deathaxe
Copy link
Contributor

Could you please add bracket rules for my CNC SINUMERIK 840D package, please?
see here

{
"name": "s840d_gcode",
"open": "(?i)\\b(IF(?!.*GOTO)|FOR|WHILE|REPEAT(?!.*GOTO))\\b",
"close": "(?i)\\b(END(?:IF|FOR|WHILE)|UNTIL)\\b",
Copy link
Owner

Choose a reason for hiding this comment

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

Is UNTIL meant to be REPEAT? If so, you might want to implement a bh_module to ensure this pairing. You can check out existing bh_modules. Maybe this one would help: https://github.com/facelessuser/BracketHighlighter/blob/master/bh_modules/luakeywords.py.

// SINUMERIK 840D SL G-Code
{
"name": "s840d_gcode",
"open": "(?i)\\b(IF(?!.*GOTO)|FOR|WHILE|REPEAT(?!.*GOTO))\\b",
Copy link
Owner

Choose a reason for hiding this comment

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

Don't use (?i), it should already be case insensitive. If you need to enforce case, do it in a bh_module. These flags will affect all currently active rules.

@deathaxe
Copy link
Contributor Author

Added bh_modules for both syntaxes and removed the (?i) tags.


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.

@deathaxe
Copy link
Contributor Author

This is actually a good idea. I unfortunatelly took the bashsupport.py as an example, which creates a list, too. So I would suggest to change it to use static tubles, too.

@facelessuser
Copy link
Owner

I agree. I am trying to be more thorough, but it doesn't surprise me that bad examples exist from previous pulls.

@@ -8,6 +8,9 @@
lowercase = import_module("bh_modules.lowercase")


BASH_KEYWORDS = ("select", "for", "while", "until")
Copy link
Owner

Choose a reason for hiding this comment

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

Only one blank line is needed before this. You will only see two before functions and classes in the global scope. It's a Python PEP8 thing.

"""


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

Choose a reason for hiding this comment

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

Same as mentioned previously. Only one blank line before this.

@deathaxe
Copy link
Contributor Author

You are very thorough now, even more than me. ;-) Neither SublimeLinter nor your travis-ci displayed an linting error for this blank line. But I agree, with you and removed it to make code as clean as possible.

@facelessuser
Copy link
Owner

Yeah, I was surprised the linter didn't pick it up. I would have easily missed it if it wasn't the only change in that last revision :).

Thanks for the pull. This should make it in the next release.

@facelessuser facelessuser merged commit 027dcb1 into facelessuser:master Oct 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants