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 = (List<String>) ot.getValue(); compositeNode.setOptions(optionList); advanceTokenPointer(); } return compositeNode; }
FormattingNode COMPOSITE() throws ScanException { CompositeNode compositeNode = new CompositeNode(); Node childNode = E(); // System.out.println("Child node: " + childNode); compositeNode.setChildNode(childNode); Token t = getNextToken(); // System.out.println("Next token is" + t); if (t.getType() != Token.RIGHT_PARENTHESIS) { throw new IllegalStateException( "Expecting RIGHT_PARENTHESIS token but got " + t); } else { // System.out.println("got expected ')'"); } return compositeNode; }
@Test public void testNested() throws Exception { { Parser<Object> p = new Parser("%top %(%child%(%h))"); Node t = p.parse(); Node witness = new SimpleKeywordNode("top"); Node w = witness.next = new Node(Node.LITERAL, " "); CompositeNode composite = new CompositeNode(BARE); w = w.next = composite; Node child = new SimpleKeywordNode("child"); composite.setChildNode(child); composite = new CompositeNode(BARE); child.next = composite; composite.setChildNode(new SimpleKeywordNode("h")); assertEquals(witness, t); } }
@Test public void testCompositeFormatting() throws Exception { Parser<Object> p = new Parser("hello%5(XYZ)"); Node t = p.parse(); Node witness = new Node(Node.LITERAL, "hello"); CompositeNode composite = new CompositeNode(BARE); composite.setFormatInfo(new FormatInfo(5, Integer.MAX_VALUE)); Node child = new Node(Node.LITERAL, "XYZ"); composite.setChildNode(child); witness.next = composite; 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 = (List<String>) ot.getValue(); compositeNode.setOptions(optionList); advanceTokenPointer(); } return compositeNode; }
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 = (List<String>) ot.getValue(); compositeNode.setOptions(optionList); advanceTokenPointer(); } return compositeNode; }
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 = (List<String>) ot.getValue(); compositeNode.setOptions(optionList); advanceTokenPointer(); } return compositeNode; }
@SuppressWarnings("unchecked") 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; }
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 = (List<String>) ot.getValue(); compositeNode.setOptions(optionList); advanceTokenPointer(); } return compositeNode; }
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 = (List<String>) ot.getValue(); compositeNode.setOptions(optionList); advanceTokenPointer(); } return compositeNode; }
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 = (List<String>) ot.getValue(); compositeNode.setOptions(optionList); advanceTokenPointer(); } return compositeNode; }
CompositeNode composite = new CompositeNode(BARE); Node child = new SimpleKeywordNode("child"); composite.setChildNode(child); witness.next = composite; CompositeNode composite = new CompositeNode(BARE); Node child = new SimpleKeywordNode("child"); composite.setChildNode(child); witness.next = composite; child.next = new Node(Node.LITERAL, " "); 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"); 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"); CompositeNode composite = new CompositeNode(BARE); Node child = new Node(Node.LITERAL, " "); composite.setChildNode(child); Node c = child; c = c.next = new SimpleKeywordNode("child");