Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » using format effector character in a terminal rule(trouble with special characters)
using format effector character in a terminal rule [message #894347] Sun, 08 July 2012 14:40 Go to next message
Jens Kuenzer is currently offline Jens KuenzerFriend
Messages: 29
Registered: October 2009
Junior Member
I tried to remove "vertical tab" and "form feed" character from the single line comment according to the spec of the language. This is the code so far:

terminal SL_COMMENT :
	'--'
//	( '\u0000'..'\u0008' | '\u000E'..'\u00FF' )*  //ERROR invalid xml char

//	!( '\r'..'\n' )*                          //ERROR antlr null range

	!( '\r' //  u000A     carriage return
//	 |        '\u000B' // vertical tabulation //ERROR invalid xml char
//	 | '\f' //  u000C     form feed           //ERROR invalid xml char
	 | '\n' //  u000D     line feed
	 )*

	 ('\r'? '\n')?
	 ;


You can see there are two problems not directly related to Xtext.
One is related to ANTLR that can not handle inverting a range like this.
The other problem is about XML library not able to handle that character.
I tried xml1.1 as suggested in another thread but with no success.
So for now I live with comments that can have such characters - no big deal. But I also failed to add these character to my white space terminal rule. So my language is not 100% according to the spec for now.

I also found some funny effects using comments like "// | '\f' // \u000C " in Xtext. The result would be a Java file with the same comment. So far Xtext has done nothing wrong. But there are some error marker in the comment.
Re: using format effector character in a terminal rule [message #894616 is a reply to message #894347] Mon, 09 July 2012 20:02 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
Am 08.07.12 16:40, schrieb Jens Kuenzer:
> I tried to remove "vertical tab" and "form feed" character from the
> single line comment according to the spec of the language.
> This is the code so far:
>
>
> terminal SL_COMMENT :
> '--'
> // ( '\u0000'..'\u0008' | '\u000E'..'\u00FF' )* //ERROR invalid xml char
>
> // !( '\r'..'\n' )* //ERROR antlr null range
>
> !( '\r' // u000A carriage return
> // | '\u000B' // vertical tabulation //ERROR invalid xml char
> // | '\f' // u000C form feed //ERROR invalid xml char
> | '\n' // u000D line feed
> )*
>
> ('\r'? '\n')?
> ;

What are you trying to achieve? It doesn't make sense to exclude non
terminating chars - yours are \n possibly preceeded by \r - in the
contents of the comment.

> You can see there are two problems not directly related to Xtext. One is
> related to ANTLR that can not handle inverting a range like this.

You could enumerate all four elements in an alternative and negate that.

> The other problem is about XML library not able to handle that character.
> I tried xml1.1 as suggested in another thread but with no success.

What problem did you run into?

> So for now I live with comments that can have such characters - no big
> deal. But I also failed to add these character to my white space
> terminal rule. So my language is not 100% according to the spec for now.

What happens if you add them?

> I also found some funny effects using comments like "// | '\f' // \u000C
> " in Xtext. The result would be a Java file with the same comment. So
> far Xtext has done nothing wrong. But there are some error marker in the
> comment.

I have never seen \f in code. And it seems to be forbidden in Java. What
do you expect the Java code to look like? To filter it, consider binding
your own value converter.


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Re: using format effector character in a terminal rule [message #894725 is a reply to message #894616] Tue, 10 July 2012 09:35 Go to previous message
Jens Kuenzer is currently offline Jens KuenzerFriend
Messages: 29
Registered: October 2009
Junior Member
Hi,

thanks for your response. I try to implement comments according to VHDL IEEE Std 1076™-2008 Chapter 15.9:

"A single-line comment starts with two
adjacent hyphens and extends up to the end of the line. ... A single-line comment can appear on any line of a VHDL description and may contain any character except
the format effectors vertical tab, carriage return, line feed, and form feed."

The straight forward approach would be:
terminal SL_COMMENT :
	'--'
	!( '\r' // \u000A     carriage return
	 |        '\u000B' // vertical tabulation
	 | '\f' // \u000C     form feed
	 | '\n' // \u000D     line feed
	 )*
	 ('\r'? '\n')?
	 ;


I just like to share my experience that it is not that simple. You can try it, if you like. I hit some more problems during my attempts to find a workaround. Now I think these exotic character like '\f' are not important enough to be supported and I gave up.
Previous Topic:How to run Xtend2 from toolbar bottom?
Next Topic:Sense in testing the parser and the semantic model If using Xtext
Goto Forum:
  


Current Time: Thu Feb 27 00:00:16 GMT 2020

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

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

Back to the top