@Test public void label() { assertEquals(Collections.singletonList( new NumberElement("4", CSLLabel.PAGE, false)), NumberParser.parse("p. 4")); assertEquals(Collections.singletonList( new NumberElement("10", CSLLabel.CHAPTER, false)), NumberParser.parse("ch. 10")); assertEquals(Collections.singletonList( new NumberElement("ch 10")), NumberParser.parse("ch 10")); assertEquals(Collections.singletonList( new NumberElement("cha 10")), NumberParser.parse("cha 10")); assertEquals(Collections.singletonList( new NumberElement("10", CSLLabel.CHAPTER, false)), NumberParser.parse("chap. 10")); assertEquals(Collections.singletonList( new NumberElement("10", CSLLabel.SECTION, false)), NumberParser.parse("sec. 10")); assertEquals(Collections.singletonList( new NumberElement("1.5", CSLLabel.SECTION, false)), NumberParser.parse("sec. 1.5")); assertEquals(Collections.singletonList( new NumberElement("10", CSLLabel.CHAPTER, false)), NumberParser.parse("chapter 10")); assertEquals(Collections.singletonList( new NumberElement("10", CSLLabel.SECTION, false)), NumberParser.parse("section 10")); assertEquals(Collections.singletonList( new NumberElement("10a-b", CSLLabel.SECTION, false)), NumberParser.parse("sec. 10a-b")); assertEquals(Collections.singletonList( new NumberElement("10a:b", CSLLabel.SECTION, false)), NumberParser.parse("sec. 10a:b")); assertEquals(Collections.singletonList( new NumberElement("1.a", CSLLabel.SECTION, false)), NumberParser.parse("sec. 1.a")); assertEquals(Collections.singletonList( new NumberElement("I.a", CSLLabel.SECTION, false)), NumberParser.parse("sec. I.a")); assertEquals(Collections.singletonList( new NumberElement("1.I", CSLLabel.SECTION, false)), NumberParser.parse("sec. 1.I")); assertEquals(Collections.singletonList( new NumberElement("I", CSLLabel.SECTION, false)), NumberParser.parse("sec. I")); assertEquals(Collections.singletonList( new NumberElement("IV", CSLLabel.SECTION, false)), NumberParser.parse("sec. IV")); assertEquals(Collections.singletonList( new NumberElement("foo. 4")), NumberParser.parse("foo. 4")); assertEquals(Collections.singletonList( new NumberElement("foo", CSLLabel.CHAPTER, false)), NumberParser.parse("ch. foo")); }
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);  }