/*
 * Copyright 2015 Bernd Vogt and others.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.sourcepit.antlr4.eclipse.lang;

import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.BufferedTokenStream;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Token;
import org.sourcepit.ltk.ast.ParseResult;
import org.sourcepit.ltk.ast.ParserDelegate;

public class AntlrParserDelegate implements ParserDelegate {

   @Override
   public ParseResult parse(String input) {
      final CharStream charStream = new ANTLRInputStream(input);
      final Lexer lexer = new ANTLRv4Lexer(charStream);
      final BufferedTokenStream tokenStream = new CommonTokenStream(lexer);
      final ANTLRv4Parser parser = new ANTLRv4Parser(tokenStream);
      try {
         return new ParseResult(lexer, tokenStream, parser, parser.grammarSpec());
      }
      catch (RecognitionException e) {
         return new ParseResult(lexer, tokenStream, parser, e);
      }
   }

   @Override
   public ParseResult parseNestedLanguage(Class<? extends Lexer> sourceType, Token token) {
      return null;
   }

}

@@ -1737,24 +1737,695 @@
 en token) %7B%0A
+      if (ANTLRv4Lexer.class == sourceType) %7B%0A         if (ANTLRv4Lexer.BLOCK_COMMENT == token.getType()) %7B%0A            final CharStream charStream = new ANTLRInputStream(token.getText());%0A            final Lexer lexer = new CommentLexer(charStream);%0A            final BufferedTokenStream tokenStream = new CommonTokenStream(lexer);%0A            final CommentParser parser = new CommentParser(tokenStream);%0A            try %7B%0A               return new ParseResult(lexer, tokenStream, parser, parser.comment());%0A            %7D%0A            catch (RecognitionException e) %7B%0A               return new ParseResult(lexer, tokenStream, parser, e);%0A            %7D%0A         %7D%0A      %7D%0A
       return

Include comments in parse tree