@Test public void merge() { assertEquals(Collections.singletonList( new NumberElement("10, 40", CSLLabel.CHAPTER, true)), NumberParser.parse("ch. 10, ch. 40")); assertEquals(Collections.singletonList( new NumberElement("10, 40", CSLLabel.SECTION, true)), NumberParser.parse("sec. 10, sec. 40")); assertEquals(Collections.singletonList( new NumberElement("10\u201312, 40", CSLLabel.SECTION, true)), NumberParser.parse("sec. 10-12, sec. 40")); assertEquals(Arrays.asList( new NumberElement("10, ", CSLLabel.CHAPTER, false), new NumberElement("40", CSLLabel.SECTION, false)), NumberParser.parse("ch. 10, sec. 40")); assertEquals(Arrays.asList( new NumberElement("10, 40, ", CSLLabel.CHAPTER, true), new NumberElement("2", CSLLabel.SECTION, false)), NumberParser.parse("ch. 10, ch. 40, sec. 2")); assertEquals(Arrays.asList( new NumberElement("10, ", CSLLabel.CHAPTER, false), new NumberElement("40, ", CSLLabel.SECTION, false), new NumberElement("2", CSLLabel.CHAPTER, false)), NumberParser.parse("ch. 10, sec. 40, ch. 2")); }
public static List<NumberElement> parse(String number) { CharStream cs = CharStreams.fromString(number); InternalNumberLexer lexer = new InternalNumberLexer(cs); lexer.removeErrorListeners(); CommonTokenStream tokens = new CommonTokenStream(lexer); InternalNumberParser parser = new InternalNumberParser(tokens); parser.removeErrorListeners(); InternalNumberParser.NumbersContext ctx = parser.numbers(); if (ctx.exception != null || parser.getNumberOfSyntaxErrors() > 0 || ctx.elements.isEmpty()) { return Collections.singletonList(new NumberElement(number)); } return ctx.elements; }
NumberParser { public static List<NumberElement> parse(String number) { CharStream cs = CharStreams.fromString(number); InternalNumberLexer lexer = new InternalNumberLexer(cs); lexer.removeErrorListeners(); CommonTokenStream tokens = new CommonTokenStream(lexer); InternalNumberParser parser = new InternalNumberParser(tokens); parser.removeErrorListeners(); InternalNumberParser.NumbersContext ctx = parser.numbers(); if (ctx.exception != null || parser.getNumberOfSyntaxErrors() > 0 || ctx.elements.isEmpty()) { return Collections.singletonList(new NumberElement(number)); } return ctx.elements; } }
NumberParser { public static List<NumberElement> parse(String number) { CharStream cs = CharStreams.fromString(number); InternalNumberLexer lexer = new InternalNumberLexer(cs); lexer.removeErrorListeners(); CommonTokenStream tokens = new CommonTokenStream(lexer); InternalNumberParser parser = new InternalNumberParser(tokens); parser.removeErrorListeners(); InternalNumberParser.NumbersContext ctx = parser.numbers(); if (ctx.exception != null || parser.getNumberOfSyntaxErrors() > 0 || ctx.elements.isEmpty()) { return Collections.singletonList(new NumberElement(number)); } return ctx.elements; }  }
NumberParser { public static List<NumberElement> parse(String number) { CharStream cs = CharStreams.fromString(number); InternalNumberLexer lexer = new InternalNumberLexer(cs); lexer.removeErrorListeners(); CommonTokenStream tokens = new CommonTokenStream(lexer); InternalNumberParser parser = new InternalNumberParser(tokens); parser.removeErrorListeners(); InternalNumberParser.NumbersContext ctx = parser.numbers(); if (ctx.exception != null || parser.getNumberOfSyntaxErrors() > 0 || ctx.elements.isEmpty()) { return Collections.singletonList(new NumberElement(number)); } return ctx.elements; }  static List<NumberElement> parse(String number); }
NumberParser { public static List<NumberElement> parse(String number) { CharStream cs = CharStreams.fromString(number); InternalNumberLexer lexer = new InternalNumberLexer(cs); lexer.removeErrorListeners(); CommonTokenStream tokens = new CommonTokenStream(lexer); InternalNumberParser parser = new InternalNumberParser(tokens); parser.removeErrorListeners(); InternalNumberParser.NumbersContext ctx = parser.numbers(); if (ctx.exception != null || parser.getNumberOfSyntaxErrors() > 0 || ctx.elements.isEmpty()) { return Collections.singletonList(new NumberElement(number)); } return ctx.elements; }  static List<NumberElement> parse(String number);  }