[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipse-dev] where to get started writing a language parser for SWIG
|
Am 21.04.22 um 06:16 schrieb Stephen Crowley:
Hypothetically, what is the proper way to create a mode (im not sure
of the proper jargon) to parse SWIG interface files
<https://www.swig.org/>
for syntax hilighting, type hierarchy, etc.
I suggest to use Xtext; it comes with a powerful set of tools to parse
and process DSLs: Define the grammar, build ASTs from files, transform
them, generate code in any language from the AST using Xtend, integrate
the AST with Java projects. For example, you can make sure that at some
point in the grammar an enum from a Java project in the workspace is
being used. If you do this, then renaming items in the enum will rename
them in all DSL files in your workspace as well and vice versa.
Everything can then be packaged as an Eclipse plugin.
My use case was a DSL for I18N where I could define messages
welcome.message(User user): "Welcome, " user.name
where "User" was a type from the Java project. Xtext will then offer
code completion here (so you only select types from the project and then
only properties from the selected type).
That way, I18n messages would never get out of sync with the source
code. I would then generate Java classes with methods:
public class Welcome {
public I18NMessage message(User user) {
... build I18NMessage with user.getName()...
}
}
So I would always use the correct type when using those messages.
Regards,
--
Aaron "Optimizer" Digulla a.k.a. Philmann Dark
"It's not the universe that's limited, it's our imagination.
Follow me and I'll show you something beyond the limits."
http://blog.pdark.de/