Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtend Grey Space: It works great until it doesn't
Xtend Grey Space: It works great until it doesn't [message #1815746] Wed, 09 October 2019 17:44 Go to next message
Brandon Lewis is currently offline Brandon LewisFriend
Messages: 268
Registered: May 2012
Senior Member
Seems nearly every time I use Xtend, I experience a brief moment of really liking the gray space capability followed by an extended period of cursing it's existence.

It almost always goes wrong for me at some point. Take this example, I'm doing standard coding indentation, which is supposed to be ignored, but it isn't. The editor is smart enough to tell me that I have problems, but not smart enough to fix them (like it says it's supposed to).

I'm generating a YAML output, so white space is critical to the storage format. if I can't get it right, I can't use it.

From this picture, why does Xtend and its editor hate me?

index.php/fa/36517/0/

[Updated on: Wed, 09 October 2019 17:46]

Report message to a moderator

Re: Xtend Grey Space: It works great until it doesn't [message #1815747 is a reply to message #1815746] Wed, 09 October 2019 17:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
can you please provide the code snippet too.
what looks strange that the content of the 3rd if is not indented into the if


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Wed, 09 October 2019 18:02]

Report message to a moderator

Re: Xtend Grey Space: It works great until it doesn't [message #1815748 is a reply to message #1815747] Wed, 09 October 2019 18:11 Go to previous messageGo to next message
Brandon Lewis is currently offline Brandon LewisFriend
Messages: 268
Registered: May 2012
Senior Member
				    fsa.generateFile(fileName, '''
---
component:
	vendor : «dwc.vendor»
	library: «dwc.library»
	name   : «dwc.name»
	version: «dwc.version»

  «IF comp.model !== null»
  model: 
  «IF comp.model.ports !== null»
    ports:
	  «FOR port : comp.model.ports.port»
		  «IF port !== null»
      - port: «port.name»
		 		«IF port.wire !== null»
        wire:
          «IF port.wire.direction !== null»direction: «port.wire.direction.literal»«ENDIF»
			  «ENDIF»
			«ENDIF»
		«ENDFOR»
		«ENDIF»
	«ENDIF»
'''
					)


I've set tabs to insert 2 spaces.

I've been tabbing and spacing and cursing for an hour now. :-) Thank you for looking, I know this isn't an interesting technical question.


index.php/fa/36518/0/

Looks like I have a mess of tabs and spaces. However, after I display white space and very deliberately go and edit all my code to only have spaces, I still get a block where it refuses to do the appropriate grey spacing.

index.php/fa/36519/0/
Re: Xtend Grey Space: It works great until it doesn't [message #1815749 is a reply to message #1815748] Wed, 09 October 2019 18:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
what is the expected result?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtend Grey Space: It works great until it doesn't [message #1815750 is a reply to message #1815749] Wed, 09 October 2019 18:29 Go to previous messageGo to next message
Brandon Lewis is currently offline Brandon LewisFriend
Messages: 268
Registered: May 2012
Senior Member
I would expect that the whitespace of "direction:" would be recognized after two spaces after its containing <<IF>> template statement. It, I believe, should recognize that the initial 2 whitespace characters are keeping my code spacing consistent, but after that, all entered whitespace should be recognized.

Instead, I can put 3000 whitespace characters in and it won't enter a single space in front of "direction:" in my output. And I can't massage it to insert any real output whitespace there.

Why does line 59 recognize it needs to start "real whitespace" 2 whitespaces within the <<IF>>, but line 61 never recognizes it?

[Updated on: Wed, 09 October 2019 18:31]

Report message to a moderator

Re: Xtend Grey Space: It works great until it doesn't [message #1815751 is a reply to message #1815750] Wed, 09 October 2019 18:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
nooo i mean: i dont know where you want to indent and were not.
=> i cannot tell you how to change the stuff.

for the direction: its the indentation of the if that matters

e.g.

class A {
	def static void main(String[] args) {
		println('''
---
component:
  vendor : x
  library: x
  name   : x
  version: x
  «IF true»
    model: 
    «IF true»
      ports:
      «FOR port : 1..5»
        «IF port !== null»
        - port: «port»
          «IF true»
          wire:
            «IF true»
            direction: bla
            «ENDIF»
          «ENDIF»
          «ENDIF»
    «ENDFOR»
    «ENDIF»
  «ENDIF»
    ''')
	}
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtend Grey Space: It works great until it doesn't [message #1815752 is a reply to message #1815750] Wed, 09 October 2019 18:35 Go to previous messageGo to next message
Brandon Lewis is currently offline Brandon LewisFriend
Messages: 268
Registered: May 2012
Senior Member
I"m getting output like this (which isn't valid YAML so it's pretty bad):

  model: 
    ports:
      - port: CK
        wire:
direction: in
      - port: rst_n
        wire:
direction: in  (I need this to be 2 spaces within wire:)

[Updated on: Wed, 09 October 2019 18:35]

Report message to a moderator

Re: Xtend Grey Space: It works great until it doesn't [message #1815753 is a reply to message #1815752] Wed, 09 October 2019 18:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
so this would be something like

class A2 {
	def static void main(String[] args) {
		println('''
---
component:
  vendor : x
  library: x
  name   : x
  version: x
  «IF true»
    model: 
      «IF true»
        ports:
          «FOR port : 1..5»
          «IF port !== null»
          - port: «port»
            «IF true»
            wire:
              «IF true»
              direction: bla
              «ENDIF»
            «ENDIF»
            «ENDIF»
          «ENDFOR»
      «ENDIF»
  «ENDIF»
    ''')
	}
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtend Grey Space: It works great until it doesn't [message #1815754 is a reply to message #1815753] Wed, 09 October 2019 18:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
result

---
component:
  vendor : x
  library: x
  name   : x
  version: x
  model: 
    ports:
      - port: 1
        wire:
          direction: bla
      - port: 2
        wire:
          direction: bla
      - port: 3
        wire:
          direction: bla
      - port: 4
        wire:
          direction: bla
      - port: 5
        wire:
          direction: bla




Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtend Grey Space: It works great until it doesn't [message #1815755 is a reply to message #1815754] Wed, 09 October 2019 18:54 Go to previous messageGo to next message
Brandon Lewis is currently offline Brandon LewisFriend
Messages: 268
Registered: May 2012
Senior Member
Thanks for your example, once I copied that, things seem to be working. I'm still never sure what it is I'm doing to makes everything go wrong to begin with. Once they go bad, and I don't understand why, it's always hard to fix.

I think I'll need to send you a Christmas card or something this year for your help.
Re: Xtend Grey Space: It works great until it doesn't [message #1816610 is a reply to message #1815755] Fri, 01 November 2019 14:12 Go to previous messageGo to next message
Brandon Lewis is currently offline Brandon LewisFriend
Messages: 268
Registered: May 2012
Senior Member
It's a common occurrence - I'm back where I always end up - cursing at Xtend grey space! There is something mentally incompatible with the way I think about code and the way it thinks about code. I dont' get it.

What is the general cause of this editor/tool/language REFUSING to honor my spacing? When it completely refuses to enter a gray space where I need it, what is the cause of it doing that?

I have white space turned on in my editor and I'm ever so carefully spacing everything correctly, making sure everything is all tabs or all spaces, and inevitably - every time I've ever tried to use xtend to generate output ever in my life - it will reach a state where it refuses to indent the way I want it to.

Am I the only person on the planet that Xtend Gray Space hates?

It really sucks to spend 30 minutes trying to insert two whitespace in an output file.

Is there a way to turn this feature off? What causes its refusal to honor my spacing?
Re: Xtend Grey Space: It works great until it doesn't [message #1816611 is a reply to message #1816610] Fri, 01 November 2019 14:21 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

It is actually a rather hard problem to distinguish casual whitespace that the user finds aesthetically pleasing for Xtend source layout and what is necessary to provide aesthetically satisfactory output. Particularly hard since the greying of new-lines remains todo. I'm not sure the problem is even tractable without introducing hard rather than inferred greyed spaces/new-lines.

But before you complain too much, try Acceleo where satisfactory whitespacing is much much harder. Acceleo silences its critics by recommending pretty formatting in a subsequent pass. You might find that approach necessary for you too.

Regards

Ed Willink
Re: Xtend Grey Space: It works great until it doesn't [message #1816614 is a reply to message #1816611] Fri, 01 November 2019 14:34 Go to previous messageGo to next message
Brandon Lewis is currently offline Brandon LewisFriend
Messages: 268
Registered: May 2012
Senior Member
At least maybe I'm not the only person. I have work to do and can't change gears and learn another framework to print out text.

I've burnt an hour cursing trying to get whitespaces. It's quite infuriating. Here's a print method below, this is the second time this morning I've spent 30minutes cursing and maybe eventually getting 2 spaces inserted in my output - maybe if I ask nice and curse ALOT.

I guess I'll just do it all with StringBuilder and move forward.

Every single time I use Xtend this magical feature hates my guts.

I'm not sure how the following code is ambiguous.

  def printModuleDecl(ComponentType comp) {
    return '''
module «comp.name» (

«IF comp.model !== null && comp.model.ports !== null»
  «FOR port : comp.model.ports.port»
                                       | <- why is there no white space to the left of here?!
  «ENDFOR»
«ENDIF»
);
    
    // Stuff
    
endmodule : «comp.name»

'''
  }
Re: Xtend Grey Space: It works great until it doesn't [message #1816625 is a reply to message #1816614] Fri, 01 November 2019 17:39 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
the answer is: cause you dont indent the if statement itself

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtend Grey Space: It works great until it doesn't [message #1816631 is a reply to message #1816625] Fri, 01 November 2019 20:23 Go to previous messageGo to next message
Brandon Lewis is currently offline Brandon LewisFriend
Messages: 268
Registered: May 2012
Senior Member
Doesn't work for me if my first entry is a <<xtend_var>>. When I try to use an <<xtend_var>> it almost never works - well I should say it works sometimes initially, but will inevitably start failing somewhere in my generator.

I often, if printing simple reports, start lines with a single '.' once it starts "messing up" and then it'll snap into making sense. But in real life I never have a literal character I can just put on a front line for force it to recognize my whitespacing

I don't get it. I got confident with your answer, tried every possible permutation of indents of:

'''
<<IF>>
<<FOR>>
<<xtend_var>>

I could think of and it refuses to insert leading white space in my for loop, or my if loop.

Whatever it wants me to do, I'm seem to be incapable of figuring it out. It's a fist fight every time. Seems _so_ simple and it's really cool when it works, but it breaks for me every time I try to use it.

[Updated on: Fri, 01 November 2019 20:28]

Report message to a moderator

Re: Xtend Grey Space: It works great until it doesn't [message #1816639 is a reply to message #1816631] Sat, 02 November 2019 10:05 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
As you have state before you can do this with a string builder manually too

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Check if a language/grammar file is defined twice in Workspace
Next Topic:[Beginner] Can't get Xtext examples to work
Goto Forum:
  


Current Time: Thu Apr 25 17:32:15 GMT 2024

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

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

Back to the top