Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Behaviour of terminals
Behaviour of terminals [message #1858193] Wed, 22 March 2023 08:56 Go to next message
Dennis Untiet is currently offline Dennis UntietFriend
Messages: 14
Registered: March 2022
Junior Member
Hey everyone,

I have a question about the behaviour of whitespaces (or maybe all terminals).
This is my example grammar:
index.php/fa/43036/0/

And I have this example:
index.php/fa/43037/0/

Why is the grammar with the WS terminal showing an error? The definition is the same.

Maybe someone can explain this.

Thanks
Dennis
  • Attachment: Grammar.PNG
    (Size: 3.93KB, Downloaded 133 times)
  • Attachment: Dont Work.PNG
    (Size: 3.63KB, Downloaded 139 times)
Re: Behaviour of terminals [message #1858194 is a reply to message #1858193] Wed, 22 March 2023 08:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14654
Registered: July 2009
Senior Member
can you please provide a complete grammar and unit test
do you use both in the same grammar?


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

[Updated on: Wed, 22 March 2023 09:06]

Report message to a moderator

Re: Behaviour of terminals [message #1858195 is a reply to message #1858194] Wed, 22 March 2023 09:10 Go to previous messageGo to next message
Dennis Untiet is currently offline Dennis UntietFriend
Messages: 14
Registered: March 2022
Junior Member
This is my grammar:
grammar com.godyo.p4.xtext.installer.P4InstallDSL with org.eclipse.xtext.common.Terminals hidden(WS, ML_COMMENT)

generate installerDSL "http://www.godyo.com/p4/installer/dslP4InstallDSL"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore

Domainmodel:
    works=WORKS | dontWorks=DONTWORKS;
    
terminal WORKS:
	'Hello' -> 'World' (' '|'\t'|'\r'|'\n')+ '!';

terminal DONTWORKS:
	'Bye' -> 'World' WS '!'; 


And here are the tests:
@RunWith(XtextRunner)
@InjectWith(DSLInjectorProvider)
class DSLParsingTest {
	@Inject
	ParseHelper<Domainmodel> parseHelper
	
	@Test
	def void loadModel(){
		val String works = '''
		Hello 
			bla
			bla
			World
		World
		!
		''';
		
		val result1 = parseHelper.parse(works)
		Assert.assertNotNull(result1)
		val errors1 = result1.eResource.errors
		Assert.assertTrue(errors1.isEmpty)
		
		val String dontWork = '''
		Bye 
			bla
			bla
			World
		World
		!
		'''
		
		val result2 = parseHelper.parse(dontWork)
		Assert.assertNull(result2)
	}


The String dontWorks can't be parsed so it is null.
Re: Behaviour of terminals [message #1858196 is a reply to message #1858195] Wed, 22 March 2023 09:35 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14654
Registered: July 2009
Senior Member
i assume the problem is how the terminal fragments are generated. and thus conflict with the original ws rule. and also the greedyness of the lexer

=> i assume you have to have a look at the genrated lexer and debug.



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Perplexing Verilog Operator Grammar: Replication Operator
Next Topic:Load Resources
Goto Forum:
  


Current Time: Wed Feb 28 14:06:15 GMT 2024

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

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

Back to the top