Package org.eclipse.xtext.parser

Examples of org.eclipse.xtext.parser.IParseResult


  private static EObject rootOf(XtextResource resource) {
    if (resource == null) {
      return null;
    }
    IParseResult parseResult = resource.getParseResult();
    return parseResult == null ? null : parseResult.getRootASTElement();
  }
View Full Code Here


  }

  public IParseResult parseText(String text) {
    boolean ignoreSyntaxErrors = shouldIgnoreSyntaxErrorsIn(text);
    XtextResource resource = createResourceFrom(new StringInputStream(text));
    IParseResult parseResult = resource.getParseResult();
    if (ignoreSyntaxErrors || !parseResult.hasSyntaxErrors()) {
      return parseResult;
    }
    StringBuilder builder = new StringBuilder();
    builder.append("Syntax errors:");
    for (INode error : parseResult.getSyntaxErrors()) {
      builder.append(lineSeparator()).append("- ").append(error.getSyntaxErrorMessage());
    }
    throw new IllegalStateException(builder.toString());
  }
View Full Code Here

    }
    return null;
  }

  public void parseText(String text) {
    IParseResult parseResult = protobufParser.parseText(text);
    root = (Protobuf) parseResult.getRootASTElement();
    if (root != null) {
      resource = (XtextResource) root.eResource();
    }
  }
View Full Code Here

   * @param resource the given resource.
   * @return the root element of the given resource, or {@code null} if the given resource does not have a root element.
   */
  public Protobuf rootOf(Resource resource) {
    if (resource instanceof XtextResource) {
      IParseResult parseResult = ((XtextResource) resource).getParseResult();
      if (parseResult != null) {
        EObject root = parseResult.getRootASTElement();
        return (Protobuf) root;
      }
    }
    TreeIterator<Object> contents = getAllContents(resource, true);
    if (contents.hasNext()) {
View Full Code Here

    }
    return base;
  }

  private void parseText(String text) {
    IParseResult parseResult = protobufParser.parseText(text);
    rootNode = parseResult.getRootNode();
  }
View Full Code Here

public class PreferenceDrivenProtobufParser extends ProtobufParser {
  @Inject private IPreferenceStoreAccess storeAccess;

  @Override protected IParseResult doParse(String ruleName, CharStream in, NodeModelBuilder builder,
      int initialLookAhead) {
    IParseResult result = super.doParse(ruleName, in, builder, initialLookAhead);
    MiscellaneousPreferences preferences = new MiscellaneousPreferences(storeAccess);
    if (preferences.isGoogleInternal() && isNotProto2(result)) {
      return new ParseResult(new NonProto2Protobuf(), result.getRootNode(), false);
    }
    return result;
  }
View Full Code Here

 
  public String findTask(final XtextResource res, final int offset) {
    if ((offset < 0)) {
      return null;
    }
    IParseResult _parseResult = res.getParseResult();
    ICompositeNode _rootNode = _parseResult.getRootNode();
    final ILeafNode start = NodeModelUtils.findLeafNodeAtOffset(_rootNode, offset);
    boolean _isHidden = start.isHidden();
    if (_isHidden) {
      IParseResult _parseResult_1 = res.getParseResult();
      ICompositeNode _rootNode_1 = _parseResult_1.getRootNode();
      Iterable<ILeafNode> _leafNodes = _rootNode_1.getLeafNodes();
      final List<ILeafNode> list = IterableExtensions.<ILeafNode>toList(_leafNodes);
      final int index = list.indexOf(start);
      IntegerRange _upTo = new IntegerRange(index, 0);
      final Function1<Integer, Boolean> _function = new Function1<Integer, Boolean>() {
View Full Code Here

 
  public void doProvideHighlightingFor(final XtextResource resource, final IHighlightedPositionAcceptor acceptor) {
    super.doProvideHighlightingFor(resource, acceptor);
    acceptor.addPosition(0, 4, TemplateHighlightingConfiguration.TEXT);
    acceptor.addPosition(4, 1, TemplateHighlightingConfiguration.ESCAPE);
    IParseResult _parseResult = resource.getParseResult();
    ICompositeNode _rootNode = _parseResult.getRootNode();
    Iterable<ILeafNode> _leafNodes = _rootNode.getLeafNodes();
    for (final ILeafNode leafNode : _leafNodes) {
      boolean _isText = this.isText(leafNode);
      if (_isText) {
        int _offset = leafNode.getOffset();
View Full Code Here

   * TODO: Use this
   *
   * @since 2.1
   */
  public INode getCrossReferenceNode(XtextResource resource, ITextRegion region) {
    IParseResult parseResult = resource.getParseResult();
    if(parseResult != null && parseResult.getRootNode() != null) {
      ILeafNode leaf = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), region.getOffset());
      INode crossRefNode = findCrossReferenceNode(leaf);
      // if not a cross reference position and the cursor is at the beginning of a node try the previous one.
      if(crossRefNode == null && leaf != null && region.getLength() == 0 &&
          leaf.getOffset() == region.getOffset()) {
        leaf = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), region.getOffset() - 1);
        return findCrossReferenceNode(leaf);
      }
      else if(crossRefNode != null &&
          crossRefNode.getOffset() + crossRefNode.getLength() >= region.getOffset() + region.getLength()) {
        return crossRefNode;
View Full Code Here

   * result.
   */
  @Override
  protected String getURIFragmentRootSegment(EObject eObject) {
    if(unloadingContents == null) {
      IParseResult parseResult = getParseResult();
      if(parseResult != null && eObject == parseResult.getRootASTElement()) {
        return "0";
      }
    }
    return super.getURIFragmentRootSegment(eObject);
  }
View Full Code Here

TOP

Related Classes of org.eclipse.xtext.parser.IParseResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.