char c = text.charAt(index++);
private boolean bareword(Token t, Object v) { return v instanceof CharSequence && Token.eq(t, (CharSequence) v); }
protected Token whole(Token b, Token e) { return tz.text.subSequence(b.start - tz.text.start, e.start + e.length() - tz.text.start); }
public ParsedLineImpl(Program program, Token line, int cursor, List<Token> tokens) { this.program = program; this.source = line.toString(); this.cursor = cursor - line.start(); this.tokens = new ArrayList<>(); for (Token token : tokens) { for (int i = 0; i < tokens.size(); i++) { Token t = tokens.get(i); if (t.start() > cursor) { wi = i; wc = 0; break; if (t.start() + t.length() >= cursor) { wi = i; wc = cursor - t.start(); break;
if (token.start() >= buffer.length()) { break; if (token.start() > cur) { cur = token.start(); if (Token.eq(token, "{") || Token.eq(token, "}") || Token.eq(token, "(") || Token.eq(token, ")") || Token.eq(token, "[") || Token.eq(token, "]") || Token.eq(token, "|") || Token.eq(token, ";") || Token.eq(token, "=")) { type = Type.Reserved; } else if (token.charAt(0) == '\'' || token.charAt(0) == '"') { type = Type.String; } else if (token.toString().matches("^[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?$")) { type = Type.Number; } else if (token.charAt(0) == '$') { type = Type.Variable; } else if (((Set<?>) session.get(CommandSessionImpl.CONSTANTS)).contains(token.toString()) || Token.eq(token, "null") || Token.eq(token, "false") || Token.eq(token, "true")) { type = Type.Constant; } else { && token == statement.tokens().get(2); boolean isAssign = statement != null && statement.tokens().size() > 1
|| Token.eq("\n", t) || Token.eq(";", t) || Token.eq("&", t) || Token.eq("&&", t) || Token.eq("||", t) || Token.eq("|", t) || Token.eq("|&", t) || Token.eq("}", t) || Token.eq(")", t) || Token.eq("]", t)) break; if (Token.eq("{", t)) else if (Token.eq("[", t)) else if (Token.eq("(", t)) redirs.add(tz.readHereDoc(t.charAt(t.length() - 1) == '-'));
throw new EOFError(sLine, sCol, "expected here-doc start", "heredoc", "foo\n"); Token token = text.subSequence(start, index - 1); getch(); start = index - 1; Token s = text.subSequence(nlIndex, index - 1); if (Token.eq(s, token)) Token hd = text.subSequence(start, s.start()); getch(); return hd; throw new EOFError(sLine, sCol, "unexpected eof found in here-doc", "heredoc", "\n" + token.toString() + "\n");
if (Token.eq("]", key)) if (Token.eq("\n", key)) if (Token.eq("{", key) || Token.eq(";", key) || Token.eq("&", key) || Token.eq("&&", key) || Token.eq("||", key) || Token.eq("|", key) || Token.eq("|&", key) || Token.eq(")", key) || Token.eq("}", key) || Token.eq("=", key)) throw new SyntaxError(key.line(), key.column(), "unexpected token '" + key + "' while looking for array key"); if (Token.eq("(", key)) if (Token.eq("[", key)) isMap = Token.eq("=", n); push(n); else if (Token.eq(";", val) || Token.eq("&", val) || Token.eq("&&", val) || Token.eq("||", val) || Token.eq("|", val) || Token.eq("|&", val) || Token.eq(")", key) || Token.eq("}", key) || Token.eq("=", key)) throw new SyntaxError(key.line(), key.column(), "unexpected token '" + key + "' while looking for array value"); else if (Token.eq("[", val)) else if (Token.eq("(", val)) else if (Token.eq("{", val))
String cmdName = session.resolveCommand(statement.tokens().get(0).toString()); String[] parts = cmdName.split(":"); Command cmd = parts.length == 2 ? session.getRegistry().getCommand(parts[0], parts[1]) : null; List<Token> tokens = new ArrayList<>(statement.tokens()); Token last = tokens.get(tokens.size() - 1); tokens.set(tokens.size() - 1, last.subSequence(0, line.length() - last.start())); return new ParsedLineImpl(program, stmt, cursor, tokens);
private Object doExpand() throws Exception int i = text.length(); while ((--i >= 0) && (special.indexOf(text.charAt(i)) == -1)); value = text.subSequence(start + 1, index - 1); getch(); buf.append("\'"); value = text.subSequence(start, index - 1); getch(); Object expand = expand(value, evaluate, true); value = text.subSequence(start - 1, index); getch(); if (eot() && buf.length() == 0)
protected Token expect(String str) { Token start = next(); if (start == null) { throw new EOFError(tz.line, tz.column, "unexpected EOT looking for '" + str + "", getMissing(), str); } if (!Token.eq(str, start)) { throw new SyntaxError(start.line, start.column, "expected '" + str + "' but got '" + start.toString() + "'"); } return start; }
private Token token(int start) { if (start == index - 1) { if (ch == EOT) { return null; } if (ch == '\r' && peek() == '\n') { getch(); } getch(); last = text.subSequence(index - 2, index - 1); } else { last = text.subSequence(start, index - 1); } return last; }
return t; skipSpace(last == null || Token.eq(last, "\n")); int start = index - 1; Token t, tn; t = text.subSequence(start, index); if (!eot()) tn = text.subSequence(start, index + 1); if (redir.matcher(tn).matches()) return token(start); case '-': t = text.subSequence(start, index); if (redir.matcher(t).matches()) else if (redir.matcher(text.subSequence(start, index)).matches())
List<Token> tokens = new ArrayList<>(statement.tokens()); Token last = tokens.get(tokens.size() - 1); tokens.set(tokens.size() - 1, last.subSequence(0, line.length() - last.start())); return new ParsedLineImpl(program, stmt, cursor, tokens);
private Token word(CharSequence value) { return new Token(Type.WORD, value, line, column); }
protected boolean eot() { return index >= text.length(); }
Token token; while ((token = tokenizer.next()) != null) { args.add(token.toString());
|| Token.eq("\n", t) || Token.eq(";", t) || Token.eq("&", t) || Token.eq("&&", t) || Token.eq("||", t) || Token.eq("|", t) || Token.eq("|&", t) || Token.eq("}", t) || Token.eq(")", t) || Token.eq("]", t)) break; if (Token.eq("{", t)) else if (Token.eq("[", t)) else if (Token.eq("(", t)) redirs.add(tz.readHereDoc(t.charAt(t.length() - 1) == '-'));