Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Behaviour of terminals
Behaviour of terminals [message #1858193] Wed, 22 March 2023 04:56 Go to next message
Eclipse UserFriend
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 261 times)
  • Attachment: Dont Work.PNG
    (Size: 3.63KB, Downloaded 267 times)
Re: Behaviour of terminals [message #1858194 is a reply to message #1858193] Wed, 22 March 2023 04:57 Go to previous messageGo to next message
Eclipse UserFriend
can you please provide a complete grammar and unit test
do you use both in the same grammar?

[Updated on: Wed, 22 March 2023 05:06] by Moderator

Re: Behaviour of terminals [message #1858195 is a reply to message #1858194] Wed, 22 March 2023 05:10 Go to previous messageGo to next message
Eclipse UserFriend
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 05:35 Go to previous message
Eclipse UserFriend
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.

Previous Topic:Perplexing Verilog Operator Grammar: Replication Operator
Next Topic:Load Resources
Goto Forum:
  


Current Time: Sun Aug 31 07:56:56 EDT 2025

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

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

Back to the top