Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Modeling predefined and custom commands with same prefix
Modeling predefined and custom commands with same prefix [message #57143] Sun, 12 July 2009 21:01 Go to next message
Dénes Harmath is currently offline Dénes HarmathFriend
Messages: 157
Registered: July 2009
Senior Member
Hi all,

I want to define a DSL where there are predefined commands starting with \
which I would like to parse. Also, there is the ability to define custom
commands and refer to them also in \command syntax. I'm not sure
whether/how this is possible. I tried:

PredefinedCommand: "\\commandPreset1" | "\\commandPreset2" // And so on
Assignment: id=ID "=" value=Value; // The Value rule is irrelevant here
CustomCommand hidden(): "\\" ref=[Assignment|ID];

But unfortunately the following sample file:

commandCustom = ...
\commandCustom

generates the following error:

no viable alternative at character 'C'

at the "commandCustom" token's 'C' character because the parser wants to
match one of the predefined command tokens. How could I tell the parser to
behave the right way? Any help would be highly appreciated!

Thanks in advance
thSoft
Re: Modeling predefined and custom commands with same prefix [message #57362 is a reply to message #57143] Mon, 13 July 2009 07:32 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
I'm not sure why the lexer behaves like you described.
Looking at the grammar it should at least have parsed until the 'P'
because '\command' seems to be the common prefix.

Anyway, from a language design point of view, I would prefer to either
don't have built-in commands but try to define them using a library
approach or if you want to have them built-in doing it like so:

Command : '\\' (ref=[Assignment|ID] | builtInCommand=BuiltInCommans);
enum BuiltInCommand :
'commandPreset1'|
'commandPreset2';

Because then you're able to handle commands more generically in your code.

Hope that helps,
Sven

Dennis Harmath schrieb:
> Hi all,
>
> I want to define a DSL where there are predefined commands starting with
> \ which I would like to parse. Also, there is the ability to define
> custom commands and refer to them also in \command syntax. I'm not sure
> whether/how this is possible. I tried:
>
> PredefinedCommand: "\\commandPreset1" | "\\commandPreset2" // And so on
> Assignment: id=ID "=" value=Value; // The Value rule is irrelevant here
> CustomCommand hidden(): "\\" ref=[Assignment|ID];
>
> But unfortunately the following sample file:
>
> commandCustom = ...
> \commandCustom
>
> generates the following error:
>
> no viable alternative at character 'C'
>
> at the "commandCustom" token's 'C' character because the parser wants to
> match one of the predefined command tokens. How could I tell the parser
> to behave the right way? Any help would be highly appreciated!
>
> Thanks in advance
> thSoft
>
Re: Modeling predefined and custom commands with same prefix [message #58183 is a reply to message #57362] Tue, 14 July 2009 09:24 Go to previous message
Dénes Harmath is currently offline Dénes HarmathFriend
Messages: 157
Registered: July 2009
Senior Member
Thank you for your help, Sven! Your second approach does work. However, it
will be tough work to refactor my grammar because there are many built-in
commands with "arguments" which I also want to parse, and there must be no
whitespace between \ and the command name (hence the hidden() directives).
It's time to give it a go...
Previous Topic:Error generating UI [ropject from TMF grammar
Next Topic:Left recursion: from binary to n-ary operations
Goto Forum:
  


Current Time: Wed Jul 17 15:27:00 GMT 2024

Powered by FUDForum. Page generated in 0.04175 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top