def _ReadArithExpr(self): # type: () -> arith_expr_t """Read and parse an arithmetic expression in various contexts. $(( 1+2 )) (( a=1+2 )) ${a[ 1+2 ]} ${a : 1+2 : 1+2} See tests/arith-context.test.sh for ambiguous cases. ${a[a[0]]} is valid # VS_RBRACKET vs Id.Arith_RBracket ${s : a<b?0:1 : 1} # VS_COLON vs Id.Arith_Colon TODO: Instead of having an eof_type. I think we should use just run the arith parser until it's done. That will take care of both : and ]. We switch the state back. See the assertion in ArithParser.Parse() -- unexpected extra input. """ # calls self.ReadWord(lex_mode_e.Arith) a_parser = tdop.TdopParser(arith_parse.Spec(), self, self.parse_opts) anode = a_parser.Parse() return anode
def MakeArithParser(self, code_str): # type: (str) -> TdopParser """Used for a[x+1]=foo in the CommandParser.""" line_reader = reader.StringLineReader(code_str, self.arena) lx = self._MakeLexer(line_reader) w_parser = word_parse.WordParser(self, lx, line_reader) w_parser.Init(lex_mode_e.Arith) # Special initialization a_parser = tdop.TdopParser(arith_parse.Spec(), w_parser, self.parse_opts) return a_parser