language with unstructured macros [message #805251] |
Thu, 23 February 2012 09:49  |
Eclipse User |
|
|
|
Hi,
My problem is that the language has C-like macros. The values for the macros need not be well-formed expressions and in the worst case the resulting code that we have to parse loses all structure. Is there some trick to handle this kind of situation? I mean, maybe not the worst case, but as much as possible.
best regards,
Vlad
|
|
|
|
|
Re: language with unstructured macros [message #806410 is a reply to message #805532] |
Fri, 24 February 2012 18:43   |
Eclipse User |
|
|
|
On 2012-23-02 22:46, Vlad Dumitrescu wrote:
> Thanks Henrik,
>
> Quote:
>> Seriously - correctly dealing with macros as a MAJOR pita.
>
>
> I knew this was the case, but hoped somewhat irrationally that there was
> some magic that would ease the pain.
>
Nope, it is really, really awful and difficult to get right, and you
have to override things here, there and everywhere.
> I'm glad that the generated parser has good error recovery and the
> disturbance does not spread through the whole file. If I could ignore
> the related errors in Eclipse, it could be good enough.
>
Nope, no, sorry - if not very hard, it is at least a LOT of work.
I would forget about trying to solve this at the grammar level, it is a
lexing and textual read/write and presentation matter - basically the
lexer needs to evaluate the macros to turn the macros into valid
expressions in the language as this is what the parser needs. At the
same time you need to present things in the editor where the macros are
not expanded.
--- in file "x.header"
#define x = public class
--- in file mystuff
#include x.header
x foo {}
class bar extends foo {}
There is no support for this in Xtext at all. If you really need this, I
suggest talking to the guys at Itemis and pay for help.
Regards
- henrik
|
|
|
Re: language with unstructured macros [message #806961 is a reply to message #806410] |
Sat, 25 February 2012 14:48  |
Eclipse User |
|
|
|
Hi!
Quote:> I'm glad that the generated parser has good error recovery and the
> disturbance does not spread through the whole file. If I could ignore
> the related errors in Eclipse, it could be good enough.
>
Nope, no, sorry - if not very hard, it is at least a LOT of work.
I would forget about trying to solve this at the grammar level, it is a
lexing and textual read/write and presentation matter - basically the
lexer needs to evaluate the macros to turn the macros into valid
expressions in the language as this is what the parser needs. At the
same time you need to present things in the editor where the macros are
not expanded.
Fortunately, real-world uses of macros are not very wild and crazy, so there are only a few cases that can happen - mostly that any expression or sequence of expressions can be represented by a macro instance. Unfortunately, this is still enough to make the grammar ambiguous.
I tried to let only the basic structural features of the language remain in place and let the rest be possible to be anything, but it doesn't look too bright. It might work with a backtracking parser, though.
Thanks a gain for the support!
regards,
Vlad
|
|
|
Powered by
FUDForum. Page generated in 0.07009 seconds