I'm using Java Swing to develop an application and I want to use Lua as an embedded scripting language. For that I need to create a text component that would provide syntax highlighting and automatically organize the code by adding tabs and so on.
Is there a library or resource that I could use in order to achieve this?
Here is an example of what I want to do: http://openendedgroup.com/field/attachment/wiki/OverviewBanners2/p2.png
Thanks,
Code formatting (indentation) and Syntax Highlighting are two different pairs of shoes! For formatting you also need a relative complete parser, while for syntax highlighting you can simply tokenize your input and colorize it.
I believe there are extensible highlighters out there, but you will need something like the ANTLR parser if you need to format your code.
Related
I'm trying to use Java to develop a piece of software, but I've run into the issue of UI elements parsing HTML beyond the way I want them to.
The Java JEditorPane seems to be only able to be marked up by HTML or something that is essentially HTML underneath. I want the user to be able to type and see HTML tags, not have them formatted into markup, but still have something like the tags colored red and standard text not.
Is there a method of marking up Java's UIs without HTML? (I don't mind using an extra library, but if it can be avoided that'd be great.)
I haven't used it, but RSyntaxTextArea seems to achieve what you want. The intro says
RSyntaxTextArea is a syntax highlighting text component for Java
Swing.
and
Syntax highlighting for over 30 programming languages
Example usage and source code at github.
I want to use a math-expression parser of java code. In particular I would like to convert a math-expression given as String to an abstract syntax tree consisted of separate nodes.
Is there anyone to recommend me a relevant open source tool?
If no, how do you reckon the possibility to exploit Intellij source code to do this work?
Which classes are responsible for code parsing and analysis?
Are they included in idea.jar? How can I easily infiltrate their functionality (methods etc)?
I am speaking exclusively for Intellij.
Take a look at MVEL library.
If you only want the results of the math-expression you should revise the question and the answer i selected months ago:
Java 1.5: mathematical formula parser
Brieff description: use the java integration with dinamyc languajes like javascript to let them do the work for you
I would not use IntelliJ, as much as I love it.
If you need an AST, look no further than ANTLR. If you can write a grammar for your equations, ANTLR can generate a lexer/parser to create it for you.
I'm looking for a sample or possibly even code I can use which scans Java files and tells me key pieces of information about each class, which i can then use much like the NetBeans refactoring and go to source features do.
Instead of reusing the Netbeans sources, you should probably just find a good library.
tells me key pieces of information about each class
Depending on your definition of "key pieces", I would recommend QDox:
http://qdox.codehaus.org/
QDox is a high speed, small footprint
parser for extracting
class/interface/method definitions
from source files complete with
JavaDoc #tags.
If you are looking for reusing Netbeans code which parses Java file, I don't know.
If you are looking for how to parse a Java file, you can try ANTLR. ANTLR is a parser generator. There exists Java grammar which you can use right away. Once, you generate a Java parser, you can use the parser to parse your Java file. You will have to learn how to use ANTLR.
I don't understand very well your question.
If you want to navigate inside source java code with netbeans, push CTRL and with your mouse go over the word you want to explore ; netbeans highligth the word, and if you clic you go to the source.
As the title says, I want to parse some Java source code in Java. I'm pretty sure there are other java libraries that already perform this, but I couldn't find any.
Antlr has a grammar file for Java. See this.
Janino can parse, compile and execute Java code.
You may be looking for something like ANTLR: http://www.antlr.org/
Eclipse exposes the Syntax Tree of it's own Java compiler. You can simply access the elements.
See here.
JavaCC has a Java 1.5 grammar including generics.
the tokens are probably more
fine-grained then what I want
Your first requirement is to get an accurate parse, and you will realistically only get that from an existing parser. What you do with the result is up to you.
I'm trying to find a solution to highlight part of a text file in Java.
Basically, what I'm doing is lexing and parsing a text file respecting a certain grammar, storing some information related to the various elements of this file and then logging the information to a database.
I would like to have something more visual like a representation of the text file with some parts highlighted (and an index of the various colors used) - or even better with some context-sensitive information attached to a particular token.
Is there an easy way to do so? Basically what I would like to have, in terms of features, is a really primitive Eclipse plugin for a particular language and stand-alone. Maybe there's a framework to build DSL editors, something like that.
Hope it is clear...
Thanks
I think Xtext is just what you are looking for, it generates an Eclipse editor and more from a grammar.
Although not for Eclipse, there's MPS by JetBrains (the makers of the now open source IntelliJ IDEA) which may be worth taking a look at:
http://www.jetbrains.com/mps/