예제 #1
0
파일: arith_parse.py 프로젝트: vck/oil
def LeftIndex(p, w, left, unused_bp):
    """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("%s can't be indexed", left, word=w)
    index = p.ParseUntil(0)
    p.Eat(Id.Arith_RBracket)

    return ast.ArithBinary(word.ArithId(w), left, index)
예제 #2
0
파일: tdop.py 프로젝트: waldyrious/oil
def LeftBinaryOp(p, w, left, rbp):
    """ Normal binary operator like 1+2 or 2*3, etc. """
    return ast.ArithBinary(word.ArithId(w), left, p.ParseUntil(rbp))
예제 #3
0
def LeftBinaryOp(p, w, left, rbp):
    """ Normal binary operator like 1+2 or 2*3, etc. """
    # TODO: w shoudl be a TokenWord, and we should extract the token from it.
    return ast.ArithBinary(word.ArithId(w), left, p.ParseUntil(rbp))