Exemple #1
0
    def testShellFuncExecution(self):
        ex = cmd_exec_test.InitExecutor()
        func_node = ast.FuncDef()

        c1 = ast.CompoundWord()
        t1 = ast.token(Id.Lit_Chars, 'f1')
        c1.parts.append(ast.LiteralPart(t1))

        c2 = ast.CompoundWord()
        t2 = ast.token(Id.Lit_Chars, 'f2')
        c2.parts.append(ast.LiteralPart(t2))

        a = ast.ArrayLiteralPart()
        a.words = [c1, c2]
        w = ast.CompoundWord()
        w.parts.append(a)

        # Set global COMPREPLY=(f1 f2)
        pair = ast.assign_pair(ast.LhsName('COMPREPLY'), assign_op_e.Equal, w)
        pair.spids.append(0)  # dummy
        pairs = [pair]
        body_node = ast.Assignment(Id.Assign_None, [], pairs)

        func_node.name = 'myfunc'
        func_node.body = body_node

        a = completion.ShellFuncAction(ex, func_node)
        matches = list(a.Matches([], 0, 'f'))
        self.assertEqual(['f1 ', 'f2 '], matches)
Exemple #2
0
    def _ReadArrayLiteralPart(self):
        self._Next(LexMode.OUTER)  # advance past (
        self._Peek()
        assert self.cur_token.id == Id.Op_LParen, self.cur_token

        # MUST use a new word parser (with same lexer).
        w_parser = WordParser(self.lexer, self.line_reader)
        words = []
        while True:
            w = w_parser.ReadWord(LexMode.OUTER)

            if w.tag == word_e.TokenWord:
                word_id = word.CommandId(w)
                if word_id == Id.Right_ArrayLiteral:
                    break
                # Unlike command parsing, array parsing allows embedded \n.
                elif word_id == Id.Op_Newline:
                    continue
                else:
                    self.AddErrorContext(
                        'Unexpected word in array literal: %s', w, word=w)
                    return None

            words.append(w)

        words2 = braces.BraceDetectAll(words)
        words3 = word.TildeDetectAll(words2)

        return ast.ArrayLiteralPart(words3)
Exemple #3
0
    def _ReadArrayLiteralPart(self):
        array_part = ast.ArrayLiteralPart()

        self._Next(LexMode.OUTER)  # advance past (
        self._Peek()
        assert self.cur_token.id == Id.Op_LParen, self.cur_token

        # MUST use a new word parser (with same lexer).
        w_parser = WordParser(self.lexer, self.line_reader)
        while True:
            w = w_parser.ReadWord(LexMode.OUTER)
            if word.CommandId(w) == Id.Right_ArrayLiteral:
                break
            array_part.words.append(w)

        return array_part
Exemple #4
0
    def _ReadArrayLiteralPart(self):
        self._Next(LexMode.OUTER)  # advance past (
        self._Peek()
        assert self.cur_token.id == Id.Op_LParen, self.cur_token

        # MUST use a new word parser (with same lexer).
        w_parser = WordParser(self.lexer, self.line_reader)
        words = []
        while True:
            w = w_parser.ReadWord(LexMode.OUTER)
            if word.CommandId(w) == Id.Right_ArrayLiteral:
                break

            words.append(w)

        words2 = braces.BraceDetectAll(words)
        words3 = word.TildeDetectAll(words2)

        return ast.ArrayLiteralPart(words3)