1# Copyright 2014-2017 Insight Software Consortium. 2# Copyright 2004-2009 Roman Yakovenko. 3# Distributed under the Boost Software License, Version 1.0. 4# See http://www.boost.org/LICENSE_1_0.txt 5 6""" 7Free function invocation parser 8 9The parser is able to extract function name and list of arguments from a 10function invocation statement. For example, for the following code 11 12.. code-block:: c++ 13 14 do_something( x1, x2, x3 ) 15 16the parser will extract 17- function name - `do_something` 18- argument names - `[ x1, x2, x3 ]` 19 20""" 21 22from . import pattern_parser 23 24__THE_PARSER = pattern_parser.parser_t('(', ')', ',') 25 26 27def is_call_invocation(declaration_string): 28 """ 29 Returns True if `declaration_string` is a function invocation. 30 31 :param declaration_string: string that should be checked for pattern. 32 :type declaration_string: str 33 34 :rtype: bool 35 36 """ 37 return __THE_PARSER.has_pattern(declaration_string) 38 39 40def name(declaration_string): 41 """ 42 Returns the name of a function. 43 44 :type declaration_string: str 45 :rtype: str 46 47 """ 48 return __THE_PARSER.name(declaration_string) 49 50 51def args(declaration_string): 52 """ 53 Returns list of function arguments 54 55 :type declaration_string: str 56 :rtype: [str] 57 58 """ 59 return __THE_PARSER.args(declaration_string) 60 61 62NOT_FOUND = __THE_PARSER.NOT_FOUND 63 64 65def find_args(text, start=None): 66 """ 67 Finds arguments within function invocation. 68 69 :type text: str 70 :rtype: [ arguments ] or :data:NOT_FOUND if arguments could not be found. 71 72 """ 73 return __THE_PARSER.find_args(text, start) 74 75 76def split(declaration_string): 77 """ 78 Returns (name, [arguments] ) 79 80 """ 81 return __THE_PARSER.split(declaration_string) 82 83 84def split_recursive(declaration_string): 85 """ 86 Returns [(name, [arguments])]. 87 88 """ 89 return __THE_PARSER.split_recursive(declaration_string) 90 91 92def join(name_, args_, arg_separator=None): 93 """ 94 Returns name( argument_1, argument_2, ..., argument_n ). 95 96 """ 97 return __THE_PARSER.join(name_, args_, arg_separator) 98