RSyntaxTextArea Custom Language JFlex - java

I'm trying to use JFlex to add custom language highlighting to RSyntaxTextArea. However, the moment I type a character I get an Index Out of Bounds Exception:
http://pastie.org/private/ygjyj4y5nludeu3dn1xug
This occurs even if I use the example JFlex code provided here: https://github.com/bobbylight/RSyntaxTextArea/wiki/Adding-Syntax-Highlighting-for-a-new-Language
I'm not sure what could be causing this. Could someone point me in the right direction?

I'm not quite sure why this works, but I appear to have fixed this problem by copying part of the yylex method from PythonTokenMaker.java to the Java class created by JFlex.
Specifically, I copied and replaced this section of the code: http://pastie.org/private/whjzfhbrzwm8qc88t1idq
It is from the defintion of the method to the line with the comment // store back cached position
Hopefully this will help someone stuck on the same problem!

Related

infinite loop detected, partial ../foo.mustache was previously loaded

Hi I have two handlebars templates which is as below.
foo.mustache
{{#if hasProperties}}
{{>bar}}
{{/if}}{{^hasProperties}}{{propsName}}{{/hasProperties}}
bar.mustache
{{#propertyObject}}{{>foo}}{{/propertyObject}}
When I compile this and run, I get the following error.
infinite loop detected, partial '/templates/foo.mustache' was
previously loaded
What is the proper way to fix this?
I've found the solution for this issue. It's not something related to the template itself. The mustache files were in correct order but there is a property in the mustache java implementation where default value is set to false.
public void setInfiniteLoops(boolean infiniteLoops) link
this method will actually set to accept infinite loops which will be needed if you are running a recursive call inside the mustache template itself.
I hope this will help anyone looking to solve a similar kind of error.

ifstream error readings characters from string

so, I've written programs using ifstream in the past, successfully. yet this time, I can't seem to correct this "cannot read characters from string" error shown in the image. I basically declare ifstream inputFileStream in the class header, then try stating inputFileStream("text.txt"); and I already have that given error in the debugger.
More specifically, I construct an instance of the given class in the main method, and call (from the main method,) the public method which contains the statement inputFileStream("text.txt");.
I've made sure that the given text file is actually in the same folder as the project. Anybody familiar with this error?
I looked up the cccccccc error code and it has to do with an uninitialized stack something, but why would that be relevant to this?
The closest post to this was here, but im still trying to decipher the problem How to end up with a pointer to 0xCCCCCCCC
so, I got it working. I'm using visual studio 2013. all I had to do was copy the code into a new project, and compile it there. no idea why this worked as such

Why does importStatic Eclipse template variable need a namespace?

I'm trying to use Eclipse templates (in Juno) to generate statements for both regular and static imports and ran into something odd.
After consulting the docs my first attempt was this
${:import(org.junit.Test)} //ok
${:importStatic('org.junit.Assert.*')} //gives error
:import works fine, but :importStatic gives this error
Template variable '' has incompatible types
But the syntax above is exactly how it's presented in the docs, where :importStatic is identical to :import in the left-hand column.
I noticed the example in the right-hand column, which uses a namespace is in front of :importStatic
${is:importStatic(...
So I added that namespace, the error went away, and the template works
However I'm a little bugged by this magical unexplained is namespace - I can't find any explanation in the docs of where it comes from. In fact, playing around a little it seems there's nothing special about is at all - turns out any namespace in front of :importStatic will work.
${donkey:importStatic(... //works fine...
So, does anyone know why a namespace is necessary for :importStatic but not :import?
Is the error and the fact it won't save without a namespace just a bug in the template editor or am I missing something?
This is not a namespace, it is an id for the variable used in the template - except that import and importStatic should not need a variable.
I believe what you are see is Eclipse bug 336989 where leaving out the id on two statements causes this problem. As you have found the workaround is to specify an id even though it is not required.

Remove the remaining new line after using VTD-XML to remove an element

I'm trying to remove a set of child elements from a parent element using VTD-XML.
Unfortunately after removing an element, it leaves behind the new line that the removed element previously occupied. This behaviour is also observed by a reader of an article on VTD-XML by the VTD-XML author here. I'm trying to work out how to remove this new line.
I managed to achieve a modicum of success by manipulating the length value stored in the underlying 64-bit VTD token to cover the new line character (additional 2 bytes). Code snippet is as follows:
// XMLModifier modifier
modifier.remove(vn.getElementFragment()+0x200000000L);
I've tested that this works well on the old_cd.xml provided in ex_16 of the VTD-XML Examples.
However when I try this same approach on my working file, a ModifyException error is thrown when I attempt to call modifier.output(), specifically it is thrown by modifier.check2().
Questions
1. Why would the above approach cause check2() to fail? I don't think I'm overflowing the bits on the VTD token, file is < 2MB. See Update.
2. Is there a better approach to remove the remaining new line?
I'm still fairly new to VTD-XML so I would greatly appreciate any advice and insight and learn from more experienced users.
Thanks for your help.
Update
Wow, in the process of writing this question I realise that I forgot to consider the different character encodings and updating the adjusting long value to 1 byte fixed the check2() problem! (another reason to take the time to pause and rethink/write out the problem).
I'd still like to know from more experienced users if there are better approaches to this.
To answer your question, I think this needs to be done at the API level and it needs to take care a few extra details, like the options to remove all surrounding white spaces or none of the white spaces. It needs to be done in the next release...

Help to find ConsoleConstants

I just find the snippet which contains this code:
setHeaderEncoding(ConsoleConstants.UTF8_ENCODING)
But I just have file not found exception. So my question is where to find the lib which contains ConsoleConstants?
Any useful comment is appreciated :)
Andrew
I think you might be referring to this SO answer: File Upload with Java (with progress bar)
The snippet appears to be using Apache Commons FileUpload, and calling this method. From the context, it would appear that is just wants the standard Java character encoding name for UTF-8; i.e. "UTF-8".
It is impossible to figure out which ConsoleConstants class the code is actually referring to, but it doesn't matter, IMO. Just use a literal string.

Categories

Resources