Custom end-of-line character, w/ default value. [message #720186] |
Tue, 30 August 2011 00:52  |
Eclipse User |
|
|
|
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 #720196 is a reply to message #720186] |
Tue, 30 August 2011 01:25   |
Eclipse User |
|
|
|
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 01:25   |
Eclipse User |
|
|
|
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 #720853 is a reply to message #720805] |
Wed, 31 August 2011 07:15  |
Eclipse User |
|
|
|
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!
|
|
|
Powered by
FUDForum. Page generated in 0.05775 seconds