ANTLR v3: token file - 'array' and 'null' - antlr3

See ANTLR v3: order token to improve performance of tree walker as pre-info
Unfortunately I have problems with 'array' and 'null' as tokens. If I specify them in the token file as follows:
TypeArray=394
'array'=394
Null=395
'null'=395
Then it seems that ANTLR does not recognise the tokens any more. I got the following error message when I am compiling the grammar:
TSPHP.g:582:4: no lexer rule corresponding to token: TypeArray
TSPHP.g:980:4: no lexer rule corresponding to token: Null
And furthermore when I am debugging:
[18:59:10] warning(24): template error: context [/outputFile /parser /genericParser /region__/genericParser__members /region__/genericParser__members /_sub290] 8:27 no such property or can't access: null.hasSynPred
How I am supposed to specify the tokens in order that it works?
Edit:
As additional information. When I generate the grammar file without using the tokenVocab option then it seems to work. When I then try to use the generated token file as input for tokenVocab then I get the following exception:
[18:49:28] error(10): internal error: D:\TSPHP-parser\antlr\TSPHP.g : java.lang.NullPointerException
org.antlr.tool.AssignTokenTypesBehavior.aliasTokenIDsAndLiterals(AssignTokenTypesBehavior.java:278)
org.antlr.tool.AssignTokenTypesBehavior.defineTokens(AssignTokenTypesBehavior.java:215)
org.antlr.tool.CompositeGrammar.assignTokenTypes(CompositeGrammar.java:347)
org.antlr.Tool.process(Tool.java:481)
org.antlr.works.generate.CodeGenerate.generate(CodeGenerate.java:104)
org.antlr.works.generate.CodeGenerate.run(CodeGenerate.java:185)
java.lang.Thread.run(Thread.java:722)
I realised that this was due to the token '\\' which needed to be specified as follows '\\\\'. But as soon as I have fixed this issue then I get the same problem again as above (no lexer rule....)

Related

HAPI FHIR R4 : Modifiers on ReferenceParam

I'm currently building a FHIR (R4) Server, and i try to implement the following request:
[base]/PractitionerRole?practitioner.active:not=true
I know that active is a Token Param, and thanks to HAPI, i can use the following command :
TokenParam tokenSubject = referenceParam.toTokenParam(myContext);
But sadly, all the modifier part is lost : in my referenceParam, i only have a chain part (active:not), and a value part (true), so i don't have any modifiers, missing, etc..
So when i convert it to a TokenParam, i don't have neither the modifiers, missing, etc ...
So here is my question : Is there a way to have a ReferenceParam that has modifiers?
I would like to have a chain part (active), a modifier (not) and a value (true), as in a real TokenParam
Your syntax looks correct. My best guess is you're using token search directly, instead of as part of a chain.
Token/Identifier alone would be appropriate if you were searching for active directly on PractionerRole.
For example: http://hapi.fhir.org/baseR4/PractitionerRole?active:not=true
However, you're doing a nested search with ?practitioner.active:not=true
Try Search Parameters > 4.5.9 Chained Resource References > Dynamic Chains
For example: http://hapi.fhir.org/baseR4/PractitionerRole?practitioner.active:not=true
NB: active:not=true will return both active:missing and active=false

SpelParseException: After parsing a valid expression, there is still more data in the expression: 'lcurly({)'

I am trying to condtionally create a component using #ConditionalOnExpression("not ${service.synchronous} && not ${service.disabled}").
I based this on Spring Boot SpEL ConditionalOnExpression check multiple properties, which provides a multi-property conditional as follows: #ConditionalOnExpression("${properties.first.property.enable:true} && ${properties.second.property.startServer:false}")
However, I keep getting:
Caused by: org.springframework.expression.spel.SpelParseException: EL1041E: After parsing a valid expression, there is still more data in the expression: 'lcurly({)'
Those properties are always set in my .properties file so I did not provide a default value with the colon notation. What am I doing wrong?
You will need to provide the default values for your properties like in the example you followed, so update the expression to be:
#ConditionalOnExpression("not ${service.synchronous:false} && not ${service.disabled:true}")
In most such cases the properties your app is reading are not what you expect them to be.
Set a breakpoint on all constructors of SpelParseException. In the debugger you will see the expression that is parsed, that will give show you exactly which properties you are really using.
Maybe you have to go search a little in the stack until you find the right location where you can see the expression.
My mistake was that I had not imported the test properties file in a Spring test.
After I added #TestPropertySource("classpath:/application.properties") to the test class, the properties from the properties file were used.

Issues when uploading data to Google Alerts

I am trying to upload a list of companies to Google Alerts, but getting this error:
CasperError: Errors encountered while filling form: Unable to find field element in form: FieldNotFound: setField: Invalid field ; only HTMLElement is supported
/Users/sam/Documents/Work/google-alerts-export-import/phantomjs:/platform/casper.js:837 in fillForm
/Users/sam/Documents/Work/google-alerts-export-import/phantomjs:/platform/casper.js:930 in fillSelectors
/Users/sam/Documents/Work/google-alerts-export-import/phantomjs:/code/galerts.js:229
/Users/sam/Documents/Work/google-alerts-export-import/phantomjs:/platform/casper.js:1637 in runStep
/Users/sam/Documents/Work/google-alerts-export-import/phantomjs:/platform/casper.js:414 in checkStep
Here's the sample.csv file data:
Apple;At most once a week;Blogs;English;Argentina;All results;RSS feed
And I run it as:
casperjs galerts.js import --file=sample.csv --delete-others
Here's the Github for the program:
https://github.com/jra11/google-alerts-export-import
This happens due to mismatch in versions of library, downgrade casper.

Stripes Framework expression validation on property

I am trying to add expression validation on my property on actionbean but I am unable to make it work. I have even tried with integers like this >0 but still the same exception is thrown. Below is the code
#Validate(required=true, minvalue=1, expression="${this > maxBudget}")
int minBudget;
int maxBudget;
I am getting the below exception:
net.sourceforge.stripes.exception.StripesRuntimeException: Could not parse the EL expression being used to validate
field minBudget. This is not a transient error. Please double check the following expression for errors: ${this > maxBudget}
caused by
javax.el.ELException: The identifier [this] is not a valid Java identifier as required by section 1.19 of the EL specification (Identifier ::= Java language identifier).
This check can be disabled by setting the system property org.apache.el.parser.SKIP_IDENTIFIER_CHECK to true.
I have tried few variation, but every time it throws this exception.
Can some one please point out the mistake I am doing here
thanks
If you want to make sure minBudget is larger than maxBudget (isn't that the other way around?) you could just do:
#Validate(required=true, minvalue=1, expression="${minBudget > maxBudget}")
For greater flexibility you could consider implementing a custom validation method:
#ValidationMethod(on={"show"})
public void checkBudgetRange(ValidationErrors errors) {
if (minBudget < maxBudget)
errors.addGlobalError( new SimpleError("This is not good..."));
// all sorts of other checks to your liking
}
The on array argument holds the name(s) of the event handler(s) for which you want to perform this validation method. So in the example here that would be public Resolution show().
There's an excellent explanation at the Stripes Framework site at https://stripesframework.atlassian.net/wiki/display/STRIPES/Validation+Reference
UPDATE:
If you want to make use of the this keyword in validation expressions you may need to add a VM argument to your server (tested this on Tomcat 8):
-Dorg.apache.el.parser.SKIP_IDENTIFIER_CHECK=true
Otherwise the abovementioned error may be thrown.
The default value of org.apache.el.parser.SKIP_IDENTIFIER_CHECK was changed from true to false as of version 7 in Tomcat.
https://tomcat.apache.org/tomcat-6.0-doc/config/systemprops.html
https://tomcat.apache.org/tomcat-7.0-doc/config/systemprops.html

Error Code Reference for OSX/Cocoa

If I get an error code result from a Cocoa function, is there any easy way to figure out what it means (other than by grepping through all the .h files in the framework bundles)?
You should look at the <Framework/FrameworkErrors.h> header for whatever framework the method you're using that's returning an error comes from.
For example, an NSError in the Cocoa domain that you get from a method in the Foundation framework will have its code property described in the <Foundation/FoundationErrors.h> header. Similarly with AppKit and <AppKit/AppKitErrors.h> and Core Data and <CoreData/CoreDataErrors.h>.
Also, if you print the description of the NSError in the debugger, it should include not only the error domain and code, but also the name of the actual error code constant so you can look it up in the API reference.
The sections on 'Error Domains' and 'Error Codes' in Apple's Error Handling Programming Guide address this reasonably well. You need to do the following:
Log the error, taking note of both the error domain (a human-readable / Googleable string that tells you where to look for the error code definitions) and the error code itself (an integer)
Sniff around on Google (or read from the list below) and figure out the name of the header file(s) where the error codes for that error domain are defined
Search those header file(s) for the error code you got. You should find both a constant name for the error code (like ENOMEM), and hopefully also an explanatory comment (like /* Cannot allocate memory */) explaining what the error means. If there's no comment, and the constant name isn't self-explanatory, just Google the constant name and you'll probably find a proper description.
Some header files of major error domains:
NSCocoaErrorDomain
Error code declarations are spread across three header files:
<Foundation/FoundationErrors.h> (Generic Foundation error codes)
<AppKit/AppKitErrors.h> (Generic AppKit error codes)
<CoreData/CoreDataErrors.h> (Core Data error codes)
NSURLErrorDomain
Check NSURLError.h
NSXMLParserErrorDomain
CheckNSXMLParser.h
NSMachErrorDomain
Check /usr/include/mach/kern_return.h
NSPOSIXErrorDomain
Check /usr/include/sys/errno.h
NSOSStatusErrorDomain
Check
/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework/Headers/MacErrors.h
Also, Cocoa's NSError is meant to be displayable to the end user. If you just log it, it should be readable.
If you're talking about Carbon's OSStatus and such, MacErrors.h.
For NSError errors add a line of code:
NSError *error;
// ... Some code that returns an error
// Get the error as a string
NSString *s = [error localizedDescription];
// Observe the code for yourself or display to the user.

Resources