@Override public boolean run(final Context<BaseTemplate> context) { ValueStack<BaseTemplate> stack = context.getValueStack(); if (stack.size() > 1) { BaseTemplate body = pop(); ((Block) section.get()).inverse(body); } return addToline(section.get()); } }
@Override public boolean run(final Context<BaseTemplate> context) { ValueStack<BaseTemplate> stack = context.getValueStack(); if (stack.size() > 1) { BaseTemplate body = pop(); ((Block) section.get()).body(body); } return addToline(section.get()); } }).label("block");
@Override public boolean run(Context<CfgElement> context) { final ValueStack<CfgElement> stack = context.getValueStack(); if (!context.hasError()) { int size = stack.size(); switch (size) { case 1: CfgElement elemKey = stack.pop(); parsedProps.setProperty(unescape(elemKey.getText()), ""); cfgFile.getElements().add(new PairElement(elemKey)); break; case 2: // NOTE: stack popping order below is important! final CfgElement elemValue = stack.pop(); elemKey = stack.pop(); parsedProps.setProperty(unescape(elemKey.getText()), unescape(elemValue.getText())); cfgFile.getElements().add(new PairElement(elemKey, elemValue)); break; default: throw new IllegalStateException(String.format("Cannot manage %d values on the parsing stack", size)); } } else { stack.clear(); } return true; }
/** * Creates CSV value. * * @return An CSV value. */ protected CsvReaderValue createCsvReaderValue() { CSVParserSettings parserSettings = null; switch (getContext().getValueStack().size()) { case 1: parserSettings = new CSVParserSettings((String) pop()); break; case 2: parserSettings = new CSVParserSettings((String) pop(1), (char) pop()); break; case 8: parserSettings = new CSVParserSettings((String) pop(7), (char) pop(6), (String) pop(5), (boolean) pop(4), peek(3) instanceof NullValue ? null : (Character) pop(3), (char) pop(2), (boolean) pop(1), peek() instanceof NullValue ? null : (String) pop()); break; default: throw new RuntimeException("Unsupported number of parameters, should not happen ever."); } return new CsvReaderValue(parserSettings); }
/** * Creates CSV value. * * @return An CSV value. */ protected CsvReaderValue createCsvReaderValue() { CSVParserSettings parserSettings = null; switch (getContext().getValueStack().size()) { case 1: parserSettings = new CSVParserSettings((String) pop()); break; case 2: parserSettings = new CSVParserSettings((String) pop(1), (char) pop()); break; case 8: parserSettings = new CSVParserSettings((String) pop(7), (char) pop(6), (String) pop(5), (boolean) pop(4), peek(3) instanceof NullValue ? null : (Character) pop(3), (char) pop(2), (boolean) pop(1), peek() instanceof NullValue ? null : (String) pop()); break; default: throw new RuntimeException("Unsupported number of parameters, should not happen ever."); } return new CsvReaderValue(parserSettings); }