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; }
CompositeConverter<E> compositeConverter = createCompositeConverter(cn); if(compositeConverter == null) { addError("Failed to create converter for [%"+cn.getValue()+"] keyword"); addToList(new LiteralConverter<E>("%PARSER_ERROR["+cn.getValue()+"]")); break; compositeConverter.setFormattingInfo(cn.getFormatInfo()); compositeConverter.setOptionList(cn.getOptions()); Compiler<E> childCompiler = new Compiler<E>(cn.getChildNode(), converterMap); childCompiler.setContext(context);
public String toString() { StringBuilder buf = new StringBuilder(); if(childNode != null) { buf.append("CompositeNode("+childNode+")"); } else { buf.append("CompositeNode(no child)"); } buf.append(printNext()); return buf.toString(); } }
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 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); }
/** * Attempt to create a converter using the information found in * 'compositeConverterMap'. * * @param cn * @return */ @SuppressWarnings("unchecked") CompositeConverter<E> createCompositeConverter(CompositeNode cn) { String keyword = (String) cn.getValue(); String converterClassStr = (String) converterMap.get(keyword); if (converterClassStr != null) { try { return (CompositeConverter) OptionHelper.instantiateByClassName( converterClassStr, CompositeConverter.class, context); } catch (Exception e) { addError("Failed to instantiate converter class [" + converterClassStr + "] as a composite converter for keyword ["+keyword+"]", e); return null; } } else { addError("There is no conversion class registered for composite conversion word [" + keyword + "]"); return null; } }
CompositeNode cn = (CompositeNode) n; CompositeConverter<E> compositeConverter = new CompositeConverter<E>(); compositeConverter.setFormattingInfo(cn.getFormatInfo()); Compiler<E> childCompiler = new Compiler<E>(cn.getChildNode(), converterMap); childCompiler.setContext(context);
@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); } }
/** * Attempt to create a converter using the information found in * 'compositeConverterMap'. * * @param cn * @return */ @SuppressWarnings("unchecked") CompositeConverter<E> createCompositeConverter(CompositeNode cn) { String keyword = (String) cn.getValue(); String converterClassStr = (String) converterMap.get(keyword); if (converterClassStr != null) { try { return (CompositeConverter<E>) OptionHelper.instantiateByClassName( converterClassStr, CompositeConverter.class, context); } catch (Exception e) { addError("Failed to instantiate converter class [" + converterClassStr + "] as a composite converter for keyword ["+keyword+"]", e); return null; } } else { addError("There is no conversion class registered for composite conversion word [" + keyword + "]"); return null; } }
CompositeConverter<E> compositeConverter = createCompositeConverter(cn); if(compositeConverter == null) { addError("Failed to create converter for [%"+cn.getValue()+"] keyword"); addToList(new LiteralConverter<E>("%PARSER_ERROR["+cn.getValue()+"]")); break; compositeConverter.setFormattingInfo(cn.getFormatInfo()); compositeConverter.setOptionList(cn.getOptions()); Compiler<E> childCompiler = new Compiler<E>(cn.getChildNode(), converterMap); childCompiler.setContext(context);
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, " "); 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"); 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"); Node t = p.parse(); Node witness = new Node(Node.LITERAL, "hello");
public String toString() { StringBuilder buf = new StringBuilder(); if (childNode != null) { buf.append("CompositeNode(" + childNode + ")"); } else { buf.append("CompositeNode(no child)"); } buf.append(printNext()); return buf.toString(); } }
/** * Attempt to create a converter using the information found in * 'compositeConverterMap'. * * @param cn * @return */ @SuppressWarnings("unchecked") CompositeConverter<E> createCompositeConverter(CompositeNode cn) { String keyword = (String) cn.getValue(); String converterClassStr = (String) converterMap.get(keyword); if (converterClassStr != null) { try { return (CompositeConverter) OptionHelper.instantiateByClassName(converterClassStr, CompositeConverter.class, context); } catch (Exception e) { addError("Failed to instantiate converter class [" + converterClassStr + "] as a composite converter for keyword [" + keyword + "]", e); return null; } } else { addError("There is no conversion class registered for composite conversion word [" + keyword + "]"); return null; } }
CompositeConverter<E> compositeConverter = createCompositeConverter(cn); if(compositeConverter == null) { addError("Failed to create converter for [%"+cn.getValue()+"] keyword"); addToList(new LiteralConverter<E>("%PARSER_ERROR["+cn.getValue()+"]")); break; compositeConverter.setFormattingInfo(cn.getFormatInfo()); compositeConverter.setOptionList(cn.getOptions()); Compiler<E> childCompiler = new Compiler<E>(cn.getChildNode(), converterMap); childCompiler.setContext(context);
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; }
public String toString() { StringBuilder buf = new StringBuilder(); if (childNode != null) { buf.append("CompositeNode(" + childNode + ")"); } else { buf.append("CompositeNode(no child)"); } buf.append(printNext()); return buf.toString(); } }
/** * Attempt to create a converter using the information found in * 'compositeConverterMap'. * * @param cn * @return */ @SuppressWarnings("unchecked") CompositeConverter<E> createCompositeConverter(CompositeNode cn) { String keyword = (String) cn.getValue(); String converterClassStr = (String) converterMap.get(keyword); if (converterClassStr != null) { try { return (CompositeConverter) OptionHelper.instantiateByClassName(converterClassStr, CompositeConverter.class, context); } catch (Exception e) { addError("Failed to instantiate converter class [" + converterClassStr + "] as a composite converter for keyword [" + keyword + "]", e); return null; } } else { addError("There is no conversion class registered for composite conversion word [" + keyword + "]"); return null; } }
CompositeConverter<E> compositeConverter = createCompositeConverter(cn); if(compositeConverter == null) { addError("Failed to create converter for [%"+cn.getValue()+"] keyword"); addToList(new LiteralConverter<E>("%PARSER_ERROR["+cn.getValue()+"]")); break; compositeConverter.setFormattingInfo(cn.getFormatInfo()); compositeConverter.setOptionList(cn.getOptions()); Compiler<E> childCompiler = new Compiler<E>(cn.getChildNode(), converterMap); childCompiler.setContext(context);
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; }