org.eclipse.xtext.parser.IParser Java Examples

The following examples show how to use org.eclipse.xtext.parser.IParser. 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: N4LanguageUtils.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Parses the given string with the parser of the Xtext language denoted by the given file extension. In case of
 * syntax errors, the returned parse result will have a non-empty list of {@link ParseResult#errors}.
 */
public static <T extends EObject> ParseResult<T> parseXtextLanguage(String fileExtOfLanguage,
		ParserRule parserRuleOrNull, Class<T> expectedTypeOfRoot, Reader sourceReader) {
	final IParser parser = getServiceForContext(fileExtOfLanguage, IParser.class)
			.orElseThrow(() -> new RuntimeException(
					"Cannot obtain Xtext parser for language with file extension: " + fileExtOfLanguage));
	final IParseResult result;
	if (parserRuleOrNull != null) {
		result = parser.parse(parserRuleOrNull, sourceReader);
	} else {
		result = parser.parse(sourceReader);
	}
	final Iterable<SyntaxErrorMessage> errors = Iterables.transform(result.getSyntaxErrors(),
			node -> node.getSyntaxErrorMessage());
	final EObject root = result.getRootASTElement();
	if (root != null && expectedTypeOfRoot.isInstance(root)) {
		final T rootCasted = expectedTypeOfRoot.cast(root);
		return new ParseResult<>(rootCasted, errors);
	}
	return new ParseResult<>(null, errors);
}
 
Example #2
Source File: DotAutoEditStrategy.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
private HtmlTag findOpenTag(String htmlLabelText, int offset) {
	Injector htmlLabelInjector = DotActivator.getInstance().getInjector(
			DotActivator.ORG_ECLIPSE_GEF_DOT_INTERNAL_LANGUAGE_DOTHTMLLABEL);
	IParser htmlLabelParser = htmlLabelInjector.getInstance(IParser.class);

	HtmlLabel htmlLabel = (HtmlLabel) htmlLabelParser
			.parse(new StringReader(htmlLabelText)).getRootASTElement();

	if (htmlLabel != null) {
		HtmlContent result = findContentAtOffset(htmlLabel.getParts(),
				offset);

		if (result != null) {
			return result.getTag();
		}
	}

	return null;
}
 
Example #3
Source File: DotFontUtil.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
public FontName parseHtmlFontFace(String face) {
	if (face == null) {
		return null;
	}
	IParser parser = DotActivator.getInstance().getInjector(
			DotActivator.ORG_ECLIPSE_GEF_DOT_INTERNAL_LANGUAGE_DOTFONTNAME)
			.getInstance(IParser.class);
	EObject rootNode = parser.parse(new StringReader(face))
			.getRootASTElement();
	if (rootNode instanceof FontName) {
		return (FontName) rootNode;
	}
	return null;
}
 
Example #4
Source File: DotColorUtil.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the {@link Color} of a HTML-like label color attribute
 *
 * @param htmlColor
 *            The string attribute value.
 * @return The corresponding {@link Color}.
 */
public Color computeHtmlColor(String htmlColor) {
	if (htmlColor == null) {
		return null;
	}
	IParser parser = DotActivator.getInstance().getInjector(
			DotActivator.ORG_ECLIPSE_GEF_DOT_INTERNAL_LANGUAGE_DOTCOLOR)
			.getInstance(IParser.class);
	EObject rootNode = parser.parse(new StringReader(htmlColor))
			.getRootASTElement();
	if (rootNode instanceof Color) {
		return (Color) rootNode;
	}
	return null;
}
 
Example #5
Source File: AbstractFormatterTestLanguageRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IParser> bindIParser() {
	return FormatterTestLanguageParser.class;
}
 
Example #6
Source File: AbstractBmTestLanguageRuntimeModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IParser> bindIParser() {
	return BmTestLanguageParser.class;
}
 
Example #7
Source File: AbstractBug303200TestLanguageRuntimeModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IParser> bindIParser() {
	return Bug303200TestLanguageParser.class;
}
 
Example #8
Source File: AbstractEnumRulesTestLanguageRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IParser> bindIParser() {
	return EnumRulesTestLanguageParser.class;
}
 
Example #9
Source File: AbstractPartialParserTestLanguageRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IParser> bindIParser() {
	return PartialParserTestLanguageParser.class;
}
 
Example #10
Source File: AbstractBug443221TestLanguageRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IParser> bindIParser() {
	return Bug443221TestLanguageParser.class;
}
 
Example #11
Source File: AbstractMultiGenMMTestLanguageRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IParser> bindIParser() {
	return MultiGenMMTestLanguageParser.class;
}
 
Example #12
Source File: AbstractBug362902RuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IParser> bindIParser() {
	return Bug362902Parser.class;
}
 
Example #13
Source File: AbstractContextFinderTestLanguageRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IParser> bindIParser() {
	return ContextFinderTestLanguageParser.class;
}
 
Example #14
Source File: AbstractParametersTestLanguageExRuntimeModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IParser> bindIParser() {
	return ParametersTestLanguageExParser.class;
}
 
Example #15
Source File: AbstractQuickfixCrossrefTestLanguageRuntimeModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IParser> bindIParser() {
	return QuickfixCrossrefTestLanguageParser.class;
}
 
Example #16
Source File: IndentationAwareTestLanguageRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Class<? extends IParser> bindIParser() {
	return CustomizedIndentationAwareTestLanguageParser.class;
}
 
Example #17
Source File: AbstractGH341TestLanguageRuntimeModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IParser> bindIParser() {
	return GH341TestLanguageParser.class;
}
 
Example #18
Source File: AbstractSimpleUnorderedGroupsTestLanguageRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IParser> bindIParser() {
	return SimpleUnorderedGroupsTestLanguageParser.class;
}
 
Example #19
Source File: AbstractFragmentTestLanguageRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IParser> bindIParser() {
	return FragmentTestLanguageParser.class;
}
 
Example #20
Source File: AbstractFormatterTestLanguage2RuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IParser> bindIParser() {
	return FormatterTestLanguage2Parser.class;
}
 
Example #21
Source File: AbstractTransientValuesTestRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IParser> bindIParser() {
	return TransientValuesTestParser.class;
}
 
Example #22
Source File: AbstractBug301935TestLanguageRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IParser> bindIParser() {
	return Bug301935TestLanguageParser.class;
}
 
Example #23
Source File: AbstractBug304681TestLanguageRuntimeModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IParser> bindIParser() {
	return Bug304681TestLanguageParser.class;
}
 
Example #24
Source File: AbstractDomainModelTestLanguageRuntimeModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IParser> bindIParser() {
	return DomainModelTestLanguageParser.class;
}
 
Example #25
Source File: AbstractExBeeLangTestLanguageRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IParser> bindIParser() {
	return ExBeeLangTestLanguageParser.class;
}
 
Example #26
Source File: AbstractBug302128TestLanguageRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IParser> bindIParser() {
	return Bug302128TestLanguageParser.class;
}
 
Example #27
Source File: AbstractOutlineTestLanguageRuntimeModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IParser> bindIParser() {
	return OutlineTestLanguageParser.class;
}
 
Example #28
Source File: AbstractImportUriUiTestLanguageRuntimeModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IParser> bindIParser() {
	return ImportUriUiTestLanguageParser.class;
}
 
Example #29
Source File: AbstractBug289515TestLanguageRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IParser> bindIParser() {
	return Bug289515TestLanguageParser.class;
}
 
Example #30
Source File: AbstractTwoContextsTestLanguageRuntimeModule.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends IParser> bindIParser() {
	return TwoContextsTestLanguageParser.class;
}