Why can't I use the antlr4 parse objects - antlr4

I'd like these sentences to be valid:
user ACCESS
...
insert into ACCESS.dba.table ...
But result contains error
when i use user[ACCESS] or replace 'ACCESS' to other, Is ok
It looks like access is a keyword, But I didn't find the relevant information

Related

Using Groovy 3 YamlBuilder with Yaml that contains a hyphen

I'm trying to write a Groovy 3 script that uses yamlbuilder to write a yaml file. I have it working on almost everything apart from;
execution:
set-props:
url:http://myhouse.net
port:8000
How do I write a map that allows the use of a hyphen in the name? Following my previous work I foolishly tried;
def setprops=[:]
setprops=(["url":"http://myhouse.net","port":"8000"])
execution.set-props=setprops
Which gives me an error 'The LHS of an assignment should be a variable or a field'.
If I just use execution.setprops then it works fine, but of course the resulting yaml from yaml(execution) is invalid.
I think if the set-props was a a key/value pair then it could go into quote and everything would be good. But because it is part of the structure I don't know what needs to be done.
You can use strings as "methods" and the builder will create your
intermediate structures from them:
import groovy.yaml.YamlBuilder
def b = new YamlBuilder()
b.execution {
"set-props"(
url: "..."
)
}
println b
Or to continue on your example: You can create the whole map and use is as argument, where you want to have that content.
def setprops=["set-props": [url:"..."]]
b.execution(setprops)
Both result in:
---
execution:
set-props:
url: "..."
Note that the first version nests via passed closures and then passes in the map. The second bit just passes a nested map.

How to interpolate expressions in Terraform?

I'm trying to use the keys expression in Terraform to grab a list of keys (from a map variable) and assign it to a local variable. Here is the code snippet:
locals {
project_name_list = keys(${var.project_map})
}
However, I'm getting the following error:
Unknown token: 29:22 IDENT keys
Am I missing something here. Nowhere can I find an example of this expression. As bad as it is, even the official documentation does not help -https://www.terraform.io/docs/configuration/functions/keys.html
HashiCorp has really done a bad job of elaborating the nuances of Terraform for beginners on their website.
Terraform functions need to be wrapped in expression syntax to show that it's not a literal value: "${}"
So try this: project_name_list = "${keys(var.project_map)}"
The example in the documentation is written as though being run from the terraform command line, which already assumes the command is a HCL expression and doesn't require that syntax.
UPDATE
I said above that the expression syntax is to show that it's not a literal value. It's probably more accurate to speak of it as expression syntax vs. configuration syntax. Configuration syntax is the first level of interpolation, which forms the basic structure of your terraform file with resource blocks, data blocks, etc. The second interpolation level is expression syntax which is used to generate values used by your configuration.
Thinking of it in these terms makes better sense of the error message, Unknown token, because terraform is attempting to read it as a configuration key word.
I had compared it to a literal value because it's in the same position as where a literal value would be.

Can I put one check on a Lexial element instead for on a number of parser rules?

I,m trying to use antlr4 with the IDL.g4 grammar, to implement some checks that our idl-files shall follow. One rule is about names. The rule are like:
ID contains only letters, digits and signle underscores,
ID begin with a letter,
ID end with a letter or digit.
ID is not a reserved Word in ADA, C, C++, Java, IDL
One way to do this check is to write a function that check a string for these properties and call it in the exit listeners for every rule that has an ID. E.g(refering to IDL.g4) in exitConst_decl(), exitInit_decl(), exitSimple_declarator() and a lot of more places. Maybe that is the correct way to do it. But I was thinking about putting that check directly on the lexical element ID. But don't know how to do that, or if it is possible at all.
Validating this type of constraint in the lexer would make it significantly more difficult to provide usable error messages for invalid identifiers. However, you can create a new parser rule identifier, and replace all references to ID in various parser rules to reference identifier instead.
identifier
: ID
;
You can then place your identifier validation logic inside of the single method enterIdentifier instead of all of the various rules that currently reference ID.

How to use MFC Resource id stored as string

I am developing an MFC application in which I have menus defined in .rc file. I have an requirement for removing of few menu items at run time which are defined in xml file.
The menu ids are stored as string in xml as like below
<exclusionmenu>ID_FILE_NEW</exclusionmenu>
<exclusionmenu>ID_FILE_OPEN</exclusionmenu>
From xml the menu ids are retrieved as string,
RemoveMenu function expects UINT (menu id),
How to convert the menu id string defined in xml to uint menu id
Note: This is not direct cstring to uint conversion, ID_FILE_NEW is macro and it has int value.
The symbolic names for resource identifiers are defined in a header file, Resource.h by default. In source code and resource scripts, the symbolic names are substituted for their respective numeric values by the preprocessor. When compilation begins, the symbolic information is already gone.
To implement a scheme that uses symbolic names for configuration, you have to extract and preserve the mapping between symbolic names and resource identifiers for later use at runtime, or apply the mapping to your configuration files prior to deployment. The following is a list of potential options:
Use an associative container and populate it at application startup: An appropriate container would be std::map<std::string, unsigned int>. Populating this container is conveniently performed using C++11's list initialization feature:
static std::map<std::string, unsigned int> IdMap = {
{"ID_FILE_NEW", ID_FILE_NEW},
{"ID_FILE_OPEN", ID_FILE_OPEN},
// ...
}
At runtime you can use this container to retrieve the resource identifier given its symbolic constant:
unsigned int GetId(const std::string& name) {
if (IdMap.find(name) == IdMap.end())
throw std::runtime_error("Unknown resource identifier.");
return IdMap[name];
}
The downside to this approach is that you have to keep IdMap and the resources in sync. Whenever a resource is added, modified, or removed, the container contents must be updated to account for the changes made.
Parse Resource.h and store the mapping: The header file containing the symbolic identifier names has a fairly simple structure. Code lines that define a symbolic constant usually have the following layout:
\s* '#' \s* 'define' \s+ <name> \s+ <value> <comment>?
A parser to extract the mappings is not as difficult to implement as it may appear, and should be run at an appropriate time in the build process. Once the mapping has been extracted, it can be stored in a file of arbitrary format, for example an INI file. This file can either be deployed alongside the application, or compiled into the binary image as a resource. At application startup the contents are read back, and used to construct a mapping as described in the previous paragraph. In contrast to the previous solution, parsing the Resource.h file does not require manually updating the code when resources change.
Parse Resource.h and transform the configuration XML file: Like the previous solution this option also requires parsing of the Resource.h file. Using this information, the configuration XML file can then be transformed, substituting the symbolic names for their numeric counterparts prior to deployment. This, too, requires additional work. Once this is done, though, the process can be automated, and the results verified to maintain consistency. At runtime you can simply read the XML and have the numeric identifiers readily available.
The only way your scenario would work is when you distribute Resoutce.h with your application and you have logic to parse Resource.h at startup into a table containing ID_* names and their values.
You can't, the string form is 'lost' at compile time, it's a preprocessor token. You can store the string variations of the menu items: somewhere in your code, have std::map and fill it with values: menu_ids["ID_FILE_NEW"] = ID_FILE_NEW; Then you call RemoveMenu(menu_ids[string_from_xml]);

SSIS: Filtering Multiple GUIDs from String Variable as Parameter In Data Flow OLE Source

I have an SSIS package that obtains a list of new GUIDs from a SQL table. I then shred the GUIDs into a string variable so that I have them separated out by comma. An example of how they appear in the variable is:
'5f661168-aed2-4659-86ba-fd864ca341bc','f5ba6d28-7283-4bed-9f11-e8f6bef225c5'
The problem is in the data flow task. I use the variable as a parameter in a SQL query to get my source data and I cannot get my results. When the WHERE clause looks like:
WHERE [GUID] IN (?)
I get an invalid character error so I found out the implicit conversion doesn't work with the GUIDs like I thought they would. I could resolve this by putting {} around the GUID if this were a single GUID but there are a potential 4 or 5 different GUIDs this will need to retrieve at runtime.
Figuring I could get around it with this:
WHERE CAST([GUID] AS VARCHAR(50)) IN (?)
But this simply produces no results and there should be two in my current test.
I figure there must be a way to accomplish this... What am I missing?
You can't, at least not using the mechanics you have provided.
You cannot concatenate values and make that work with a parameter.
I'm open to being proven wrong on this point but I'll be damned if I can make it work.
How can I make it work?
The trick is to just go old school and make your query via string building/concatenation.
In my package, I defined two variables, filter and query. filter will be the concatenation you are already performing.
query will be an expression (right click, properties: set EvaluateAsExpression to True, Expression would be something like "SELECT * FROM dbo.RefData R WHERE R.refkey IN (" + #[User::filter] + ")"
In your data flow, then change your source to SQL Command from variable. No mapping required there.
Basic look and feel would be like
OLE Source query

Resources