@Test public void testParse_number() throws IOException { copyResourceTo("/parser/calculator/number.thrift", tmp.getRoot()); File number = new File(tmp.getRoot(), "number.thrift"); ThriftProgramParser parser = new ThriftProgramParser(); ProgramType program = parser.parse(new FileInputStream(number), number, new TreeSet<>()); assertThat(debugString(program), is(is( "{\n" + " program_name = \"number\"\n" + " namespaces = {\n" + " \"java\": \"net.morimekta.test.number\"\n" + " }\n" + " decl = [\n" + " {\n" + " decl_typedef = {\n" + " type = \"double\"\n" + " name = \"real\"\n" + " start_pos = {\n" + " line_no = 4\n" + " line_pos = 1\n" + " }\n" + " end_pos = {\n" + " line_no = 4\n" + " line_pos = 20\n" + " }\n" + " }\n" + " },\n" + " {\n" + " decl_message = {\n" + " name = \"Imaginary\"\n" + " fields = [\n" + " {\n" + " id = 1\n" + " requirement = REQUIRED\n" + " type = \"real\"\n" + " name = \"v\"\n" + " start_pos = {\n" + " line_no = 7\n" + " line_pos = 5\n" + " }\n" + " end_pos = {\n" + " line_no = 7\n" + " line_pos = 23\n" + " }\n" + " },\n" + " {\n" + " id = 2\n" + " type = \"double\"\n" + " name = \"i\"\n" + " default_value = \"0.0\"\n" + " value_start_pos = {\n" + " line_no = 8\n" + " line_pos = 19\n" + " }\n" + " start_pos = {\n" + " line_no = 8\n" + " line_pos = 5\n" + " }\n" + " end_pos = {\n" + " line_no = 8\n" + " line_pos = 22\n" + " }\n" + " }\n" + " ]\n" + " annotations = {\n" + " \"compact\": \"true\"\n" + " }\n" + " start_pos = {\n" + " line_no = 6\n" + " line_pos = 1\n" + " }\n" + " end_pos = {\n" + " line_no = 9\n" + " line_pos = 21\n" + " }\n" + " }\n" + " },\n" + " {\n" + " decl_typedef = {\n" + " type = \"Imaginary\"\n" + " name = \"I\"\n" + " start_pos = {\n" + " line_no = 11\n" + " line_pos = 1\n" + " }\n" + " end_pos = {\n" + " line_no = 11\n" + " line_pos = 20\n" + " }\n" + " }\n" + " },\n" + " {\n" + " decl_const = {\n" + " type = \"Imaginary\"\n" + " name = \"kSqrtMinusOne\"\n" + " value = \"{\\n \\\"v\\\": 0.0,\\n \\\"i\\\": -1.0\\n}\"\n" + " value_start_pos = {\n" + " line_no = 13\n" + " line_pos = 33\n" + " }\n" + " start_pos = {\n" + " line_no = 13\n" + " line_pos = 1\n" + " }\n" + " end_pos = {\n" + " line_no = 16\n" + " line_pos = 2\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}"))); }
@Override public ProgramType parse(InputStream in, File file, Collection<File> includeDirs) throws IOException { try { return parseInternal(in, file, includeDirs); } catch (TokenizerException e) { if (e.getFile() == null) { e.setFile(file.getName()); } throw e; } }
ThriftProgramParser implements ProgramParser { @Override public ProgramType parse(InputStream in, File file, Collection<File> includeDirs) throws IOException { try { return parseInternal(in, file, includeDirs); } catch (TokenizerException e) { if (e.getFile() == null) { e.setFile(file.getName()); } throw e; } } }
ThriftProgramParser implements ProgramParser { @Override public ProgramType parse(InputStream in, File file, Collection<File> includeDirs) throws IOException { try { return parseInternal(in, file, includeDirs); } catch (TokenizerException e) { if (e.getFile() == null) { e.setFile(file.getName()); } throw e; } } ThriftProgramParser();  ThriftProgramParser(boolean requireFieldId,
                               boolean requireEnumValue);  ThriftProgramParser(boolean requireFieldId,
                               boolean requireEnumValue,
                               boolean allowLanguageReservedNames); }
ThriftProgramParser implements ProgramParser { @Override public ProgramType parse(InputStream in, File file, Collection<File> includeDirs) throws IOException { try { return parseInternal(in, file, includeDirs); } catch (TokenizerException e) { if (e.getFile() == null) { e.setFile(file.getName()); } throw e; } } ThriftProgramParser();  ThriftProgramParser(boolean requireFieldId,
                               boolean requireEnumValue);  ThriftProgramParser(boolean requireFieldId,
                               boolean requireEnumValue,
                               boolean allowLanguageReservedNames); @Override ProgramType parse(InputStream in, File file, Collection<File> includeDirs); }
ThriftProgramParser implements ProgramParser { @Override public ProgramType parse(InputStream in, File file, Collection<File> includeDirs) throws IOException { try { return parseInternal(in, file, includeDirs); } catch (TokenizerException e) { if (e.getFile() == null) { e.setFile(file.getName()); } throw e; } } ThriftProgramParser();  ThriftProgramParser(boolean requireFieldId,
                               boolean requireEnumValue);  ThriftProgramParser(boolean requireFieldId,
                               boolean requireEnumValue,
                               boolean allowLanguageReservedNames); @Override ProgramType parse(InputStream in, File file, Collection<File> includeDirs); static final Pattern VALID_NAMESPACE; static final Pattern VALID_SDI_NAMESPACE; }