org.eclipse.xtext.xtext.generator.grammarAccess.GrammarAccessExtensions Java Examples

The following examples show how to use org.eclipse.xtext.xtext.generator.grammarAccess.GrammarAccessExtensions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KeywordHelperTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testToAntlrTokenIdentifier() throws Exception {
	// @formatter:off
	String model =
	"grammar org.eclipse.xtext.xbase.Xbase with org.eclipse.xtext.common.Terminals\n" +
	"import 'http://www.eclipse.org/emf/2002/Ecore' as ecore\n" +
	"Model returns ecore::EClass : 'model' '/EOF' 'EOF' '�������' name=ID;";
	// @formatter:off
	XtextResource resource = getResourceFromString(model);
	Grammar grammar = ((Grammar) resource.getContents().get(0));
	KeywordHelper keywordHelper = new KeywordHelper(grammar, true, new GrammarAccessExtensions());
	Assert.assertEquals("[/EOF, EOF, model, �������]",
			IterableExtensions.sort(keywordHelper.getAllKeywords()).toString());
	Assert.assertEquals("KW_EOF_1", keywordHelper.getRuleName("/EOF"));
	Assert.assertEquals("KW_EOF", keywordHelper.getRuleName("EOF"));
	Assert.assertEquals("Model", keywordHelper.getRuleName("model"));
	Assert.assertEquals("AeOeUeaeOeUe", keywordHelper.getRuleName("�������"));
}
 
Example #2
Source File: KeywordHelper.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public KeywordHelper(Grammar grammar, boolean ignoreCase) {
	super(grammar, ignoreCase, new GrammarAccessExtensions());
}
 
Example #3
Source File: GrammarAccessUtil.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.7
 */
public static String serialize(EObject obj, String prefix, String lineDelimiter) {
	ISerializer serializer = getSerializer(lineDelimiter);
	String result = GrammarAccessExtensions.grammarFragmentToString(serializer, obj, prefix);
	return result;
}
 
Example #4
Source File: KeywordHelper.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public KeywordHelper(Grammar grammar, boolean ignoreCase, GrammarAccessExtensions grammarUtil) {
	this.ignoreCase = ignoreCase;
	this.grammarUtil = grammarUtil;
	keywordValueToToken = createKeywordMap(grammar);
	grammar.eResource().getResourceSet().eAdapters().add(this);
}