This forum has been archived. All content is frozen. Please use KDE Discuss instead.

semantic analysis for new language?

Tags: None
(comma "," separated)
mpictor
Registered Member
Posts
7
Karma
0
OS

semantic analysis for new language?

Sat Jun 02, 2012 5:38 pm
Is there an example somewhere for a simple semantic analysis plugin?

I have a language with fairly simple syntax, and I'd like to be able to jump from references to declarations and vice versa.

For example:
Code: Select all
#20=(NAMED_UNIT(*)PLANE_ANGLE_UNIT()SI_UNIT($,.RADIAN.));
#21=PLANE_ANGLE_MEASURE_WITH_UNIT(PLANE_ANGLE_MEASURE(0.017453292519943295),#20);
#23=(CONVERSION_BASED_UNIT('degree',#21)NAMED_UNIT(*)PLANE_ANGLE_UNIT());


In this example, instance #23 references #21, and #21 references #20.

Using grep, I can find all declarations with
Code: Select all
^#[0-9]\\+=

and all references with
Code: Select all
\#[0-9]\\+[,\)]


How hard would it be do write a plugin that does this?
User avatar
scummos
Global Moderator
Posts
1175
Karma
7
OS
Writing language plugins for KDevelop is never trivial, as the interface is meant to be powerful and complete, not simple (i.e. it's not designed to be used in lots of 5-line language plugins). For what you proposed it shouldn't be that difficult, but you'll neverthereless need a few days at the very least to get the idea of the language plugin architecture. We're happy to help you out in our IRC channel tough, in case you have specific questions.

You could probably just take e.g. the PHP plugin, delete most code except for the parse job and the plugin trivia, change the parse job to do some regex matching and pack that into a very simple AST, and implement one function in each declaration and use builder which creates declarations / uses for those variables you have there. Stuff like highlighting and tooltips will then be (almost) available "for free".

Greetins,
Sven


I'm working on the KDevelop IDE.
mpictor
Registered Member
Posts
7
Karma
0
OS
scummos wrote:Writing language plugins for KDevelop is never trivial, as the interface is meant to be powerful and complete, not simple


It's too bad that there isn't a minimal example that does something really simple.

You could probably just take e.g. the PHP plugin, delete most code except for the parse job and the plugin trivia, change the parse job to do some regex matching and pack that into a very simple AST, and implement one function in each declaration and use builder which creates declarations / uses for those variables you have there. Stuff like highlighting and tooltips will then be (almost) available "for free".


Where is this code? I took a look at the git repos for kdevplatform and kdevelop, and nothing stood out.

Thanks
Mark
User avatar
scummos
Global Moderator
Posts
1175
Karma
7
OS
Yes, there's planning going on for a minimal example plugin. But nobody yet had the time to write it. :(

PHP and Python are seperate plugins in their own repositories, they're at git://anongit.kde.org/kdev-php.git or kdev-python.git.


I'm working on the KDevelop IDE.


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell