Beispiel #1
0
def LeftIndex(p, w, left, unused_bp):
  # type: (TdopParser, word_t, arith_expr_t, int) -> arith_expr_t
  """Array indexing, in both LValue and RValue context.

  LValue: f[0] = 1  f[x+1] = 2
  RValue: a = f[0]  b = f[x+1]

  On RHS, you can have:
  1. a = f[0]
  2. a = f(x, y)[0]
  3. a = f[0][0]  # in theory, if we want character indexing?
     NOTE: a = f[0].charAt() is probably better

  On LHS, you can only have:
  1. a[0] = 1

  Nothing else is valid:
  2. function calls return COPIES.  They need a name, at least in osh.
  3. strings don't have mutable characters.
  """
  if not tdop.IsIndexable(left):
    p_die("The [ operarator doesn't apply to this expression", word=w)
  index = p.ParseUntil(0)
  p.Eat(Id.Arith_RBracket)

  return arith_expr.Binary(word_.ArithId(w), left, index)
Beispiel #2
0
def LeftBinaryOp(p, w, left, rbp):
    # type: (TdopParser, word_t, arith_expr_t, int) -> arith_expr_t
    """ Normal binary operator like 1+2 or 2*3, etc. """
    # TODO: w shoudl be a Token, and we should extract the token from it.
    return arith_expr.Binary(word_.ArithId(w), left, p.ParseUntil(rbp))