Exemple #1
0
    def _ReadArithExpr(self):
        """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)
        anode = a_parser.Parse()
        assert anode is not None
        return anode  # could be None
Exemple #2
0
 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,
                                      lex_mode=lex_mode_e.Arith)
     a_parser = tdop.TdopParser(arith_parse.SPEC, w_parser)
     return a_parser
Exemple #3
0
  def MakeArithParser(self, code_str, arena):
    """Used for a[x+1]=foo in the CommandParser.

    NOTE: We add tokens to a different arena, so we don't mess up the
    invariants for translation.
    """
    line_reader = reader.StringLineReader(code_str, arena)
    lx = self._MakeLexer(line_reader, arena=arena)
    w_parser = word_parse.WordParser(self, lx, line_reader,
                                     lex_mode=lex_mode_e.Arith)
    a_parser = tdop.TdopParser(arith_parse.SPEC, w_parser)
    return a_parser