void parse() { try { // http://jira.qos.ch/browse/LBCORE-130 // we escape ')' for parsing purposes. Note that the original pattern is preserved // because it is shown to the user in status messages. We don't want the escaped version // to leak out. String patternForParsing = escapeRightParantesis(pattern); Parser<Object> p = new Parser<Object>(patternForParsing, new AlmostAsIsEscapeUtil()); p.setContext(context); Node t = p.parse(); this.headTokenConverter = p.compile(t, CONVERTER_MAP); } catch (ScanException sce) { addError("Failed to parse pattern \"" + pattern + "\".", sce); } }
Node T() throws ScanException { Token t = getCurentToken(); expectNotNull(t, "a LITERAL or '%'"); switch (t.getType()) { case Token.LITERAL: advanceTokenPointer(); return new Node(Node.LITERAL, t.getValue()); case Token.PERCENT: advanceTokenPointer(); // System.out.println("% token found"); FormatInfo fi; Token u = getCurentToken(); FormattingNode c; expectNotNull(u, "a FORMAT_MODIFIER, SIMPLE_KEYWORD or COMPOUND_KEYWORD"); if (u.getType() == Token.FORMAT_MODIFIER) { fi = FormatInfo.valueOf((String) u.getValue()); advanceTokenPointer(); c = C(); c.setFormatInfo(fi); } else { c = C(); } return c; default: return null; } }
FormattingNode C() throws ScanException { Token t = getCurentToken(); // System.out.println("in C()"); // System.out.println("Current token is " + t); expectNotNull(t, "a LEFT_PARENTHESIS or KEYWORD"); int type = t.getType(); switch (type) { case Token.SIMPLE_KEYWORD: return SINGLE(); case Token.COMPOSITE_KEYWORD: advanceTokenPointer(); return COMPOSITE(t.getValue().toString()); default: throw new IllegalStateException("Unexpected token " + t); } }
Node Eopt() throws ScanException { // System.out.println("in Eopt()"); Token next = getCurentToken(); // System.out.println("Current token is " + next); if (next == null) { return null; } else { return E(); } }
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; }
@Test public void lbcore193() throws Exception { try { Parser<Object> p = new Parser("hello%(abc"); p.setContext(context); p.parse(); fail("where the is exception?"); } catch (ScanException ise) { assertEquals("Expecting RIGHT_PARENTHESIS token but got null", ise.getMessage()); } StatusChecker sc = new StatusChecker(context); sc.assertContainsMatch("Expecting RIGHT_PARENTHESIS"); sc.assertContainsMatch("See also " + Parser.MISSING_RIGHT_PARENTHESIS); }
public Node parse() throws ScanException { return E(); }
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; }
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; }
Node Eopt() throws ScanException { // System.out.println("in Eopt()"); Token next = getCurentToken(); // System.out.println("Current token is " + next); if (next == null) { return null; } else { return E(); } }
public Node parse() throws ScanException { return E(); }
/** * Parses the pattern and creates the Converter linked list. */ @Override public void start() { int errorCount = 0; try { Parser<E> p = new Parser<E>(pattern); p.setContext(getContext()); Node t = p.parse(); this.head = p.compile(t, getEffectiveConverterMap()); ConverterUtil.startConverters(this.head); } catch (ScanException ex) { addError("Incorrect pattern found", ex); errorCount++; } if (errorCount == 0) { super.started = true; } }
FormattingNode C() throws ScanException { Token t = getCurentToken(); // System.out.println("in C()"); // System.out.println("Current token is " + t); expectNotNull(t, "a LEFT_PARENTHESIS or KEYWORD"); int type = t.getType(); switch (type) { case Token.KEYWORD: return SINGLE(); case Token.LEFT_PARENTHESIS: advanceTokenPointer(); return COMPOSITE(); default: throw new IllegalStateException("Unexpected token " + 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; }
Node T() throws ScanException { Token t = getCurentToken(); expectNotNull(t, "a LITERAL or '%'"); switch (t.getType()) { case Token.LITERAL: advanceTokenPointer(); return new Node(Node.LITERAL, t.getValue()); case Token.PERCENT: advanceTokenPointer(); // System.out.println("% token found"); FormatInfo fi; Token u = getCurentToken(); FormattingNode c; expectNotNull(u, "a FORMAT_MODIFIER, SIMPLE_KEYWORD or COMPOUND_KEYWORD"); if (u.getType() == Token.FORMAT_MODIFIER) { fi = FormatInfo.valueOf((String) u.getValue()); advanceTokenPointer(); c = C(); c.setFormatInfo(fi); } else { c = C(); } return c; default: return null; } }