I'm trying to run some unit tests using QUnit written in CoffeeScript but there seems to be some reserved words that are causing problems, most notably "not". Is there a way to escape a CoffeeScript reserved word? Here's a simple test that demonstrates the problem:
module "Sad face test"
test "will not compile", ->
not false, "holy crap this creates a syntax error :-("
The error this generates is "Parse error on line 3: Unexpected ','"
The best answer I have been able to find is to escape into JavaScript and alias the function:
notEqual = `not`
module "Sad face test"
test "will not compile", ->
notEqual false, "holy crap this creates a syntax error :-("
Although it looks like not isn't a function within the latest version of QUnit, so in this specific instance you may not need to to escape a CoffeeScript reserved word.
The not function is global, so it's actually attached to window, right? Instead of backtick escapes, then, you can just write
window.not
instead of not; or
notEqual = window.not
Related
I recently started using a 3rd party extension for language supporting robot programming (RoboDK). The extension is pretty good but doesn't include many of the commands I would like to use and doesn't correctly (at least to me) handle optional arguments to commands. I'd like to 'extend' the extension to support additional commands (and potentially provide this feedback to the developer).
I'm specifically using ABB's RAPID robot language.
Example:
MoveL robtarget, speeddata, zonedata, tooldata \WObj:=WObj0;
For MoveL, var1 thru var4 are required but \WObj:=WObj0 is optional. The '\WObj0:=' part of the string is a constant (if supplying the option) and WObj0 would be a variable of the expected type for MoveL (a work object, in this case).
Is there a way to edit the snippets json to not enter the optional part unless I start typing a backslash followed by text? I also would like to keep the optional part in the snippet as a reference so I don't have to remember every optional argument as some commands have many options.
Here's an excerpt from the snippet.abb.json file:
"movel": {
"prefix": "movel",
"body": [
"MoveL ${1:var_robtarget}, ${2:var_speeddata}, ${3:var_zonedata}, ${4:pers_tooldata} \\WObj:=WObj0;"
],
"description": "Linear motion"
},
Which results in the code with var_robtarget, var_speeddata, var_zonedata & pers_tooldata all highlighted and the remainder is plain text:
MoveL var_robtarget, var_speeddata, var_zonedata, pers_tooldata \WObj:=WObj0;
Is there a way to edit the snippets json to not enter the optional
part unless I start typing a backslash followed by text?
No, I don't think there is any way to do that within the same snippet. You could make another snippet with the backslash prefix but that is cumbersome.
Here is a simple way to do what you want but you will have to delete any optional variables you don't want:
"body" [
"MoveL ${1:var_robtarget}, ${2:var_speeddata}, ${3:var_zonedata}, ${4:pers_tooldata}${5: \\WObj:=WObj0}${6: anotherVar};"
]
That last variables are also selected when you get to them. If you don't want any just hit Delete.
In the above demo I am just tabbing and deleting.
I was writing some Perl code in vim and accidentally typed a single quote character in a variable name and noticed that it highlighted it in a different color than normal single quoted strings.
I thought that was odd, so I wrote a small test program (shown above) and tried to run it to see how Perl would handle it and I got this error:
"my" variable $var::with::apostrophes can't be in a package
What exactly is going on here? Are there situations where single quotes in variable names are actually valid? If so, what meaning do single quotes have when used in this context?
The single quote is the namespace separator used in Perl 4, replaced by the double colon :: in Perl 5. Because Perl is mostly backwards compatible, this still works. It's great for golfing, but not much else.
Here's an article about it on perl.com that doesn't explain it.
I have searched around quite a bit and have failed to find an answer. In AutoHotKey, I am not sure the difference when a single percent is used near the beginning of a line, and when a variable is enclosed between two percent signs. I usually use trial and error to find when I use one or the other, I am hoping someone could shed some light on what the difference is or explain what it is actually doing.
Here are some examples of this in action.
Example 1: I noticed if you have multiple variables along with text, scripts tend to go with the preceding percent. Such as:
some_val := Clipboard
loop 5
msgbox % "Index:" . A_Index . ", variable:" . some_val
Example 2: I often see this as well, and sometimes it appears it must be used. Is this true?
some_variable := "test text to send"
Send, %some_variable%
Wrapping in double percent signs is legacy AHK and basically there is no need to ever use it anymore. Only reason to wrap in double % would be being stuck behind in the old times, or maybe one could argue it also being more convenient, or something, to write in some cases, but I'm not buying it.
The legacy syntax is replaced by expression syntax.
The expression syntax is closer to how many other languages behave. AHK legacy syntax really is a mess.
All legacy commands (MsgBox for example) use the old legacy syntax on each parameter (unless otherwise specified).
If you specify a % followed up by a space at the start of the parameter, you're forcing AHK to evaluate an expression on that parameter instead of reading it as a legacy text parameter.
Example:
MsgBox, 5+5
We're using a legacy command, we're not starting the parameter off with a % and a space, so we're using the legacy syntax. The MsgBox is going to print the literal text 5+5 instead of 10.
MsgBox, % 5+5
Again, legacy command, but now we're forcing AHK to evaluate an expression here, 5+5.
The result of expression's evaluation is going to be passed onto the MsgBox command and the MsgBox is going to print 10.
If we wanted to MsgBox to print the literal text 5+5, and use the expression syntax to do it, we'd do MsgBox, % "5+5".
Quotation marks in expression syntax mean we're specifying a string.
Well then there's the problem of knowing when you're in expression syntax, and when you're in the legacy syntax.
By default, you're basically always in an expression.
You leave it by for example using a command or = to assign.
If the difference between a command and a function isn't clear to you, here's an example:
Command, % 7+3, % MyCoolArray[4], % SomeOtherNiceFunction(), % false
Function(7+3, MyCoolArray[4], SomeOtherNiceFunction(), false)
In the command we specified a % followed up by a space to evaluate the expressions on each parameter, and in the function, we didn't have to do that since we're already in an expression.
And if you're not clear on the difference between = and :=,
= is legacy and deprecated, it assigns plain text to a variable
:= assigns the result of an expression to a variable.
So that's what I could write from on top of my head.
If you had some more complex examples, I could try showing on them. Maybe convert some code you may have over to expression syntax, make it 100% free of legacy syntax.
And here's a good page on the documentation you should give a read:
https://www.autohotkey.com/docs/Language.htm
I'm trying to write a custom problem matcher for VS Code. My matcher matches nothing, even though testing the regular expressions on the output seem to work. I'm not even sure VS Code loads my problem matcher, let alone see which regular expression matches and which isn't.
Is there a way to debug a problem matcher? I'm basically stuck with no way to move forward.
This is an old question, but I found this site super helpful:
https://regex101.com/
It allows you to debug regular expressions. You can put an example line of compiler output and try your matcher against it.
One issue I had to figure out is that the VS Code expression is stored in a JSON file, so it has extra escape characters that should be removed if you're using the regex somewhere else.
I've been looking around.
storeEval does not exist anymore.
Commands 'runScript' & 'executeScript' seem to replace it.
However, the syntax proposed in many posts javascript{script here} is not accepted: it refuses the first {. Same for the variables with the storeVars['foo'] which seems to be replaced by ${foo}.
Trying any javascript expression (even very simple) with both commands gets me a message 'Failed: missing ) after argument list'.
For instance: | run Script | "aString" + ${previouslyStoredVar} | outputVar |
(note: the syntax of the command seems to be 'runScript', but appears as 'run script' in the IDE window).
I tried adding a return(expression), putting brackets around the expression, enclosing ${previouslyStoredVar} in double quotes, trying with an even simpler expression, and everything I could think of, but with always the same error message.
What is it I am doing wrong? It must be obvious but I can't figure it out!
Many thanks,
E.
My bad: just tried with 'return ${price_string}.substr(0, 5)' and it works. Have to find out why the other commands were not working. I'll dig and report!
OK, the pb remain but is quite different from my exepectation. The exact same expression and the same context works in a second test, but fails in the first test (with the missing parenthesis message). Seems to be a bug in the IDE then, or a corruption of some sort of the Selenium script...