コード例 #1
0
 @Override
 public FlyweightCapableTreeStructure<LighterASTNode> parseContents(
     LighterLazyParseableNode chameleon) {
   final PsiBuilder builder = createBuilder(chameleon.getText());
   parse(builder);
   return builder.getLightTree();
 }
コード例 #2
0
 public void parse(PsiBuilder builder) {
   final PsiBuilder.Marker root = builder.mark();
   PsiBuilder.Marker error = null;
   while (!builder.eof()) {
     final String token = builder.getTokenText();
     if ("?".equals(token)) error = builder.mark();
     builder.advanceLexer();
     if (error != null) {
       error.error("test error 2");
       error = null;
     }
   }
   root.done(this);
 }
コード例 #3
0
  private static void doTest(
      @NonNls final String text, final Parser parser, @NonNls final String expected) {
    final PsiBuilder builder = createBuilder(text);
    final PsiBuilder.Marker rootMarker = builder.mark();
    parser.parse(builder);
    rootMarker.done(ROOT);

    // check light tree composition
    final FlyweightCapableTreeStructure<LighterASTNode> lightTree = builder.getLightTree();
    assertEquals(expected, DebugUtil.lightTreeToString(lightTree, false));
    // verify that light tree can be taken multiple times
    final FlyweightCapableTreeStructure<LighterASTNode> lightTree2 = builder.getLightTree();
    assertEquals(expected, DebugUtil.lightTreeToString(lightTree2, false));

    // check heavy tree composition
    final ASTNode root = builder.getTreeBuilt();
    assertEquals(expected, DebugUtil.nodeTreeToString(root, false));

    // check heavy vs. light tree merging
    final PsiBuilder builder2 = createBuilder(text);
    final PsiBuilder.Marker rootMarker2 = builder2.mark();
    parser.parse(builder2);
    rootMarker2.done(ROOT);
    DiffTree.diff(
        new ASTStructure(root),
        builder2.getLightTree(),
        new ShallowNodeComparator<ASTNode, LighterASTNode>() {
          @Override
          public ThreeState deepEqual(ASTNode oldNode, LighterASTNode newNode) {
            return ThreeState.UNSURE;
          }

          @Override
          public boolean typesEqual(ASTNode oldNode, LighterASTNode newNode) {
            return true;
          }

          @Override
          public boolean hashCodesEqual(ASTNode oldNode, LighterASTNode newNode) {
            return true;
          }
        },
        new DiffTreeChangeBuilder<ASTNode, LighterASTNode>() {
          @Override
          public void nodeReplaced(@NotNull ASTNode oldChild, @NotNull LighterASTNode newChild) {
            fail("replaced(" + oldChild + "," + newChild.getTokenType() + ")");
          }

          @Override
          public void nodeDeleted(@NotNull ASTNode oldParent, @NotNull ASTNode oldNode) {
            fail("deleted(" + oldParent + "," + oldNode + ")");
          }

          @Override
          public void nodeInserted(
              @NotNull ASTNode oldParent, @NotNull LighterASTNode newNode, int pos) {
            fail("inserted(" + oldParent + "," + newNode.getTokenType() + ")");
          }
        });
  }
コード例 #4
0
 public void parse(PsiBuilder builder) {
   final PsiBuilder.Marker root = builder.mark();
   PsiBuilder.Marker nested = null;
   while (!builder.eof()) {
     final String token = builder.getTokenText();
     if ("[".equals(token) && nested == null) {
       nested = builder.mark();
     }
     builder.advanceLexer();
     if ("]".equals(token) && nested != null) {
       nested.collapse(myCHAMELEON_2);
       nested.precede().done(OTHER);
       nested = null;
       builder.error("test error 1");
     }
   }
   if (nested != null) nested.drop();
   root.done(this);
 }
コード例 #5
0
 @Override
 public ASTNode parseContents(ASTNode chameleon) {
   final PsiBuilder builder = createBuilder(chameleon.getText());
   parse(builder);
   return builder.getTreeBuilt().getFirstChildNode();
 }
コード例 #6
0
  private static void doFailTest(
      @NonNls final String text, final Parser parser, @NonNls final String expected) {
    final PrintStream std = System.err;
    //noinspection IOResourceOpenedButNotSafelyClosed
    System.setErr(new PrintStream(new NullStream()));
    try {
      try {
        ParserDefinition parserDefinition =
            new ParserDefinition() {
              @NotNull
              @Override
              public Lexer createLexer(Project project) {
                return null;
              }

              @Override
              public PsiParser createParser(Project project) {
                return null;
              }

              @Override
              public IFileElementType getFileNodeType() {
                return null;
              }

              @NotNull
              @Override
              public TokenSet getWhitespaceTokens() {
                return TokenSet.EMPTY;
              }

              @NotNull
              @Override
              public TokenSet getCommentTokens() {
                return TokenSet.EMPTY;
              }

              @NotNull
              @Override
              public TokenSet getStringLiteralElements() {
                return null;
              }

              @NotNull
              @Override
              public PsiElement createElement(ASTNode node) {
                return null;
              }

              @Override
              public PsiFile createFile(FileViewProvider viewProvider) {
                return null;
              }

              @Override
              public SpaceRequirements spaceExistanceTypeBetweenTokens(
                  ASTNode left, ASTNode right) {
                return null;
              }
            };
        final PsiBuilder builder =
            PsiBuilderFactory.getInstance()
                .createBuilder(parserDefinition, new MyTestLexer(), text);
        builder.setDebugMode(true);
        parser.parse(builder);
        builder.getLightTree();
        fail("should fail");
      } catch (AssertionError e) {
        assertEquals(expected, e.getMessage());
      }
    } finally {
      System.setErr(std);
    }
  }