示例#1
0
 /**
  * Parses and returns a number.
  *
  * @param cmd referring command; if specified, the result must not be empty
  * @return name
  * @throws QueryException query exception
  */
 private String number(final Cmd cmd) throws QueryException {
   consumeWS();
   final StringBuilder sb = new StringBuilder();
   if (parser.curr() == '-') sb.append(parser.consume());
   while (digit(parser.curr())) sb.append(parser.consume());
   return finish(eoc() || ws(parser.curr()) ? sb : null, cmd);
 }
示例#2
0
 /**
  * Parses and returns the specified keyword.
  *
  * @param key token to be parsed
  * @param cmd referring command; if specified, the keyword is mandatory
  * @return result of check
  * @throws QueryException query exception
  */
 private boolean key(final String key, final Cmd cmd) throws QueryException {
   consumeWS();
   final int p = parser.pos;
   final boolean ok =
       (parser.consume(key) || parser.consume(key.toLowerCase(Locale.ENGLISH)))
           && (parser.curr(0) || ws(parser.curr()));
   if (!ok) {
     parser.pos = p;
     if (cmd != null) throw help(null, cmd);
   }
   return ok;
 }
示例#3
0
 /**
  * Parses and returns a command. A command is limited to letters.
  *
  * @param cmd referring command; if specified, the result must not be empty
  * @return name
  * @throws QueryException query exception
  */
 private String command(final Cmd cmd) throws QueryException {
   consumeWS();
   final StringBuilder sb = new StringBuilder();
   while (!eoc() && !ws(parser.curr())) {
     sb.append(parser.consume());
   }
   return finish(sb, cmd);
 }
示例#4
0
 /**
  * Parses and returns a glob expression, which extends {@link #name(Cmd)} function with asterisks,
  * question marks and commands.
  *
  * @param cmd referring command; if specified, the result must not be empty
  * @return glob expression
  * @throws QueryException query exception
  */
 private String glob(final Cmd cmd) throws QueryException {
   consumeWS();
   final StringBuilder sb = new StringBuilder();
   while (true) {
     final char ch = parser.curr();
     if (!Databases.validChar(ch) && ch != '*' && ch != '?' && ch != ',') {
       return finish(eoc() || ws(ch) ? sb : null, cmd);
     }
     sb.append(parser.consume());
   }
 }
示例#5
0
 /**
  * Parses and returns a string, delimited by a semicolon or, optionally, a space. Quotes can be
  * used to include spaces.
  *
  * @param cmd referring command; if specified, the result must not be empty
  * @param space stop when encountering space
  * @return string
  * @throws QueryException query exception
  */
 private String string(final Cmd cmd, final boolean space) throws QueryException {
   final StringBuilder sb = new StringBuilder();
   consumeWS();
   boolean q = false;
   while (parser.more()) {
     final char c = parser.curr();
     if (!q && ((space ? c <= ' ' : c < ' ') || eoc())) break;
     if (c == '"') q ^= true;
     else sb.append(c);
     parser.consume();
   }
   return finish(sb, cmd);
 }
示例#6
0
 /**
  * Checks if the end of a command has been reached.
  *
  * @return true if command has ended
  */
 private boolean eoc() {
   return !parser.more() || parser.curr() == ';';
 }
示例#7
0
 /**
  * Parses and returns a name. A name may contain letters, numbers and any of the special
  * characters <code>!#$%&'()+-=@[]^_`{}~</code>.
  *
  * @param cmd referring command; if specified, the result must not be empty
  * @return name
  * @throws QueryException query exception
  */
 private String name(final Cmd cmd) throws QueryException {
   consumeWS();
   final StringBuilder sb = new StringBuilder();
   while (Databases.validChar(parser.curr())) sb.append(parser.consume());
   return finish(eoc() || ws(parser.curr()) ? sb : null, cmd);
 }