Incomprehensible unexpected token error in do...while loop - vue.js

It's perhaps the first time I use a do...while loop. I can't figure out what's wrong with it:
const randomLetter
do {
randomLetter = String.fromCharCode(97 + 26 * Math.random() | 0)
} while (state.lettersFound.includes(randomLetter))
At line do { I'm getting some unexpected token syntax error. Why?

The syntax for declaring a constant is:
const Identifier = Initializer
The parser is expecting to see an equals sign = after the identifier (randomLetter), but instead it unexpectedly sees the keyword do.
So, the error message and the error location is correct: the unexpected token is the keyword do and the error occurs at the token do.
Note: depending on the parser, the error message is more or less helpful, e.g. I get this in Node.js 13.1.0 / V8 7.8:
Thrown:
const randomLetter
^^^^^^^^^^^^
SyntaxError: Missing initializer in const declaration
Note: this is not really about do-loops: anything that is not an equals sign = would trigger a similar syntax error.
Note: vue.js cannot possibly have anything to do with this, since it is clearly a syntax / parse error and ECMAScript (like almost all languages and certainly all mainstream languages) does not allow libraries to change the fundamental syntax of the language.

Related

Disable Syntax Error "Symbol <id> could not be resolved" for some symbols in Eclipse Plugin using CDT

In my eclipse plugin I want to support my tool's language which extends C++ with some keywords and concepts. My language class, editor class and source parser class are all inheriting CDT classes for C++. I can parse the keywords and add nodes for them to the AST. But some of my keywords/commands the editor will always mark as "Symbol could not be resolved".
Example:
There is a command "#result" which returns the result of a last computation as an enum value that is defined in some header file in the tool's core.
typedef enum {
OK = 0;
WARNING = 1;
ERROR = 2;
} errCode_t;
So the command #result returns 0, 1 or 2. But inside the editor the command is marked as Symbol '#result' could not be resolved. No I want to tell the Indexer to not try to resolve this very token.
In the Preprocessor class I could change the token type from IToken.tIDENTIFIER to, say, 50000. What I try to achieve by that is something like
if (token.getType() == 50000) {
// don't try to resolve symbol
return null;
} else {
return super.resolveSymbol();
}
Is there a way to do that? I think my first problem is that I don't understand who or what is responsible for the Syntax Error Marking (maybe the Indexer?).
Errors of the form Symbol ... could not be resolved are produced by CDT's Code Analysis component, specifically ProblemBindingChecker, which traverses the AST and reports the error for any IASTName which resolves (via IASTName.resolveBinding()) to a ProblemBinding.
It is only IASTName nodes which resolve to bindings, so if you are getting this error for your #result token, that suggests the parser is building an IASTName node for it. I'm not sure how that's happening if you've changed the token type, I suppose it depends on how you handle the new token type in your extended parser.

Trying to deserialize and serialize a table in lua using the serpent library

So I am trying to do a simple serialization of a lua table, and deserialize it back into a table. But for some reason it just fails.
local a = {}
a[0] = {name="presetA"}
local line = serpent.line(a)
local presets, err = loadstring(line)
if (err) then
log("Error")
log(err)
else
log("Success")
log(serpent.block(presets))
end
After running, log(err) shows
[string "{[0] = {name = "presetA"}}"]:1: unexpected symbol near '{'
loadstring loads a Lua chunk from the given string and runs it.
As your serialized table is not a valid Lua expression the interpreter reports the observed error.
Let's serialze an example:
serpent.line({key = "value"})
returns
"{key = "value"} --[[table: 0D80CF40]]"
A table constructor on it's own is not a valid Lua expression.
Try to run that line and you'll Lua will report:
input:1: unexpected symbol near '{'
The output of serpent.line cannot be used as input to loadstring.
Now see the difference if you use serpent.dump instead
"do local _={name="hallo"};return _;end"
This is a valid, executable Lua chunk that will return the serialized table.
Please note the following section from the serpent documentation:
Note that line and block functions return pretty-printed data
structures and if you want to deserialize them, you need to add return
before running them through loadstring. For example:
loadstring('return '..require('mobdebug').line("foo"))() == "foo".
While you can use loadstring or load functions to load serialized
fragments, Serpent also provides load function that adds safety checks
and reports an error if there is any executable code in the fragment...
Please read manuals.

Mongodb SyntaxError: Unexpected token }

This is my query
db.courses.find({"courses"})
on my courses collection. I'm not sure what's going wrong in my syntax considering I have two brackets.
The error says
E QUERY SyntaxError: Unexpected token }
You need to past a valid JSON object to the find() method
{courses:'xxx'}
If you are trying to get all, then you just need to paste a empty braces, db.courses.find({}) or leave it blank.
Read a little more about MongoDB and the find method in the documentation.

Calling one module from another

I am trying to call one of the 2 modules (fifo_test_1 or fifo_test_2) depending on the value of bit data[0] in the following Verilog code.
module VC_selector(data);
input [10:0] data;
always # (data[0])
begin
if(~data[0])
begin
fifo_test_1 t1(.buf_in(data));
end
else if (data[0])
begin
fifo_test_2 t2 (.buf_in(data));
end
end
endmodule
fifo_test_1 and fifo_test_2 modules are working fine. But the above code gives these errors:
** Error: C:/Users/Swayam/Documents/VC_selector.v(8): Undefined variable: fifo_test_1.
** Error: C:/Users/Swayam/Documents/VC_selector.v(8): near "t1": syntax error, unexpected IDENTIFIER
** Error: C:/Users/Swayam/Documents/VC_selector.v(12): Undefined variable: fifo_test_2.
** Error: C:/Users/Swayam/Documents/VC_selector.v(12): near "t2": syntax error, unexpected IDENTIFIER
Please help me debug the code.
You cannot change the modules included while the hardware is running. The modules must be a constant during execution. For that reason, you can't include a module definition inside an always statement.
One thing you could do is move the two modules outside the always block and use some logic to switch between their outputs. Because neither of the fifo modules have outputs that would be rather difficult to do in this particular case, but it is possible in the general case.
assign my_switched_output = data[0] ? module_1_output : module_2_output;
The ternary operator (used here) allows you to do this switching that it appears you are attempting to do.
Another thing to make sure you have done is to include both the module file you are trying to simulate/synthesize AND all of the submodule verilog files you need in the command. How to include all of these files based on the simulator.

Why am I getting this Objective-C error message: invalid conversion from 'objc_object*'

This error message had me stumped for a while:
invalid conversion from 'objc_object* to 'int'
The line in question was something like this:
int iResult = [MyUtils utilsMemberFunc:param1,param2];
It doesn't matter what the "to" type is, what is important is that you recognize that this message, in this context, is reporting that the utilsMemberFunc declaration was not found and due to Objective-C's dynamic binding it is assuming it returns an objc_object* rather than the type that utilsMemberFunc was declared to return.
So why isn't it finding the declaration? Because ',' is being used rather than ':' to separate the parameters.