@Test public void testComposite() throws Exception { { Parser<Object> p = new Parser<>("hello%(%child)"); Node t = p.parse(); Node witness = new Node(Node.LITERAL, "hello"); CompositeNode composite = new CompositeNode(BARE); Node child = new SimpleKeywordNode("child"); composite.setChildNode(child); witness.next = composite; assertEquals(witness, t); } { Parser<Object> p = new Parser<>("hello%(%child )"); Node t = p.parse(); Node witness = new Node(Node.LITERAL, "hello"); CompositeNode composite = new CompositeNode(BARE); Node child = new SimpleKeywordNode("child"); composite.setChildNode(child); witness.next = composite; child.next = new Node(Node.LITERAL, " "); assertEquals(witness, t); } { Parser<Object> p = new Parser<>("hello%(%child %h)"); Node t = p.parse(); Node witness = new Node(Node.LITERAL, "hello"); CompositeNode composite = new CompositeNode(BARE); Node child = new SimpleKeywordNode("child"); composite.setChildNode(child); child.next = new Node(Node.LITERAL, " "); child.next.next = new SimpleKeywordNode("h"); witness.next = composite; assertEquals(witness, t); } { Parser<Object> p = new Parser<>("hello%(%child %h) %m"); Node t = p.parse(); Node witness = new Node(Node.LITERAL, "hello"); CompositeNode composite = new CompositeNode(BARE); Node child = new SimpleKeywordNode("child"); composite.setChildNode(child); child.next = new Node(Node.LITERAL, " "); child.next.next = new SimpleKeywordNode("h"); witness.next = composite; composite.next = new Node(Node.LITERAL, " "); composite.next.next = new SimpleKeywordNode("m"); assertEquals(witness, t); } { Parser<Object> p = new Parser<>("hello%( %child \\(%h\\) ) %m"); Node t = p.parse(); Node witness = new Node(Node.LITERAL, "hello"); CompositeNode composite = new CompositeNode(BARE); Node child = new Node(Node.LITERAL, " "); composite.setChildNode(child); Node c = child; c = c.next = new SimpleKeywordNode("child"); c = c.next = new Node(Node.LITERAL, " ("); c = c.next = new SimpleKeywordNode("h"); c = c.next = new Node(Node.LITERAL, ") "); witness.next = composite; composite.next = new Node(Node.LITERAL, " "); composite.next.next = new SimpleKeywordNode("m"); assertEquals(witness, t); } }
FormattingNode COMPOSITE(String keyword) throws ScanException { CompositeNode compositeNode = new CompositeNode(keyword); Node childNode = E(); compositeNode.setChildNode(childNode); Token t = getNextToken(); if (t == null || t.getType() != Token.RIGHT_PARENTHESIS) { String msg = "Expecting RIGHT_PARENTHESIS token but got " + t; addError(msg); addError("See also " + MISSING_RIGHT_PARENTHESIS); throw new ScanException(msg); } Token ot = getCurentToken(); if (ot != null && ot.getType() == Token.OPTION) { List<String> optionList = ot.getOptionsList(); compositeNode.setOptions(optionList); advanceTokenPointer(); } return compositeNode; }
Parser extends ContextAwareBase { FormattingNode COMPOSITE(String keyword) throws ScanException { CompositeNode compositeNode = new CompositeNode(keyword); Node childNode = E(); compositeNode.setChildNode(childNode); Token t = getNextToken(); if (t == null || t.getType() != Token.RIGHT_PARENTHESIS) { String msg = "Expecting RIGHT_PARENTHESIS token but got " + t; addError(msg); addError("See also " + MISSING_RIGHT_PARENTHESIS); throw new ScanException(msg); } Token ot = getCurentToken(); if (ot != null && ot.getType() == Token.OPTION) { List<String> optionList = ot.getOptionsList(); compositeNode.setOptions(optionList); advanceTokenPointer(); } return compositeNode; } }
Parser extends ContextAwareBase { FormattingNode COMPOSITE(String keyword) throws ScanException { CompositeNode compositeNode = new CompositeNode(keyword); Node childNode = E(); compositeNode.setChildNode(childNode); Token t = getNextToken(); if (t == null || t.getType() != Token.RIGHT_PARENTHESIS) { String msg = "Expecting RIGHT_PARENTHESIS token but got " + t; addError(msg); addError("See also " + MISSING_RIGHT_PARENTHESIS); throw new ScanException(msg); } Token ot = getCurentToken(); if (ot != null && ot.getType() == Token.OPTION) { List<String> optionList = ot.getOptionsList(); compositeNode.setOptions(optionList); advanceTokenPointer(); } return compositeNode; } Parser(TokenStream ts);  Parser(String pattern);  Parser(String pattern, IEscapeUtil escapeUtil); }
Parser extends ContextAwareBase { FormattingNode COMPOSITE(String keyword) throws ScanException { CompositeNode compositeNode = new CompositeNode(keyword); Node childNode = E(); compositeNode.setChildNode(childNode); Token t = getNextToken(); if (t == null || t.getType() != Token.RIGHT_PARENTHESIS) { String msg = "Expecting RIGHT_PARENTHESIS token but got " + t; addError(msg); addError("See also " + MISSING_RIGHT_PARENTHESIS); throw new ScanException(msg); } Token ot = getCurentToken(); if (ot != null && ot.getType() == Token.OPTION) { List<String> optionList = ot.getOptionsList(); compositeNode.setOptions(optionList); advanceTokenPointer(); } return compositeNode; } Parser(TokenStream ts);  Parser(String pattern);  Parser(String pattern, IEscapeUtil escapeUtil); Converter<E> compile(final Node top, Map<String, String> converterMap); Node parse(); }
Parser extends ContextAwareBase { FormattingNode COMPOSITE(String keyword) throws ScanException { CompositeNode compositeNode = new CompositeNode(keyword); Node childNode = E(); compositeNode.setChildNode(childNode); Token t = getNextToken(); if (t == null || t.getType() != Token.RIGHT_PARENTHESIS) { String msg = "Expecting RIGHT_PARENTHESIS token but got " + t; addError(msg); addError("See also " + MISSING_RIGHT_PARENTHESIS); throw new ScanException(msg); } Token ot = getCurentToken(); if (ot != null && ot.getType() == Token.OPTION) { List<String> optionList = ot.getOptionsList(); compositeNode.setOptions(optionList); advanceTokenPointer(); } return compositeNode; } Parser(TokenStream ts);  Parser(String pattern);  Parser(String pattern, IEscapeUtil escapeUtil); Converter<E> compile(final Node top, Map<String, String> converterMap); Node parse(); final static String MISSING_RIGHT_PARENTHESIS; final static Map<String, String> DEFAULT_COMPOSITE_CONVERTER_MAP; final static String REPLACE_CONVERTER_WORD; }