org.antlr.runtime.CommonTokenStream Java Examples

The following examples show how to use org.antlr.runtime.CommonTokenStream. 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: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Load a group file with full path {@code fileName}; it's relative to root by {@code prefix}. */

    public void loadGroupFile(String prefix, String fileName) {
        if ( verbose ) System.out.println(this.getClass().getSimpleName()+".loadGroupFile(group-file-prefix="+prefix +
                                          ", fileName=" +
fileName +
                                          ")");
        GroupParser parser;
        try {
            URL f = new URL(fileName);
            ANTLRInputStream fs = new ANTLRInputStream(f.openStream(), encoding);
            GroupLexer lexer = new GroupLexer(fs);
            fs.name = fileName;
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            parser = new GroupParser(tokens);
            parser.group(this, prefix);
        }
        catch (Exception e) {
            errMgr.IOError(null, ErrorType.CANT_LOAD_GROUP_FILE, e, fileName);
        }
    }
 
Example #2
Source File: TreeTest.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
private LogicalExpression parseExpression(String expr) throws RecognitionException, IOException{

    ExprLexer lexer = new ExprLexer(new ANTLRStringStream(expr));
    CommonTokenStream tokens = new CommonTokenStream(lexer);

//    tokens.fill();
//    for(Token t : (List<Token>) tokens.getTokens()){
//      System.out.println(t + "" + t.getType());
//    }
//    tokens.rewind();

    ExprParser parser = new ExprParser(tokens);
    parse_return ret = parser.parse();

    return ret.e;

  }
 
Example #3
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Load a group file with full path {@code fileName}; it's relative to root by {@code prefix}. */

    public void loadGroupFile(String prefix, String fileName) {
        if ( verbose ) System.out.println(this.getClass().getSimpleName()+".loadGroupFile(group-file-prefix="+prefix+", fileName="+fileName+")");
        GroupParser parser;
        try {
            URL f = new URL(fileName);
            ANTLRInputStream fs = new ANTLRInputStream(f.openStream(), encoding);
            GroupLexer lexer = new GroupLexer(fs);
            fs.name = fileName;
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            parser = new GroupParser(tokens);
            parser.group(this, prefix);
        }
        catch (Exception e) {
            errMgr.IOError(null, ErrorType.CANT_LOAD_GROUP_FILE, e, fileName);
        }
    }
 
Example #4
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Load a group file with full path {@code fileName}; it's relative to root by {@code prefix}. */

    public void loadGroupFile(String prefix, String fileName) {
        if ( verbose ) System.out.println(this.getClass().getSimpleName()+".loadGroupFile(group-file-prefix="+prefix+", fileName="+fileName+")");
        GroupParser parser;
        try {
            URL f = new URL(fileName);
            ANTLRInputStream fs = new ANTLRInputStream(f.openStream(), encoding);
            GroupLexer lexer = new GroupLexer(fs);
            fs.name = fileName;
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            parser = new GroupParser(tokens);
            parser.group(this, prefix);
        }
        catch (Exception e) {
            errMgr.IOError(null, ErrorType.CANT_LOAD_GROUP_FILE, e, fileName);
        }
    }
 
Example #5
Source File: STGroupString.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void load() {
    if ( alreadyLoaded ) return;
    alreadyLoaded = true;
    GroupParser parser;
    try {
        ANTLRStringStream fs = new ANTLRStringStream(text);
        fs.name = sourceName;
        GroupLexer lexer = new GroupLexer(fs);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        parser = new GroupParser(tokens);
        // no prefix since this group file is the entire group, nothing lives
        // beneath it.
        parser.group(this, "/");
    }
    catch (Exception e) {
        errMgr.IOError(null, ErrorType.CANT_LOAD_GROUP_FILE, e, "<string>");
    }
}
 
Example #6
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Load a group file with full path {@code fileName}; it's relative to root by {@code prefix}. */

    public void loadGroupFile(String prefix, String fileName) {
        if ( verbose ) System.out.println(this.getClass().getSimpleName()+".loadGroupFile(group-file-prefix="+prefix+", fileName="+fileName+")");
        GroupParser parser;
        try {
            URL f = new URL(fileName);
            ANTLRInputStream fs = new ANTLRInputStream(f.openStream(), encoding);
            GroupLexer lexer = new GroupLexer(fs);
            fs.name = fileName;
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            parser = new GroupParser(tokens);
            parser.group(this, prefix);
        }
        catch (Exception e) {
            errMgr.IOError(null, ErrorType.CANT_LOAD_GROUP_FILE, e, fileName);
        }
    }
 
Example #7
Source File: STGroupString.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void load() {
    if ( alreadyLoaded ) return;
    alreadyLoaded = true;
    GroupParser parser;
    try {
        ANTLRStringStream fs = new ANTLRStringStream(text);
        fs.name = sourceName;
        GroupLexer lexer = new GroupLexer(fs);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        parser = new GroupParser(tokens);
        // no prefix since this group file is the entire group, nothing lives
        // beneath it.
        parser.group(this, "/");
    }
    catch (Exception e) {
        errMgr.IOError(null, ErrorType.CANT_LOAD_GROUP_FILE, e, "<string>");
    }
}
 
Example #8
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Load a group file with full path {@code fileName}; it's relative to root by {@code prefix}. */

    public void loadGroupFile(String prefix, String fileName) {
        if ( verbose ) System.out.println(this.getClass().getSimpleName()+".loadGroupFile(group-file-prefix="+prefix+", fileName="+fileName+")");
        GroupParser parser;
        try {
            URL f = new URL(fileName);
            ANTLRInputStream fs = new ANTLRInputStream(f.openStream(), encoding);
            GroupLexer lexer = new GroupLexer(fs);
            fs.name = fileName;
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            parser = new GroupParser(tokens);
            parser.group(this, prefix);
        }
        catch (Exception e) {
            errMgr.IOError(null, ErrorType.CANT_LOAD_GROUP_FILE, e, fileName);
        }
    }
 
Example #9
Source File: STGroupString.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void load() {
    if ( alreadyLoaded ) return;
    alreadyLoaded = true;
    GroupParser parser;
    try {
        ANTLRStringStream fs = new ANTLRStringStream(text);
        fs.name = sourceName;
        GroupLexer lexer = new GroupLexer(fs);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        parser = new GroupParser(tokens);
        // no prefix since this group file is the entire group, nothing lives
        // beneath it.
        parser.group(this, "/");
    }
    catch (Exception e) {
        errMgr.IOError(null, ErrorType.CANT_LOAD_GROUP_FILE, e, "<string>");
    }
}
 
Example #10
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Load a group file with full path {@code fileName}; it's relative to root by {@code prefix}. */

    public void loadGroupFile(String prefix, String fileName) {
        if ( verbose ) System.out.println(this.getClass().getSimpleName()+".loadGroupFile(group-file-prefix="+prefix+", fileName="+fileName+")");
        GroupParser parser;
        try {
            URL f = new URL(fileName);
            ANTLRInputStream fs = new ANTLRInputStream(f.openStream(), encoding);
            GroupLexer lexer = new GroupLexer(fs);
            fs.name = fileName;
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            parser = new GroupParser(tokens);
            parser.group(this, prefix);
        }
        catch (Exception e) {
            errMgr.IOError(null, ErrorType.CANT_LOAD_GROUP_FILE, e, fileName);
        }
    }
 
Example #11
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Load template stream into this group. {@code unqualifiedFileName} is
 *  {@code "a.st"}. The {@code prefix} is path from group root to
 *  {@code unqualifiedFileName} like {@code "/subdir"} if file is in
 *  {@code /subdir/a.st}.
 */

public CompiledST loadTemplateFile(String prefix, String unqualifiedFileName, CharStream templateStream) {
    GroupLexer lexer = new GroupLexer(templateStream);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    GroupParser parser = new GroupParser(tokens);
    parser.group = this;
    lexer.group = this;
    try {
        parser.templateDef(prefix);
    }
    catch (RecognitionException re) {
        errMgr.groupSyntaxError(ErrorType.SYNTAX_ERROR, unqualifiedFileName, re, re.getMessage());
    }

    String templateName = Misc.getFileNameNoSuffix(unqualifiedFileName);
    if ( prefix!=null && prefix.length()>0 ) templateName = prefix+templateName;
    CompiledST impl = rawGetTemplate(templateName);
    impl.prefix = prefix;
    return impl;
}
 
Example #12
Source File: STGroupString.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void load() {
    if ( alreadyLoaded ) return;
    alreadyLoaded = true;
    GroupParser parser;
    try {
        ANTLRStringStream fs = new ANTLRStringStream(text);
        fs.name = sourceName;
        GroupLexer lexer = new GroupLexer(fs);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        parser = new GroupParser(tokens);
        // no prefix since this group file is the entire group, nothing lives
        // beneath it.
        parser.group(this, "/");
    }
    catch (Exception e) {
        errMgr.IOError(null, ErrorType.CANT_LOAD_GROUP_FILE, e, "<string>");
    }
}
 
Example #13
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Load a group file with full path {@code fileName}; it's relative to root by {@code prefix}. */

    public void loadGroupFile(String prefix, String fileName) {
        if ( verbose ) System.out.println(this.getClass().getSimpleName()+".loadGroupFile(group-file-prefix="+prefix+", fileName="+fileName+")");
        GroupParser parser;
        try {
            URL f = new URL(fileName);
            ANTLRInputStream fs = new ANTLRInputStream(f.openStream(), encoding);
            GroupLexer lexer = new GroupLexer(fs);
            fs.name = fileName;
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            parser = new GroupParser(tokens);
            parser.group(this, prefix);
        }
        catch (Exception e) {
            errMgr.IOError(null, ErrorType.CANT_LOAD_GROUP_FILE, e, fileName);
        }
    }
 
Example #14
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Load template stream into this group. {@code unqualifiedFileName} is
 *  {@code "a.st"}. The {@code prefix} is path from group root to
 *  {@code unqualifiedFileName} like {@code "/subdir"} if file is in
 *  {@code /subdir/a.st}.
 */

public CompiledST loadTemplateFile(String prefix, String unqualifiedFileName, CharStream templateStream) {
    GroupLexer lexer = new GroupLexer(templateStream);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    GroupParser parser = new GroupParser(tokens);
    parser.group = this;
    lexer.group = this;
    try {
        parser.templateDef(prefix);
    }
    catch (RecognitionException re) {
        errMgr.groupSyntaxError(ErrorType.SYNTAX_ERROR, unqualifiedFileName, re, re.getMessage());
    }

    String templateName = Misc.getFileNameNoSuffix(unqualifiedFileName);
    if ( prefix!=null && prefix.length()>0 ) templateName = prefix+templateName;
    CompiledST impl = rawGetTemplate(templateName);
    impl.prefix = prefix;
    return impl;
}
 
Example #15
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Load a group file with full path {@code fileName}; it's relative to root by {@code prefix}. */

    public void loadGroupFile(String prefix, String fileName) {
        if ( verbose ) System.out.println(this.getClass().getSimpleName()+".loadGroupFile(group-file-prefix="+prefix+", fileName="+fileName+")");
        GroupParser parser;
        try {
            URL f = new URL(fileName);
            ANTLRInputStream fs = new ANTLRInputStream(f.openStream(), encoding);
            GroupLexer lexer = new GroupLexer(fs);
            fs.name = fileName;
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            parser = new GroupParser(tokens);
            parser.group(this, prefix);
        }
        catch (Exception e) {
            errMgr.IOError(null, ErrorType.CANT_LOAD_GROUP_FILE, e, fileName);
        }
    }
 
Example #16
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Load template stream into this group. {@code unqualifiedFileName} is
 *  {@code "a.st"}. The {@code prefix} is path from group root to
 *  {@code unqualifiedFileName} like {@code "/subdir"} if file is in
 *  {@code /subdir/a.st}.
 */

public CompiledST loadTemplateFile(String prefix, String unqualifiedFileName, CharStream templateStream) {
    GroupLexer lexer = new GroupLexer(templateStream);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    GroupParser parser = new GroupParser(tokens);
    parser.group = this;
    lexer.group = this;
    try {
        parser.templateDef(prefix);
    }
    catch (RecognitionException re) {
        errMgr.groupSyntaxError(ErrorType.SYNTAX_ERROR, unqualifiedFileName, re, re.getMessage());
    }

    String templateName = Misc.getFileNameNoSuffix(unqualifiedFileName);
    if ( prefix!=null && prefix.length()>0 ) templateName = prefix+templateName;
    CompiledST impl = rawGetTemplate(templateName);
    impl.prefix = prefix;
    return impl;
}
 
Example #17
Source File: STGroupString.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void load() {
    if ( alreadyLoaded ) return;
    alreadyLoaded = true;
    GroupParser parser;
    try {
        ANTLRStringStream fs = new ANTLRStringStream(text);
        fs.name = sourceName;
        GroupLexer lexer = new GroupLexer(fs);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        parser = new GroupParser(tokens);
        // no prefix since this group file is the entire group, nothing lives
        // beneath it.
        parser.group(this, "/");
    }
    catch (Exception e) {
        errMgr.IOError(null, ErrorType.CANT_LOAD_GROUP_FILE, e, "<string>");
    }
}
 
Example #18
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Load a group file with full path {@code fileName}; it's relative to root by {@code prefix}. */

    public void loadGroupFile(String prefix, String fileName) {
        if ( verbose ) System.out.println(this.getClass().getSimpleName()+".loadGroupFile(group-file-prefix="+prefix +
                                          ", fileName=" +
fileName +
                                          ")");
        GroupParser parser;
        try {
            URL f = new URL(fileName);
            ANTLRInputStream fs = new ANTLRInputStream(f.openStream(), encoding);
            GroupLexer lexer = new GroupLexer(fs);
            fs.name = fileName;
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            parser = new GroupParser(tokens);
            parser.group(this, prefix);
        }
        catch (Exception e) {
            errMgr.IOError(null, ErrorType.CANT_LOAD_GROUP_FILE, e, fileName);
        }
    }
 
Example #19
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Load template stream into this group. {@code unqualifiedFileName} is
 *  {@code "a.st"}. The {@code prefix} is path from group root to
 *  {@code unqualifiedFileName} like {@code "/subdir"} if file is in
 *  {@code /subdir/a.st}.
 */

public CompiledST loadTemplateFile(String prefix, String unqualifiedFileName, CharStream templateStream) {
    GroupLexer lexer = new GroupLexer(templateStream);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    GroupParser parser = new GroupParser(tokens);
    parser.group = this;
    lexer.group = this;
    try {
        parser.templateDef(prefix);
    }
    catch (RecognitionException re) {
        errMgr.groupSyntaxError(ErrorType.SYNTAX_ERROR, unqualifiedFileName, re, re.getMessage());
    }

    String templateName = Misc.getFileNameNoSuffix(unqualifiedFileName);
    if ( prefix !=null && prefix.length()>0 ) templateName = prefix+templateName;
    CompiledST impl = rawGetTemplate(templateName);
    impl.prefix = prefix;
    return impl;
}
 
Example #20
Source File: STGroupString.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void load() {
    if ( alreadyLoaded ) return;
    alreadyLoaded = true;
    GroupParser parser;
    try {
        ANTLRStringStream fs = new ANTLRStringStream(text);
        fs.name = sourceName;
        GroupLexer lexer = new GroupLexer(fs);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        parser = new GroupParser(tokens);
        // no prefix since this group file is the entire group, nothing lives
        // beneath it.
        parser.group(this, "/");
    }
    catch (Exception e) {
        errMgr.IOError(null, ErrorType.CANT_LOAD_GROUP_FILE, e, "<string>");
    }
}
 
Example #21
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Load a group file with full path {@code fileName}; it's relative to root by {@code prefix}. */

    public void loadGroupFile(String prefix, String fileName) {
        if ( verbose ) System.out.println(this.getClass().getSimpleName()+".loadGroupFile(group-file-prefix="+prefix +
                                          ", fileName=" +
fileName +
                                          ")");
        GroupParser parser;
        try {
            URL f = new URL(fileName);
            ANTLRInputStream fs = new ANTLRInputStream(f.openStream(), encoding);
            GroupLexer lexer = new GroupLexer(fs);
            fs.name = fileName;
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            parser = new GroupParser(tokens);
            parser.group(this, prefix);
        }
        catch (Exception e) {
            errMgr.IOError(null, ErrorType.CANT_LOAD_GROUP_FILE, e, fileName);
        }
    }
 
Example #22
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Load template stream into this group. {@code unqualifiedFileName} is
 *  {@code "a.st"}. The {@code prefix} is path from group root to
 *  {@code unqualifiedFileName} like {@code "/subdir"} if file is in
 *  {@code /subdir/a.st}.
 */

public CompiledST loadTemplateFile(String prefix, String unqualifiedFileName, CharStream templateStream) {
    GroupLexer lexer = new GroupLexer(templateStream);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    GroupParser parser = new GroupParser(tokens);
    parser.group = this;
    lexer.group = this;
    try {
        parser.templateDef(prefix);
    }
    catch (RecognitionException re) {
        errMgr.groupSyntaxError(ErrorType.SYNTAX_ERROR, unqualifiedFileName, re, re.getMessage());
    }

    String templateName = Misc.getFileNameNoSuffix(unqualifiedFileName);
    if ( prefix !=null && prefix.length()>0 ) templateName = prefix+templateName;
    CompiledST impl = rawGetTemplate(templateName);
    impl.prefix = prefix;
    return impl;
}
 
Example #23
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Load template stream into this group. {@code unqualifiedFileName} is
 *  {@code "a.st"}. The {@code prefix} is path from group root to
 *  {@code unqualifiedFileName} like {@code "/subdir"} if file is in
 *  {@code /subdir/a.st}.
 */

public CompiledST loadTemplateFile(String prefix, String unqualifiedFileName, CharStream templateStream) {
    GroupLexer lexer = new GroupLexer(templateStream);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    GroupParser parser = new GroupParser(tokens);
    parser.group = this;
    lexer.group = this;
    try {
        parser.templateDef(prefix);
    }
    catch (RecognitionException re) {
        errMgr.groupSyntaxError(ErrorType.SYNTAX_ERROR, unqualifiedFileName, re, re.getMessage());
    }

    String templateName = Misc.getFileNameNoSuffix(unqualifiedFileName);
    if ( prefix!=null && prefix.length()>0 ) templateName = prefix+templateName;
    CompiledST impl = rawGetTemplate(templateName);
    impl.prefix = prefix;
    return impl;
}
 
Example #24
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Load a group file with full path {@code fileName}; it's relative to root by {@code prefix}. */

    public void loadGroupFile(String prefix, String fileName) {
        if ( verbose ) System.out.println(this.getClass().getSimpleName()+".loadGroupFile(group-file-prefix="+prefix +
                                          ", fileName=" +
fileName +
                                          ")");
        GroupParser parser;
        try {
            URL f = new URL(fileName);
            ANTLRInputStream fs = new ANTLRInputStream(f.openStream(), encoding);
            GroupLexer lexer = new GroupLexer(fs);
            fs.name = fileName;
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            parser = new GroupParser(tokens);
            parser.group(this, prefix);
        }
        catch (Exception e) {
            errMgr.IOError(null, ErrorType.CANT_LOAD_GROUP_FILE, e, fileName);
        }
    }
 
Example #25
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Load template stream into this group. {@code unqualifiedFileName} is
 *  {@code "a.st"}. The {@code prefix} is path from group root to
 *  {@code unqualifiedFileName} like {@code "/subdir"} if file is in
 *  {@code /subdir/a.st}.
 */

public CompiledST loadTemplateFile(String prefix, String unqualifiedFileName, CharStream templateStream) {
    GroupLexer lexer = new GroupLexer(templateStream);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    GroupParser parser = new GroupParser(tokens);
    parser.group = this;
    lexer.group = this;
    try {
        parser.templateDef(prefix);
    }
    catch (RecognitionException re) {
        errMgr.groupSyntaxError(ErrorType.SYNTAX_ERROR, unqualifiedFileName, re, re.getMessage());
    }

    String templateName = Misc.getFileNameNoSuffix(unqualifiedFileName);
    if ( prefix !=null && prefix.length()>0 ) templateName = prefix+templateName;
    CompiledST impl = rawGetTemplate(templateName);
    impl.prefix = prefix;
    return impl;
}
 
Example #26
Source File: MapleCfgVisitor.java    From Gaalop with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Parses a snippet of maple code and returns a list of CFG nodes that implement the returned maple expressions.
 * 
 * @param graph The control flow graph the new nodes should be created in.
 * @param mapleCode The code returned by Maple.
 * @return A list of control flow nodes modeling the returned code.
 */
List<AssignmentNode> parseMapleCode(ControlFlowGraph graph, String mapleCode) {
	oldMinVal = new HashMap<String, String>();
	oldMaxVal = new HashMap<String, String>();

	/* fill the Maps with the min and maxvalues from the nodes */
	for (Variable v : graph.getInputVariables()) {
		if (v.getMinValue() != null)
			oldMinVal.put(v.getName(), v.getMinValue());
		if (v.getMaxValue() != null)
			oldMaxVal.put(v.getName(), v.getMaxValue());
	}

	MapleLexer lexer = new MapleLexer(new ANTLRStringStream(mapleCode));
	MapleParser parser = new MapleParser(new CommonTokenStream(lexer));
	try {
		MapleParser.program_return result = parser.program();
		MapleTransformer transformer = new MapleTransformer(new CommonTreeNodeStream(result.getTree()));
		return transformer.script(graph, oldMinVal, oldMaxVal);
	} catch (RecognitionException e) {
		throw new RuntimeException(e);
	}
}
 
Example #27
Source File: STGroupString.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void load() {
    if ( alreadyLoaded ) return;
    alreadyLoaded = true;
    GroupParser parser;
    try {
        ANTLRStringStream fs = new ANTLRStringStream(text);
        fs.name = sourceName;
        GroupLexer lexer = new GroupLexer(fs);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        parser = new GroupParser(tokens);
        // no prefix since this group file is the entire group, nothing lives
        // beneath it.
        parser.group(this, "/");
    }
    catch (Exception e) {
        errMgr.IOError(null, ErrorType.CANT_LOAD_GROUP_FILE, e, "<string>");
    }
}
 
Example #28
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Load a group file with full path {@code fileName}; it's relative to root by {@code prefix}. */

    public void loadGroupFile(String prefix, String fileName) {
        if ( verbose ) System.out.println(this.getClass().getSimpleName()+".loadGroupFile(group-file-prefix="+prefix +
                                          ", fileName=" +
fileName +
                                          ")");
        GroupParser parser;
        try {
            URL f = new URL(fileName);
            ANTLRInputStream fs = new ANTLRInputStream(f.openStream(), encoding);
            GroupLexer lexer = new GroupLexer(fs);
            fs.name = fileName;
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            parser = new GroupParser(tokens);
            parser.group(this, prefix);
        }
        catch (Exception e) {
            errMgr.IOError(null, ErrorType.CANT_LOAD_GROUP_FILE, e, fileName);
        }
    }
 
Example #29
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Load template stream into this group. {@code unqualifiedFileName} is
 *  {@code "a.st"}. The {@code prefix} is path from group root to
 *  {@code unqualifiedFileName} like {@code "/subdir"} if file is in
 *  {@code /subdir/a.st}.
 */

public CompiledST loadTemplateFile(String prefix, String unqualifiedFileName, CharStream templateStream) {
    GroupLexer lexer = new GroupLexer(templateStream);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    GroupParser parser = new GroupParser(tokens);
    parser.group = this;
    lexer.group = this;
    try {
        parser.templateDef(prefix);
    }
    catch (RecognitionException re) {
        errMgr.groupSyntaxError(ErrorType.SYNTAX_ERROR, unqualifiedFileName, re, re.getMessage());
    }

    String templateName = Misc.getFileNameNoSuffix(unqualifiedFileName);
    if ( prefix !=null && prefix.length()>0 ) templateName = prefix+templateName;
    CompiledST impl = rawGetTemplate(templateName);
    impl.prefix = prefix;
    return impl;
}
 
Example #30
Source File: STGroupString.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void load() {
    if ( alreadyLoaded ) return;
    alreadyLoaded = true;
    GroupParser parser;
    try {
        ANTLRStringStream fs = new ANTLRStringStream(text);
        fs.name = sourceName;
        GroupLexer lexer = new GroupLexer(fs);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        parser = new GroupParser(tokens);
        // no prefix since this group file is the entire group, nothing lives
        // beneath it.
        parser.group(this, "/");
    }
    catch (Exception e) {
        errMgr.IOError(null, ErrorType.CANT_LOAD_GROUP_FILE, e, "<string>");
    }
}