org.ic4j.candid.parser.tree.CandidParser.jj Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ic4j-candid Show documentation
Show all versions of ic4j-candid Show documentation
Java library to serialize and deserialize Java objects to the Internet Computer Candid types.
/*@bgen(jjtree) Generated By:JJTree: Do not edit this line. CandidParser.jj */
/*@egen*//**
* JJTree template file created by SF JavaCC plugin 1.5.28+ wizard for JavaCC 1.5.0+
*/
options
{
static = false;
}
PARSER_BEGIN(CandidParser)
package org.ic4j.candid.parser.tree;
public class CandidParser/*@bgen(jjtree)*/implements CandidParserTreeConstants/*@egen*/
{/*@bgen(jjtree)*/
protected JJTCandidParserState jjtree = new JJTCandidParserState();
/*@egen*/
public static void main(String args [])
{
CandidParser parser;
if(args.length == 0){
System.out.println("Reading from standard input...");
System.out.print("Enter an expression like \"1+(2+3)*var;\" :");
parser = new CandidParser(System.in);
}
else if(args.length == 1){
System.out.println("Reading from file " + args[0] + " . . ." );
try {
parser = new CandidParser(new java.io.FileInputStream(args[0]));
}
catch(java.io.FileNotFoundException e){
System.out.println("File " + args[0] + " not found.");
return ;
}
}
else
return;
try
{
SimpleNode n = parser.Start();
n.dump("candid");
System.out.println("Done");
System.out.println(n.jjtGetNumChildren());
for(int i = 0; i < n.jjtGetNumChildren(); i++)
{
System.out.println(n.jjtGetChild(i).getClass());
}
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
}
PARSER_END(CandidParser)
SKIP :
{
" "
| "\""
| "\t"
| "\n"
| "\r"
| < "//" (~[ "\n", "\r" ])*
(
"\n"
| "\r"
| "\r\n"
) >
| < "/*" (~[ "*" ])* "*"
(
~[ "/" ] (~[ "*" ])* "*"
)*
"/" >
}
TOKEN : {
|
|
|
|
< FUNC: "func">|
< BLOB: "blob">|
< BOOL: "bool">|
< NULL: "null">|
< RESERVED: "reserved">|
< EMPTY: "empty">|
< RECORD: "record">|
< VARIANT: "variant">|
< PRINCIPAL: "principal">|
< OPT: "opt">|
< VEC: "vec">|
< TEXT: "text">|
< NAT: "nat">|
< NAT8: "nat8">|
< NAT16: "nat16">|
< NAT32: "nat32">|
< NAT64: "nat64"> |
< INT: "int">|
< INT8: "int8">|
< INT16: "int16">|
< INT32: "int32">|
< INT64: "int64">|
< FLOAT32: "float32">|
< FLOAT64: "float64">
}
TOKEN : /* IDENTIFIERS */
{
< IDENTIFIER :
("\"")?
< LETTER >
(
< LETTER >
| < DIGIT >
)* >
| < #LETTER : [ "_", "a"-"z", "A"-"Z" ] >
| < #DIGIT : [ "0"-"9" ]
("\"")?
>
}
SimpleNode Start() :
{/*@bgen(jjtree) Start */
SimpleNode jjtn000 = new SimpleNode(JJTSTART);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) Start */
try {
/*@egen*/
(TypeExpression() | ServiceExpression() )+/*@bgen(jjtree)*/
{
jjtree.closeNodeScope(jjtn000, true);
jjtc000 = false;
}
/*@egen*/
{
return jjtn000;
}/*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
}
}
/*@egen*/
}
void TypeExpression() :
{/*@bgen(jjtree) TypeExpression */
SimpleNode jjtn000 = new SimpleNode(JJTTYPEEXPRESSION);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) TypeExpression */
try {
/*@egen*/
< TYPE > Identifier() "=" (SimpleType() | FuncType() | OptType() | VecType() | RecordType() | VariantType() | Identifier()) ";"/*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
}
}
/*@egen*/
}
void SimpleType() :
{/*@bgen(jjtree) SimpleType */
SimpleNode jjtn000 = new SimpleNode(JJTSIMPLETYPE);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
/*@egen*/
Token t;
}
{/*@bgen(jjtree) SimpleType */
try {
/*@egen*/
(
t=< BLOB >|
t=< BOOL >|
t=< NULL >|
t=< EMPTY >|
t=< PRINCIPAL>|
t=< TEXT>|
t=< NAT>|
t=< NAT8>|
t=< NAT16>|
t=< NAT32>|
t=< NAT64>|
t=< INT>|
t=< INT8>|
t=< INT16>|
t=< INT32>|
t=< INT64>|
t=< FLOAT32>|
t=< FLOAT64>
)/*@bgen(jjtree)*/
{
jjtree.closeNodeScope(jjtn000, true);
jjtc000 = false;
}
/*@egen*/
{
jjtn000.jjtSetValue(t.image);
}/*@bgen(jjtree)*/
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
}
}
/*@egen*/
}
void OptType() :
{/*@bgen(jjtree) OptType */
SimpleNode jjtn000 = new SimpleNode(JJTOPTTYPE);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) OptType */
try {
/*@egen*/
< OPT> (SimpleType() | OptType() | VecType() | FuncType() | ServiceType() | RecordType() | VariantType() | Identifier())/*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
}
}
/*@egen*/
}
void VecType() :
{/*@bgen(jjtree) VecType */
SimpleNode jjtn000 = new SimpleNode(JJTVECTYPE);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) VecType */
try {
/*@egen*/
< VEC> (SimpleType() | OptType() | VecType() | FuncType() | ServiceType() | RecordType() | VariantType() | Identifier())/*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
}
}
/*@egen*/
}
void FuncType() :
{/*@bgen(jjtree) FuncType */
SimpleNode jjtn000 = new SimpleNode(JJTFUNCTYPE);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
/*@egen*/
}
{/*@bgen(jjtree) FuncType */
try {
/*@egen*/
< FUNC> Arguments() "->" Arguments() (Query() | Oneway())?/*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
}
}
/*@egen*/
}
void ServiceType() :
{/*@bgen(jjtree) ServiceType */
SimpleNode jjtn000 = new SimpleNode(JJTSERVICETYPE);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
/*@egen*/
}
{/*@bgen(jjtree) ServiceType */
try {
/*@egen*/
< SERVICE> "{" (FuncType() (";")?)* "}"/*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
}
}
/*@egen*/
}
void Query() :
{/*@bgen(jjtree) Query */
SimpleNode jjtn000 = new SimpleNode(JJTQUERY);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
/*@egen*/
}
{/*@bgen(jjtree) Query */
try {
/*@egen*/
< QUERY >/*@bgen(jjtree)*/
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
}
}
/*@egen*/
}
void Oneway() :
{/*@bgen(jjtree) Oneway */
SimpleNode jjtn000 = new SimpleNode(JJTONEWAY);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
/*@egen*/
}
{/*@bgen(jjtree) Oneway */
try {
/*@egen*/
< ONEWAY >/*@bgen(jjtree)*/
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
}
}
/*@egen*/
}
void RecordType() :
{/*@bgen(jjtree) RecordType */
SimpleNode jjtn000 = new SimpleNode(JJTRECORDTYPE);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) RecordType */
try {
/*@egen*/
< RECORD> "{" ((RecordSubType()) (";")?)* "}"/*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
}
}
/*@egen*/
}
void VariantType() :
{/*@bgen(jjtree) VariantType */
SimpleNode jjtn000 = new SimpleNode(JJTVARIANTTYPE);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) VariantType */
try {
/*@egen*/
< VARIANT> "{" (VariantSubType() (";")?)* "}"/*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
}
}
/*@egen*/
}
void RecordSubType() :
{/*@bgen(jjtree) RecordSubType */
SimpleNode jjtn000 = new SimpleNode(JJTRECORDSUBTYPE);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) RecordSubType */
try {
/*@egen*/
(Identifier() | SimpleType() | OptType() | VecType() | FuncType() | ServiceType() | RecordType() | VariantType()) ( ":" ( SimpleType() | OptType() | VecType() | FuncType() | ServiceType() | RecordType() | VariantType() | Identifier()))?/*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
}
}
/*@egen*/
}
void VariantSubType() :
{/*@bgen(jjtree) VariantSubType */
SimpleNode jjtn000 = new SimpleNode(JJTVARIANTSUBTYPE);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) VariantSubType */
try {
/*@egen*/
Identifier() (":" (SimpleType() | OptType() | VecType() | FuncType() | ServiceType() | RecordType() | VariantType() | Identifier()))?/*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
}
}
/*@egen*/
}
void ServiceExpression() :
{/*@bgen(jjtree) ServiceExpression */
SimpleNode jjtn000 = new SimpleNode(JJTSERVICEEXPRESSION);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) ServiceExpression */
try {
/*@egen*/
< SERVICE > ( Identifier() ":" | ":") (Arguments() "->")? "{" (Function())* "}" (";")?/*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
}
}
/*@egen*/
}
void Function() :
{/*@bgen(jjtree) Function */
SimpleNode jjtn000 = new SimpleNode(JJTFUNCTION);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) Function */
try {
/*@egen*/
Identifier() ":" Arguments() "->" Arguments() (Query() | Oneway())? (";")?/*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
}
}
/*@egen*/
}
void Arguments() :
{/*@bgen(jjtree) Arguments */
SimpleNode jjtn000 = new SimpleNode(JJTARGUMENTS);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) Arguments */
try {
/*@egen*/
"(" (Argument())* ")"/*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
}
}
/*@egen*/
}
void Argument() :
{/*@bgen(jjtree) Argument */
SimpleNode jjtn000 = new SimpleNode(JJTARGUMENT);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) Argument */
try {
/*@egen*/
(SimpleType() | OptType() | VecType() | FuncType() | RecordType() | VariantType() | Identifier()) (NamedArgument())? (",")?/*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
}
}
/*@egen*/
}
void NamedArgument() :
{/*@bgen(jjtree) NamedArgument */
SimpleNode jjtn000 = new SimpleNode(JJTNAMEDARGUMENT);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
/*@egen*/}
{/*@bgen(jjtree) NamedArgument */
try {
/*@egen*/
":" (SimpleType() | OptType() | VecType() | FuncType() | RecordType() | VariantType() | Identifier())/*@bgen(jjtree)*/
} catch (Throwable jjte000) {
if (jjtc000) {
jjtree.clearNodeScope(jjtn000);
jjtc000 = false;
} else {
jjtree.popNode();
}
if (jjte000 instanceof RuntimeException) {
throw (RuntimeException)jjte000;
}
if (jjte000 instanceof ParseException) {
throw (ParseException)jjte000;
}
throw (Error)jjte000;
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
}
}
/*@egen*/
}
void Identifier() :
{/*@bgen(jjtree) Identifier */
SimpleNode jjtn000 = new SimpleNode(JJTIDENTIFIER);
boolean jjtc000 = true;
jjtree.openNodeScope(jjtn000);
/*@egen*/
Token t;
}
{/*@bgen(jjtree) Identifier */
try {
/*@egen*/
t=/*@bgen(jjtree)*/
{
jjtree.closeNodeScope(jjtn000, true);
jjtc000 = false;
}
/*@egen*/
{
jjtn000.jjtSetValue(t.image);
}/*@bgen(jjtree)*/
} finally {
if (jjtc000) {
jjtree.closeNodeScope(jjtn000, true);
}
}
/*@egen*/
}