Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [Beginner] New line, tabs([Beginner] New line, tabs)
[Beginner] New line, tabs [message #1817153] Sat, 16 November 2019 15:09 Go to next message
Tijmen Rijmen is currently offline Tijmen RijmenFriend
Messages: 11
Registered: November 2019
Junior Member
Hi guys,

First of all, I'm completely new to Xtext and completely new to this forum so hi all!

My problem:
I have defined a grammar for my intended DSL and I would like to use Xtext to validate and export files which I can use in a seperate system.

The basic grammar I would like to validate with Xtext:
bgcolor: 000000
bgsize: 1000x1000
box1:
    bgcolor: ff000ff
    position: 50x160
    size: 600x285


Like I said, I'm completely new to Xtext so this is what I came up with: (By far from finished)
Example:
    (ExampleElement+=ExampleElementType)*;

ExampleElementType:
    bgcolor | bgsize;

bgcolor:
	'bgcolor:' name=ID ;  

bgsize:
	'bgsize:' name=ID;  


How can I set it up that after entering 'bgcolor:'. 'bgcolor:' will be added to the outline (right now the value I enter after will appear in the outline) and how can I express new lines and tabs.

Thanks in advance!


Kind regards
Tijmen Rijmen
Re: [Beginner] New line, tabs [message #1817435 is a reply to message #1817153] Fri, 22 November 2019 06:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

for the outline you can customize MyDslLabelProvider (the comments there should give you some hints)

for whitespace sensitive languages you can have a look at, but this is not a beginner feature https://www.eclipse.org/Xtext/documentation/307_special_languages.html#whitespace-aware-languages . you could also splitup the inherites WS termimal and split it up into NL and WS and model them explicit but this is not a real supported usecase and will explode in all kind of situations => not beginner friendly. is there a specific reason why you want to model WS explicitely?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [Beginner] New line, tabs [message #1817849 is a reply to message #1817435] Sun, 01 December 2019 00:23 Go to previous messageGo to next message
Tijmen Rijmen is currently offline Tijmen RijmenFriend
Messages: 11
Registered: November 2019
Junior Member
The specific reason is that I want to create a Yaml file eventually which is going to be used by a different system.

The most ideal situation is that the indents happen right at the moment the user performs the input. I would settle for an option that an extra file is created which is correctly formatted. The file generated should be formatted so that every keyword is on a newline and that keywords in groups are indented by a tab or 2 spaces. Nested groups should be indented with 2 tabs or 4 spaces. How should I start with this? Should I go for the generator or the formatter?

Re: [Beginner] New line, tabs [message #1817851 is a reply to message #1817849] Sun, 01 December 2019 07:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
generating and formatting a two completely different topics so
i dont know


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [Beginner] New line, tabs [message #1817852 is a reply to message #1817851] Sun, 01 December 2019 08:34 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

A generator could be used to just prettyprint but it seems a bit strange. Easier to overload your XXXResourceImpl save to ensure that an XXXSaveImpl corrects indentation as it saves.

I'm not familiar with the 'new' formatter, but if your keywords are well disciplined even the 'old' formatter should get the indentation right. The 'new' formatter may have extra capabilities.

Using the formatter will have the advantage that you get WYSIWYG.

Regards

Ed Willink
Re: [Beginner] New line, tabs [message #1817855 is a reply to message #1817852] Sun, 01 December 2019 11:32 Go to previous messageGo to next message
Tijmen Rijmen is currently offline Tijmen RijmenFriend
Messages: 11
Registered: November 2019
Junior Member
Hi guys,

Thanks for your replies. So the way to go is using the formatter.

What I did:
- Added the formatter to my workflow by adding generateStub.
- Added terminal rules for synthetic BEGIN and END
- Added BEGIN and END to block that needs to be indented
- Works as a charm except for one thing. Trying out CTRL + SPACE to get the content-assist (at least I think it's called like that) will terminate the program.

The following error pops up:
Unresolved compilation problem: 
	The code for the static initializer is exceeding the 65535 bytes limit


linking to this rule in InternalIDSLParser.java
public class InternalIDSLParser extends AbstractInternalContentAssistParser {


Can someone explain me what's going on and the proper way to solve this?

Re: [Beginner] New line, tabs [message #1817858 is a reply to message #1817855] Sun, 01 December 2019 15:07 Go to previous messageGo to next message
Tamas Miklossy is currently offline Tamas MiklossyFriend
Messages: 157
Registered: February 2016
Senior Member
See also https://github.com/eclipse/xtext-core/issues/933
Re: [Beginner] New line, tabs [message #1817859 is a reply to message #1817858] Sun, 01 December 2019 16:03 Go to previous message
Tijmen Rijmen is currently offline Tijmen RijmenFriend
Messages: 11
Registered: November 2019
Junior Member
So the conclusion is I should get rid of all my unordered groups in my code and then it will probably just work.

I tried adding the splitting option in my workflow but that did not work out.

Thanks for your reply!
Previous Topic:Testing code generation
Next Topic:Question: DSL project with dependencies
Goto Forum:
  


Current Time: Tue Apr 23 11:45:35 GMT 2024

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

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

Back to the top