Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 354918

Summary: Tooltip for grammar rule should depict a list of sample strings matching the resp. rule
Product: [Modeling] TMF Reporter: Matthias Wienand <matthias.wienand>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: enhancement    
Priority: P3 CC: nyssen, sebastian.zarnekow
Version: 2.0.1   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Matthias Wienand CLA 2011-08-17 04:50:46 EDT
Build Identifier: I20110613-1736

While editing a .xtext-file within the Xtext editor, I think that it would be useful to get a list of sample strings which match a given grammar rule. This could be delivered as additional information when moving the mouse over the rule name, or via a selection and a context menu. The list should be generated of as many terms of the grammar rule as possible. So that, if you view a grammar rule as a syntex tree, the process of sample string generation should visit each branch at least once.

Example:
[xtext]
terminal ID: '^'?('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;
Rule: '^'* ID ('.' ID)?;
[/xtext]
[generated list for rule Rule]
a
^ ^Aa . a
^^ _Aa
^^^ ^b_Aa . Aa
^^^^ B0_Aa
^^^^^ ^_b0_Aa . _Aa
^^^^^^ cBb0_Aa
^^^^^^^ ^C_Bb0_Aa . b_Aa
...
[/generated list]

The naive approach I tried to follow to generate this short list switches the quantifiers and alternatives. The maximum number of items quantified by '*' or '+' should be relatively small (~10). 

Maybe it is viable to reuse (parts of) the ANTLR ambiguity calculation to generate the sample strings.

Reproducible: Always
Comment 1 Sebastian Zarnekow CLA 2011-10-17 16:52:19 EDT
I don't think that generated documentation is useful for grammars / terminal rules in any case.