@Test public void multipleLabels() { assertEquals(Arrays.asList( new NumberElement("10, ", CSLLabel.CHAPTER, false), new NumberElement("4", CSLLabel.SECTION, false)), NumberParser.parse(" ch. 10, sec. 4 ")); assertEquals(Arrays.asList( new NumberElement("10, ", CSLLabel.CHAPTER, false), new NumberElement("4", CSLLabel.SECTION, false)), NumberParser.parse("ch. 10 ,sec. 4")); assertEquals(Arrays.asList( new NumberElement("2\u20133, ", CSLLabel.CHAPTER, true), new NumberElement("4\u20135", CSLLabel.PAGE, true)), NumberParser.parse("ch. 2-3, p. 4-5")); assertEquals(Arrays.asList( new NumberElement("2, 3, ", CSLLabel.CHAPTER, true), new NumberElement("4, 5", CSLLabel.PAGE, true)), NumberParser.parse("ch. 2, 3, p. 4, 5")); assertEquals(Arrays.asList( new NumberElement("2, 3, ", CSLLabel.CHAPTER, true), new NumberElement("4, 5", CSLLabel.PAGE, true)), NumberParser.parse("ch. 2,3, p. 4,5")); assertEquals(Arrays.asList( new NumberElement("2, 3; ", CSLLabel.CHAPTER, true), new NumberElement("4, 5", CSLLabel.PAGE, true)), NumberParser.parse("ch. 2, 3; p. 4, 5")); assertEquals(Arrays.asList( new NumberElement("foo. bar, "), new NumberElement("2\u20133", CSLLabel.SECTION, true)), NumberParser.parse("foo. bar, sec. 2-3")); assertEquals(Arrays.asList( new NumberElement("cp. foo, "), new NumberElement("2\u20133", CSLLabel.SECTION, true)), NumberParser.parse("cp. foo, sec. 2-3")); assertEquals(Arrays.asList( new NumberElement("1, 2, and 3, ", CSLLabel.CHAPTER, true), new NumberElement("foo", CSLLabel.SECTION, false)), NumberParser.parse("ch. 1,2, and 3, sec. foo")); assertEquals(Arrays.asList( new NumberElement("1, 2, and 3, ", CSLLabel.CHAPTER, true), new NumberElement("foo bar", CSLLabel.SECTION, false)), NumberParser.parse("ch. 1,2, and 3, sec. foo bar")); assertEquals(Arrays.asList( new NumberElement("foo bar zoo, ", CSLLabel.SECTION, false), new NumberElement("dummy dummy", CSLLabel.CHAPTER, false)), NumberParser.parse("sec. foo bar zoo , ch. dummy dummy")); assertEquals(Arrays.asList( new NumberElement("5 foo, test sec. 1-5, ", CSLLabel.CHAPTER, false), new NumberElement("5, 3, 6", CSLLabel.PAGE, true)), NumberParser.parse("ch. 5 foo, test sec. 1-5, p. 5, 3, 6")); }
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);  }