final public MessageDescriptor ExtendDescriptor(ProtoDescriptor proto, MessageDescriptor parent) throws ParseException { String name; LinkedHashMap<String, FieldDescriptor> fields = new LinkedHashMap<String,FieldDescriptor>(); MessageDescriptor rc = new MessageDescriptor(proto, parent); FieldDescriptor fieldD; jj_consume_token(EXTEND); name = ID(); jj_consume_token(LBRACE); label_6: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case REQURIED: case OPTIONAL: case REPEATED: ; break; default: jj_la1[17] = jj_gen; break label_6; } fieldD = FieldDescriptor(rc); fields.put(fieldD.getName(), fieldD); } jj_consume_token(RBRACE); rc.setName(name); rc.setFields(fields); {if (true) return rc;} throw new Error("Missing return statement in function"); }
/** * Parses something like: * optional string foo = 1; */ final public EnumFieldDescriptor EnumFieldDescriptor(EnumDescriptor parent) throws ParseException { String name; int value=0; name = ID(); jj_consume_token(EQUALS); value = Integer(); EnumFieldDescriptor rc = new EnumFieldDescriptor(parent); rc.setName(name); rc.setValue(value); {if (true) return rc;} throw new Error("Missing return statement in function"); }
final public ServiceDescriptor ServiceDescriptor(ProtoDescriptor proto) throws ParseException { String name; ArrayList<MethodDescriptor> methods = new ArrayList<MethodDescriptor>(); MethodDescriptor method; jj_consume_token(SERVICE); name = ID(); jj_consume_token(LBRACE); label_5: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case RPC: ; break; default: jj_la1[16] = jj_gen; break label_5; } method = MethodDescriptor(proto); jj_consume_token(SEMICOLON); methods.add(method); } jj_consume_token(RBRACE); ServiceDescriptor rc = new ServiceDescriptor(proto); rc.setName(name); rc.setMethods(methods); {if (true) return rc;} throw new Error("Missing return statement in function"); }
final public String PackageID() throws ParseException { String t; StringBuffer sb = new StringBuffer(); t = ID(); sb.append(t); label_8: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case PERIOD: ; break; default: jj_la1[24] = jj_gen; break label_8; } jj_consume_token(PERIOD); t = ID(); sb.append("."); sb.append(t); } {if (true) return sb.toString();} throw new Error("Missing return statement in function"); }
final public MethodDescriptor MethodDescriptor(ProtoDescriptor proto) throws ParseException { String name; String input; String output; jj_consume_token(RPC); name = ID(); jj_consume_token(LPAREN); input = PackageID(); jj_consume_token(RPAREN); jj_consume_token(RETURNS); jj_consume_token(LPAREN); output = PackageID(); jj_consume_token(RPAREN); MethodDescriptor rc = new MethodDescriptor(proto); rc.setName(name); rc.setParameter(input); rc.setReturns(output); {if (true) return rc;} throw new Error("Missing return statement in function"); }
final public String Value() throws ParseException { Token t; String value=null; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case STRING: value = StringLitteral(); break; case IMPORT: case MAX: case ID: value = ID(); break; case INTEGER: t = jj_consume_token(INTEGER); value = t.image; break; case FLOAT: t = jj_consume_token(FLOAT); value = t.image; break; default: jj_la1[22] = jj_gen; jj_consume_token(-1); throw new ParseException();
FieldDescriptor rc = new FieldDescriptor(parent); MessageDescriptor group = new MessageDescriptor(parent.getProtoDescriptor(), parent); rule = Rule(); if (jj_2_1(5)) { type = PackageID(); name = ID(); jj_consume_token(EQUALS); tag = Integer(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case LBRACKET: jj_consume_token(LBRACKET); optionD = OptionDescriptor(); opts.put(optionD.getName(), optionD); label_3: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case COMMA: jj_consume_token(COMMA); optionD = OptionDescriptor(); opts.put(optionD.getName(), optionD); jj_consume_token(RBRACKET); break; default: jj_consume_token(SEMICOLON); } else { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
EnumDescriptor enumD; MessageDescriptor extendD; jj_consume_token(MESSAGE); name = ID(); jj_consume_token(LBRACE); label_2: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case OPTION: case MESSAGE: switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case OPTION: jj_consume_token(OPTION); optionD = OptionDescriptor(); jj_consume_token(SEMICOLON); opts.put(optionD.getName(),optionD); break; case OPTIONAL: case REPEATED: fieldD = FieldDescriptor(rc); fields.put(fieldD.getName(), fieldD); break; case MESSAGE: messageD = MessageDescriptor(proto, rc); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case SEMICOLON: jj_consume_token(SEMICOLON);
label_1: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case PACKAGE: jj_consume_token(PACKAGE); packageName = PackageID(); jj_consume_token(SEMICOLON); break; case OPTION: jj_consume_token(OPTION); optionD = OptionDescriptor(); jj_consume_token(SEMICOLON); opts.put(optionD.getName(),optionD); break; case IMPORT: jj_consume_token(IMPORT); o = StringLitteral(); jj_consume_token(SEMICOLON); imports.add((String)o); break; case MESSAGE: messageD = MessageDescriptor(proto, null); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case SEMICOLON: jj_consume_token(SEMICOLON); break; default: break;
jj_consume_token(ENUM); name = jj_consume_token(ID); jj_consume_token(LBRACE); label_7: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case IMPORT: case PACKAGE: if (jj_2_2(2)) { jj_consume_token(OPTION); optionD = OptionDescriptor(); jj_consume_token(SEMICOLON); opts.put(optionD.getName(),optionD); } else { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case IMPORT: case PACKAGE: case MAX: case ID: enumD = EnumFieldDescriptor(rc); jj_consume_token(SEMICOLON); fields.put(enumD.getName(),enumD); break; default: jj_la1[20] = jj_gen; jj_consume_token(-1); throw new ParseException();
private void loadImports(ProtoDescriptor proto, File protoDir) { LinkedHashMap<String,ProtoDescriptor> children = new LinkedHashMap<String,ProtoDescriptor>(); for (String imp : proto.getImports()) { File file = new File(protoDir, imp); for (int i = 0; i < path.length && !file.exists(); i++) { file = new File(path[i], imp); } if ( !file.exists() ) { errors.add("Cannot load import: "+imp); } FileInputStream is=null; try { is = new FileInputStream(file); ProtoParser parser = new ProtoParser(is); ProtoDescriptor child = parser.ProtoDescriptor(); child.setName(file.getName()); loadImports(child, file.getParentFile()); children.put(imp, child); } catch (ParseException e) { errors.add("Failed to parse: "+file.getPath()+":"+e.getMessage()); } catch (FileNotFoundException e) { errors.add("Failed to open: "+file.getPath()+":"+e.getMessage()); } finally { try { is.close(); } catch (Throwable ignore){} } } proto.setImportProtoDescriptors(children); }
final public OptionDescriptor OptionDescriptor() throws ParseException { String name; String value; name = ID(); jj_consume_token(EQUALS); value = Value(); OptionDescriptor rc = new OptionDescriptor(); rc.setName(name); rc.setValue(value); {if (true) return rc;} throw new Error("Missing return statement in function"); }
final public ExtensionsDescriptor ExtensionsDescriptor(MessageDescriptor parent) throws ParseException { int first; int last; jj_consume_token(EXTENSIONS); first = Integer(); jj_consume_token(TO); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case INTEGER: last = Integer(); break; case MAX: jj_consume_token(MAX); last=536870911; break; default: jj_la1[18] = jj_gen; jj_consume_token(-1); throw new ParseException(); } ExtensionsDescriptor rc = new ExtensionsDescriptor(parent); rc.setFirst(first); rc.setLast(last); {if (true) return rc;} throw new Error("Missing return statement in function"); }
FieldDescriptor rc = new FieldDescriptor(parent); MessageDescriptor group = new MessageDescriptor(parent.getProtoDescriptor(), parent); rule = Rule(); if (jj_2_1(5)) { type = PackageID(); name = ID(); jj_consume_token(EQUALS); tag = Integer(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case LBRACKET: jj_consume_token(LBRACKET); optionD = OptionDescriptor(); opts.put(optionD.getName(), optionD); label_3: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case COMMA: jj_consume_token(COMMA); optionD = OptionDescriptor(); opts.put(optionD.getName(), optionD); jj_consume_token(RBRACKET); break; default: jj_consume_token(SEMICOLON); } else { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
EnumDescriptor enumD; MessageDescriptor extendD; jj_consume_token(MESSAGE); name = ID(); jj_consume_token(LBRACE); label_2: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case OPTION: case MESSAGE: switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case OPTION: jj_consume_token(OPTION); optionD = OptionDescriptor(); jj_consume_token(SEMICOLON); opts.put(optionD.getName(),optionD); break; case OPTIONAL: case REPEATED: fieldD = FieldDescriptor(rc); fields.put(fieldD.getName(), fieldD); break; case MESSAGE: messageD = MessageDescriptor(proto, rc); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case SEMICOLON: jj_consume_token(SEMICOLON);
label_1: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case PACKAGE: jj_consume_token(PACKAGE); packageName = PackageID(); jj_consume_token(SEMICOLON); break; case OPTION: jj_consume_token(OPTION); optionD = OptionDescriptor(); jj_consume_token(SEMICOLON); opts.put(optionD.getName(),optionD); break; case IMPORT: jj_consume_token(IMPORT); o = StringLitteral(); jj_consume_token(SEMICOLON); imports.add((String)o); break; case MESSAGE: messageD = MessageDescriptor(proto, null); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case SEMICOLON: jj_consume_token(SEMICOLON); break; default: break;
jj_consume_token(ENUM); name = jj_consume_token(ID); jj_consume_token(LBRACE); label_7: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case IMPORT: case PACKAGE: if (jj_2_2(2)) { jj_consume_token(OPTION); optionD = OptionDescriptor(); jj_consume_token(SEMICOLON); opts.put(optionD.getName(),optionD); } else { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case IMPORT: case PACKAGE: case MAX: case ID: enumD = EnumFieldDescriptor(rc); jj_consume_token(SEMICOLON); fields.put(enumD.getName(),enumD); break; default: jj_la1[20] = jj_gen; jj_consume_token(-1); throw new ParseException();
private void loadImports(ProtoDescriptor proto, File protoDir) { LinkedHashMap<String,ProtoDescriptor> children = new LinkedHashMap<String,ProtoDescriptor>(); for (String imp : proto.getImports()) { File file = new File(protoDir, imp); for (int i = 0; i < path.length && !file.exists(); i++) { file = new File(path[i], imp); } if ( !file.exists() ) { errors.add("Cannot load import: "+imp); } FileInputStream is=null; try { is = new FileInputStream(file); ProtoParser parser = new ProtoParser(is); ProtoDescriptor child = parser.ProtoDescriptor(); child.setName(file.getName()); loadImports(child, file.getParentFile()); children.put(imp, child); } catch (ParseException e) { errors.add("Failed to parse: "+file.getPath()+":"+e.getMessage()); } catch (FileNotFoundException e) { errors.add("Failed to open: "+file.getPath()+":"+e.getMessage()); } finally { try { is.close(); } catch (Throwable ignore){} } } proto.setImportProtoDescriptors(children); }
final public String Value() throws ParseException { Token t; String value=null; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case STRING: value = StringLitteral(); break; case IMPORT: case MAX: case ID: value = ID(); break; case INTEGER: t = jj_consume_token(INTEGER); value = t.image; break; case FLOAT: t = jj_consume_token(FLOAT); value = t.image; break; default: jj_la1[22] = jj_gen; jj_consume_token(-1); throw new ParseException();
final public OptionDescriptor OptionDescriptor() throws ParseException { String name; String value; name = ID(); jj_consume_token(EQUALS); value = Value(); OptionDescriptor rc = new OptionDescriptor(); rc.setName(name); rc.setValue(value); {if (true) return rc;} throw new Error("Missing return statement in function"); }