org.antlr.runtime.tree.TreeNodeStream Java Examples

The following examples show how to use org.antlr.runtime.tree.TreeNodeStream. 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: Cob2Xsd.java    From legstar-core2 with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Generates a model from an Abstract Syntax Tree.
 * 
 * @param ast the abstract syntax tree produced by parser
 * @return a list of root COBOL data items
 * @throws RecognizerException if tree cannot be walked
 */
public List < CobolDataItem > emitModel(final CommonTree ast)
        throws RecognizerException {
    List < CobolDataItem > cobolDataItems = new ArrayList < CobolDataItem >();
    if (_log.isDebugEnabled()) {
        _log.debug("4. Emitting Model from AST: {}",
                ((ast == null) ? "null" : ast.toStringTree()));
    }
    if (ast == null) {
        return cobolDataItems;
    }
    try {
        TreeNodeStream nodes = new CommonTreeNodeStream(ast);
        CobolStructureEmitter emitter = new CobolStructureEmitterImpl(
                nodes, getErrorHandler());
        emitter.cobdata(cobolDataItems);
        return cobolDataItems;
    } catch (RecognitionException e) {
        throw new RecognizerException(e);
    }
}
 
Example #2
Source File: AbstractCobolTester.java    From legstar-core2 with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Starting from a COBOL source fragment translates to XML Schema.
 * @param source COBOL source fragment.
 * @return an XML Schema
 * @throws RecognizerException if emit fails
 */
public String emit(final String source)  throws RecognizerException {
    try {
        CommonTree ast = parse(source);
        if (_log.isDebugEnabled()) {
            _log.debug(ast.toStringTree());
        }
        TreeNodeStream nodes = new CommonTreeNodeStream(ast);
        CobolStructureEmitter emitter = new CobolStructureEmitterImpl(
                nodes, getErrorHandler());
        List < CobolDataItem > dataEntries = new ArrayList < CobolDataItem >();
        emitter.cobdata(dataEntries);
        return dataEntries.toString();
    } catch (RecognitionException e) {
        throw new RecognizerException(e);
    }
}
 
Example #3
Source File: SqlParser.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static Statement createStatement(CommonTree tree) {
    TreeNodeStream stream = new BufferedTreeNodeStream(tree);
    StatementBuilder builder = new StatementBuilder(stream);
    try {
        return builder.statement().value;
    } catch (RecognitionException e) {
        throw new AssertionError(e); // RecognitionException is not thrown
    }
}
 
Example #4
Source File: SqlParser.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private static Expression createExpression(CommonTree tree) {
    TreeNodeStream stream = new BufferedTreeNodeStream(tree);
    StatementBuilder builder = new StatementBuilder(stream);
    try {
        return builder.singleExpression().value;
    } catch (RecognitionException e) {
        throw new AssertionError(e); // RecognitionException is not thrown
    }
}
 
Example #5
Source File: SqlParser.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private static String createIdentifier(CommonTree identTree) {
    TreeNodeStream stream = new BufferedTreeNodeStream(identTree);
    StatementBuilder builder = new StatementBuilder(stream);
    try {
        return builder.ident().value;
    } catch (RecognitionException e) {
        throw new AssertionError(e); // RecognitionException is not thrown
    }
}
 
Example #6
Source File: CobolStructureEmitterImpl.java    From legstar-core2 with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Construct from a tree nodes stream and a shared state.
 * @param input the tree nodes stream
 * @param state the shared state
 * @param errorHandler handles error messages
 */
public CobolStructureEmitterImpl(
        final TreeNodeStream input,
        final RecognizerSharedState state,
        final RecognizerErrorHandler errorHandler) {
    super(input, state);
    _errorHandler = errorHandler;
}
 
Example #7
Source File: DSLMapWalker.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
public DSLMapWalker(TreeNodeStream input) {
	this(input, new RecognizerSharedState());
}
 
Example #8
Source File: DSLMapWalker.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
public DSLMapWalker(TreeNodeStream input, RecognizerSharedState state) {
	super(input, state);
}
 
Example #9
Source File: ElementFrequenciesVisitor.java    From codebuff with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ElementFrequenciesVisitor(TreeNodeStream input) {
	super(input);
	frequencies = new ArrayDeque<FrequencySet<String>>();
	frequencies.push(new FrequencySet<String>());
}
 
Example #10
Source File: CobolStructureEmitterImpl.java    From legstar-core2 with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Construct from a tree nodes stream.
 * @param input the tree nodes stream
 * @param errorHandler handles error messages
 */
public CobolStructureEmitterImpl(
        final TreeNodeStream input,
        final RecognizerErrorHandler errorHandler) {
    this(input, new RecognizerSharedState(), errorHandler);
}