Skip to content

Commit

Permalink
added convienience method to get a parser instance from Occi.g
Browse files Browse the repository at this point in the history
  • Loading branch information
dizz committed Mar 11, 2011
1 parent f1950dd commit 1fac327
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions occi-antlr/Occi.g
Expand Up @@ -35,6 +35,19 @@ options {
static String occi_core_actionterm = "occi.core.actionterm";
static String occi_core_self = "occi.core.self";
static String occi_core_category = "occi.core.category";

public static OcciParser getParser(String occiHeader) throws Exception {

CharStream stream = new ANTLRStringStream(occiHeader);
OcciLexer lexer = new OcciLexer(stream);
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
OcciParser parser = new OcciParser(tokenStream);

if(parser.getNumberOfSyntaxErrors() > 0)
throw new Exception("Errors (" + parser.getNumberOfSyntaxErrors() + ") in parsing the input string");

return parser;
}
}

headers returns [HashMap values] :
Expand Down

0 comments on commit 1fac327

Please sign in to comment.