Package freemarker.core.parser

Examples of freemarker.core.parser.ParseException


            c = skipWS();
            if (c == ' ') break;
            seq.add(fetchStringValue());
            c = skipWS();
            if (c == ' ') break;
            if (c != ',') throw new ParseException(
                    "Expected \",\" or the end of text but "
                    + "found \"" + c + "\"", 0, 0);
            p++;
        }
        return seq;
View Full Code Here


            c = skipWS();
            if (c == ' ') break;
            String lib = fetchStringValue();

            c = skipWS();
            if (c == ' ') throw new ParseException(
                    "Unexpected end of text: expected \"as\"", 0, 0);
            String s = fetchKeyword();
            if (!s.equalsIgnoreCase("as")) throw new ParseException(
                    "Expected \"as\", but found " + StringUtil.jQuote(s), 0, 0);

            c = skipWS();
            if (c == ' ') throw new ParseException(
                    "Unexpected end of text: expected gate hash name", 0, 0);
            String ns = fetchStringValue();
           
            map.put(ns, lib);

            c = skipWS();
            if (c == ' ') break;
            if (c != ',') throw new ParseException(
                    "Expected \",\" or the end of text but "
                    + "found \"" + c + "\"", 0, 0);
            p++;
        }
        return map;
View Full Code Here

    }

    String fetchKeyword() throws ParseException {
        String w = fetchWord();
        if (w.startsWith("'") || w.startsWith("\"")) {
            throw new ParseException(
                "Keyword expected, but a string value found: " + w, 0, 0);
        }
        return w;
    }
View Full Code Here

        }
        return ' ';
    }

    private String fetchWord() throws ParseException {
        if (p == ln) throw new ParseException(
                "Unexpeced end of text", 0, 0);

        char c = text.charAt(p);
        int b = p;
        if (c == '\'' || c == '"') {
            boolean escaped = false;
            char q = c;
            p++;
            while (p < ln) {
                c = text.charAt(p);
                if (!escaped) {
                    if (c == '\\') {
                        escaped = true;
                    } else if (c == q) {
                        break;
                    }
                } else {
                    escaped = false;
                }
                p++;
            }
            if (p == ln) {
                throw new ParseException("Missing " + q, 0, 0);
            }
            p++;
            return text.substring(b, p);
        } else {
            do {
                c = text.charAt(p);
                if (!(Character.isLetterOrDigit(c)
                        || c == '/' || c == '\\' || c == '_'
                        || c == '.' || c == '-' || c == '!'
                        || c == '*' || c == '?')) break;
                p++;
            } while (p < ln);
            if (b == p) {
                throw new ParseException("Unexpected character: " + c, 0, 0);
            } else {
                return text.substring(b, p);
            }
        }
    }
View Full Code Here

        int bidx = 0;
        StringBuilder buf = new StringBuilder(lidx);
        do {
            buf.append(s.substring(bidx, idx));
            if (idx >= lidx) {
                throw new ParseException("The last character of string literal is backslash", 0,0);
            }
            char c = s.charAt(idx + 1);
            switch (c) {
                case '"':
                    buf.append('"');
                    bidx = idx + 2;
                    break;
                case '\'':
                    buf.append('\'');
                    bidx = idx + 2;
                    break;
                case '\\':
                    buf.append('\\');
                    bidx = idx + 2;
                    break;
                case 'n':
                    buf.append('\n');
                    bidx = idx + 2;
                    break;
                case 'r':
                    buf.append('\r');
                    bidx = idx + 2;
                    break;
                case 't':
                    buf.append('\t');
                    bidx = idx + 2;
                    break;
                case 'f':
                    buf.append('\f');
                    bidx = idx + 2;
                    break;
                case 'b':
                    buf.append('\b');
                    bidx = idx + 2;
                    break;
                case 'g':
                    buf.append('>');
                    bidx = idx + 2;
                    break;
                case 'l':
                    buf.append('<');
                    bidx = idx + 2;
                    break;
                case 'a':
                    buf.append('&');
                    bidx = idx + 2;
                    break;
                case '{':
                    buf.append('{');
                    bidx = idx + 2;
                    break;
                case 'x': {
                    idx += 2;
                    int x = idx;
                    int y = 0;
                    int z = lidx > idx + 3 ? idx + 3 : lidx;
                    while (idx <= z) {
                        char b = s.charAt(idx);
                        if (b >= '0' && b <= '9') {
                            y <<= 4;
                            y += b - '0';
                        } else if (b >= 'a' && b <= 'f') {
                            y <<= 4;
                            y += b - 'a' + 10;
                        } else if (b >= 'A' && b <= 'F') {
                            y <<= 4;
                            y += b - 'A' + 10;
                        } else {
                            break;
                        }
                        idx++;
                    }
                    if (x < idx) {
                        buf.append((char) y);
                    } else {
                        throw new ParseException("Invalid \\x escape in a string literal",0,0);
                    }
                    bidx = idx;
                    break;
                }
                default:
                    throw new ParseException("Invalid escape sequence (\\" + c + ") in a string literal",0,0);
            }
            idx = s.indexOf('\\', bidx);
        } while (idx != -1);
        buf.append(s.substring(bidx));
View Full Code Here

        Template result = cache.getTemplate(name, locale, encoding, parse);
        if (result == null) {
            throw new FileNotFoundException("Template " + name + " not found.");
        }
        if (result.hasParsingProblems() && !tolerateParsingProblems) {
          throw new ParseException(result.getParsingProblems());
        }
        return result;
    }
View Full Code Here

      && name != VERSION
      && name != OUTPUT_ENCODING
      && name != URL_ESCAPING_CHARSET
            && name != ERROR)
        {
            throw new ParseException("Unknown built-in variable: " + name, this);
        }
    }
View Full Code Here

    private LinkedHashMap<String,Expression> namedArgs =
        new LinkedHashMap<String, Expression>();

    public void addNamedArg(String name, Expression exp) throws ParseException{
        if (namedArgs.containsKey(name)) throw new ParseException(
                "Error at: " + exp.getStartLocation() + "\nArgument " + name + " was already specified.");
        namedArgs.put(name, exp);
        exp.parent = this;
    }
View Full Code Here

                else {
                    try {
                        parse = parseExp.isTrue(null);
                    }
                    catch(NonBooleanException e) {
                        throw new ParseException("Expected a boolean or string as the value of the parse attribute", parseExp);
                    }
                }
            }
            catch(TemplateException e) {
                // evaluation of literals must not throw a TemplateException
View Full Code Here

    private boolean getYesNo(String s) throws ParseException {
        try {
           return StringUtil.getYesNo(s);
        }
        catch (IllegalArgumentException iae) {
            throw new ParseException("Error " + getStartLocation()
                 + "\nValue of include parse parameter "
                 + "must be boolean or one of these strings: "
                 + "\"n\", \"no\", \"f\", \"false\", \"y\", \"yes\", \"t\", \"true\""
                 + "\nFound: " + parseExp, parseExp);
        }
View Full Code Here

TOP

Related Classes of freemarker.core.parser.ParseException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.