@Test public void labelPlural() { assertEquals(Collections.singletonList( new NumberElement("10\u201312", CSLLabel.CHAPTER, true)), NumberParser.parse("chaps. 10-12")); assertEquals(Collections.singletonList( new NumberElement("10\u201312", CSLLabel.SECTION, true)), NumberParser.parse("secs. 10-12")); assertEquals(Collections.singletonList( new NumberElement("10\u201312", CSLLabel.CHAPTER, true)), NumberParser.parse("chapters 10-12")); assertEquals(Collections.singletonList( new NumberElement("10\u201312", CSLLabel.SECTION, true)), NumberParser.parse("sections 10-12")); assertEquals(Collections.singletonList( new NumberElement("10, 4", CSLLabel.CHAPTER, true)), NumberParser.parse("ch. 10, 4")); assertEquals(Collections.singletonList( new NumberElement("10\u201312", null, true)), NumberParser.parse("10-12")); assertEquals(Collections.singletonList( new NumberElement("10, 12", null, true)), NumberParser.parse("10,12")); assertEquals(Collections.singletonList( new NumberElement("10, 12", null, true)), NumberParser.parse("10,12")); assertEquals(Collections.singletonList( new NumberElement("10 & 12", null, true)), NumberParser.parse("10 & 12")); assertEquals(Collections.singletonList( new NumberElement("10 & 12", null, true)), NumberParser.parse("10&12")); assertEquals(Collections.singletonList( new NumberElement("10 and 12", null, true)), NumberParser.parse("10 and 12")); assertEquals(Collections.singletonList( new NumberElement("2\u20133", CSLLabel.CHAPTER, true)), NumberParser.parse("ch. 2-3")); assertEquals(Collections.singletonList( new NumberElement("1, 2, 3", CSLLabel.CHAPTER, true)), NumberParser.parse("ch. 1,2,3")); assertEquals(Collections.singletonList( new NumberElement("1, 2, and 3", CSLLabel.CHAPTER, true)), NumberParser.parse("ch. 1,2, and 3")); assertEquals(Collections.singletonList( new NumberElement("1, 2, and 3", CSLLabel.CHAPTER, true)), NumberParser.parse("ch. 1,2, and 3,")); }
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);  }