Package org.eclipse.xtext.parser

Examples of org.eclipse.xtext.parser.IParseResult


    PPGrammarAccess ga = runner.get(PPGrammarAccess.class);

    // Parse a string using the root rule "PuppetManifest"
    // throws an exception with the IParseResult if there are syntax errors
    // (test just fails if that is the case).
    IParseResult parseResult = runner.parseString(ga.getPuppetManifestRule(), "'I am often quoted'");

    // The RootASTElement is an instance of what the grammar rule specified
    // as return
    // (In this case a PuppetManifest).
    EObject result = parseResult.getRootASTElement();
    assertTrue("PuppetManifest retured", result instanceof PuppetManifest);

    // A PuppetManifest has a list of statements which are either
    // expressions
    // or a special ExprList which in turn contains a list (ExprList is for
View Full Code Here


  }

  public IParseResult parseString(ParserRule rule, String s) throws PPSyntaxErrorException {
    PPParser parser = getParser();
    IParseResult result = parser.parse(rule, new StringReader(s));
    if(result.hasSyntaxErrors())
      throw new PPSyntaxErrorException(result);
    return result;
  }
View Full Code Here

  @Test
  public void test_Parse_LiteralNameOrReference_NotOk() {
    PPGrammarAccess ga = (PPGrammarAccess) getGrammarAccess();
    PPParser parser = (PPParser) getParser();
    for(String s : invalidNames) {
      IParseResult result = parser.parse(ga.getUnionNameOrReferenceRule(), new StringReader(s));
      assertTrue("Should have errors for: " + s, result.hasSyntaxErrors());
    }

  }
View Full Code Here

  @Test
  public void test_Parse_LiteralNameOrReference_Ok() {
    PPGrammarAccess ga = (PPGrammarAccess) getGrammarAccess();
    PPParser parser = (PPParser) getParser();
    for(String s : validNames) {
      IParseResult result = parser.parse(ga.getUnionNameOrReferenceRule(), new StringReader(s));
      assertFalse("Should not have errors for: " + s, result.hasSyntaxErrors());
      assertEquals("parsed should be same as input", s, result.getRootNode().getText());
    }
    for(String s : validNames) {
      if("class".equals(s))
        continue; // 'class' alone is not a valid value expression
      IParseResult result = parser.parse(ga.getExpressionRule(), new StringReader(s));
      assertFalse("Should not have errors for: " + s, result.hasSyntaxErrors());
      assertEquals("parsed should be same as input", s, result.getRootNode().getText());
      EObject root = result.getRootASTElement();
      // if("class".equals(s)) {
      // assertTrue("Should be ResourceExpression", root instanceof ResourceExpression);
      // }
      // else {
      assertTrue("Should be LiteralNameOrReference", root instanceof LiteralNameOrReference);
      assertEquals("Literal should be same as input", s, ((LiteralNameOrReference) root).getValue());
      // }
    }
    for(String s : validNames) {
      if("class".equals(s))
        continue; // 'class' alone is not a balid value expression
      IParseResult result = parser.parse(ga.getPuppetManifestRule(), new StringReader(s));
      assertFalse("Should not have errors for: " + s, result.hasSyntaxErrors());
      assertEquals("parsed should be same as input", s, result.getRootNode().getText());
      EObject root = result.getRootASTElement();
      assertTrue("Should be PuppetManifest", root instanceof PuppetManifest);
      PuppetManifest pm = (PuppetManifest) root;
      assertTrue("Manifest should have statements", pm.getStatements().size() > 0);
      EObject expr = pm.getStatements().get(0);
      // if("class".equals(s)) {
View Full Code Here

  public void test_Parse_LiteralsInResource_Smoketest() {
    PPGrammarAccess ga = (PPGrammarAccess) getGrammarAccess();
    PPParser parser = (PPParser) getParser();

    String s = "File { mode => 666 }";
    IParseResult result = parser.parse(ga.getPuppetManifestRule(), new StringReader(s));
    assertFalse("Should not have errors for: " + s, result.hasSyntaxErrors());
    assertEquals("parsed should be same as input", s, result.getRootNode().getText());
    EObject root = result.getRootASTElement();
    assertTrue("Should be PuppetManifest", root instanceof PuppetManifest);
    PuppetManifest pm = (PuppetManifest) root;
    assertTrue("Manifest should have statements", pm.getStatements().size() > 0);
    EObject expr = pm.getStatements().get(0);
    assertInstanceOf("Should be ResourceExpression", ResourceExpression.class, expr);
View Full Code Here

  /**
   * check that the input can be successfully parsed given a specific entry
   * rule of the grammar
   * */
  protected void checkParsing(String input, String entryRule) {
    IParseResult la = getParseResult(input, entryRule);
    assertEquals(input, false, la.hasSyntaxErrors());
  }
View Full Code Here

  /**
   * check that the input cannot be successfully parsed given a specific entry
   * rule of the grammar
   * */
  protected void failParsing(String input, String entryRule) {
    IParseResult la = getParseResult(input, entryRule);
    assertEquals(input, false, la.hasSyntaxErrors());
  }
View Full Code Here

  protected Pair<EObject, IRegion> getXtextElementAt(XtextResource resource, final int offset) {
    // check for cross reference
    EObject crossLinkedEObject = eObjectAtOffsetHelper.resolveCrossReferencedElementAt(resource, offset);
    if (crossLinkedEObject != null) {
      if (!crossLinkedEObject.eIsProxy()) {
        IParseResult parseResult = resource.getParseResult();
        if (parseResult != null) {
          ILeafNode leafNode = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), offset);
          if(leafNode != null && leafNode.isHidden() && leafNode.getOffset() == offset) {
            leafNode = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), offset - 1);
          }
          if (leafNode != null) {
            return Tuples.create(crossLinkedEObject, (IRegion) new Region(leafNode.getOffset(), leafNode.getLength()));
          }
        }
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.