Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Custom end-of-line character, w/ default value.(Custom end-of-line character, w/ default value.)
Custom end-of-line character, w/ default value. [message #720186] Tue, 30 August 2011 04:52 Go to next message
Jack  is currently offline Jack Friend
Messages: 12
Registered: May 2011
Junior Member
The language I'm constructing a grammar for, requires the ability to change the End-of line character.

For example:
// By default, end-of line character = ";" 
int digit;
digit = 4;

#SET EOL = "." // This sets the End of line character to "." instead of ";" 
int digit2 = 7.
digit = digit + digit2.

// Note: ";" cannot be used until the following is executed:
#SET EOL = ";"


I've toyed with the idea some grammar such as this:
Eol_change:
'#SET' 'EOL' '=' EOL=STRING;

Statement:
[var] '=' ([var]|[integer]) [EOL];


This requires me to:
i) set a default value for EOL, and
ii) ensure that only one EOL can exist at any time.

I'm not sure how to do this (help please?), and
(perhaps more importantly) I'm not sure that this is the best way to achieve my objective.

Any ideas?


Thanks in advance.
Re: Custom end-of-line character, w/ default value. [message #720189 is a reply to message #720186] Tue, 30 August 2011 04:56 Go to previous messageGo to next message
Jack  is currently offline Jack Friend
Messages: 12
Registered: May 2011
Junior Member
I realise there's probably syntax errors within the above.
My larger concern is really the overall objective.
Re: Custom end-of-line character, w/ default value. [message #720196 is a reply to message #720186] Tue, 30 August 2011 05:25 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Jack

Selecting any character as EOL seems very flawed, what if you select
"a"? Does that break identifiers?

You use #SET EOL which is very C preprocessor like. If you really want
it, use a two level language so that you get all the pain of that
approach in an at least more predictable fashion.

If you can identify a sensible set of alternative EOLs that do not
conflict, then you can define the grammar for all of them, and use
semantic validation to warn of inconsistent usage.

Regards

Ed Willink



On 30/08/2011 05:52, Jack wrote:
> The language I'm constructing a grammar for, requires the ability to
> change the End-of line character.
>
> For example:
> // By default, end-of line character = ";" int digit;
> digit = 4;
>
> #SET EOL = "." // This sets the End of line character to "." instead
> of ";" int digit2 = 7.
> digit = digit + digit2.
>
> // Note: ";" cannot be used until the following is executed:
> #SET EOL = ";"
>
> I've toyed with the idea some grammar such as this:
> Eol_change:
> '#SET' 'EOL' '=' EOL=STRING;
>
> Statement:
> [var] '=' ([var]|[integer]) [EOL];
>
> This requires me to:
> i) set a default value for EOL, and
> ii) ensure that only one EOL can exist at any time.
>
> I'm not sure how to do this (help please?), and
> (perhaps more importantly) I'm not sure that this is the best way to
> achieve my objective.
>
> Any ideas?
>
>
> Thanks in advance.
>
Re: Custom end-of-line character, w/ default value. [message #720197 is a reply to message #720186] Tue, 30 August 2011 05:25 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Jack

Selecting any character as EOL seems very flawed, what if you select
"a"? Does that break identifiers?

You use #SET EOL which is very C preprocessor like. If you really want
it, use a two level language so that you get all the pain of that
approach in an at least more predictable fashion.

If you can identify a sensible set of alternative EOLs that do not
conflict, then you can define the grammar for all of them, and use
semantic validation to warn of inconsistent usage.

Regards

Ed Willink



On 30/08/2011 05:52, Jack wrote:
> The language I'm constructing a grammar for, requires the ability to
> change the End-of line character.
>
> For example:
> // By default, end-of line character = ";" int digit;
> digit = 4;
>
> #SET EOL = "." // This sets the End of line character to "." instead
> of ";" int digit2 = 7.
> digit = digit + digit2.
>
> // Note: ";" cannot be used until the following is executed:
> #SET EOL = ";"
>
> I've toyed with the idea some grammar such as this:
> Eol_change:
> '#SET' 'EOL' '=' EOL=STRING;
>
> Statement:
> [var] '=' ([var]|[integer]) [EOL];
>
> This requires me to:
> i) set a default value for EOL, and
> ii) ensure that only one EOL can exist at any time.
>
> I'm not sure how to do this (help please?), and
> (perhaps more importantly) I'm not sure that this is the best way to
> achieve my objective.
>
> Any ideas?
>
>
> Thanks in advance.
>
Re: Custom end-of-line character, w/ default value. [message #720805 is a reply to message #720186] Wed, 31 August 2011 09:22 Go to previous messageGo to next message
Jack  is currently offline Jack Friend
Messages: 12
Registered: May 2011
Junior Member
Good idea.

In this particular language, whilst "a" may be used (and would break identifiers), conventionally there are only a few characters that are actually used for this purpose.

I can have my editor cater for these characters quite easily.

If the developer attempts to use a non-conventional EOL character, I'll simply throw a warning. Choosing to do this will be allowed - however further parsing/validation will cease at this point.

I can see this happening in rare circumstances only... so I'm content with this.

Thanks heaps!
Re: Custom end-of-line character, w/ default value. [message #720853 is a reply to message #720805] Wed, 31 August 2011 11:15 Go to previous message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
One idea is to declare the "statement separator" as a reference (it
isn't really "End of Line", because clearly there is a '\n' character
after it. Use scoping to find the correct separator in a context.

Something along the line of:

StatementSeparator : '#' 'SET' 'EOL' '=' name=Punctuation ;
SomeExpression : Expression [StatementSeparator|Punctuation] ;

Punctuation : '.' | ',' | ';' | ... ;

Scoping would need to search from current position towards the beginning
to find the correct StatementSeparator.

Hope that helps.
- henrik

On 8/31/11 11:22 AM, Jack wrote:
> Good idea.
>
> In this particular language, whilst "a" may be used (and would break
> identifiers), conventionally there are only a few characters that are
> actually used for this purpose.
>
> I can have my editor cater for these characters quite easily.
>
> If the developer attempts to use a non-conventional EOL character, I'll
> simply throw a warning. Choosing to do this will be allowed - however
> further parsing/validation will cease at this point.
>
> I can see this happening in rare circumstances only... so I'm content
> with this.
>
> Thanks heaps!
Previous Topic:Computing the transitive hull of dependant resources
Next Topic:Changelogs of xtext
Goto Forum:
  


Current Time: Fri Apr 26 03:00:22 GMT 2024

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

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

Back to the top