                             # Check for a standard method
                             result_regex = @regex.method.exec query.slice new_start
                             if result_regex isnt null
-                                if stack[stack.length-1]?.type is 'function' or stack[stack.length-1]?.type is 'var' # We want the query to start with r. or arg.
-                                    element.type = 'function'
-                                    element.name = result_regex[0]
-                                    element.position = position+new_start
-                                    start += new_start-i
+                                result_regex_row = @regex.row.exec query.slice new_start
+                                if result_regex_row isnt null
+                                    position_opening_parenthesis = result_regex_row[0].indexOf('(')
+                                    element.type = 'function' # TODO replace with function
+                                    element.name = 'row'
+                                    stack.push element
+                                    size_stack++
+                                    if size_stack > @max_size_stack
+                                        return null
+                                    element =
+                                        type: 'function'
+                                        name: '('
+                                        position: position+3+1
+                                        context: context
+                                        complete: 'false'
+                                    stack_stop_char = ['(']
+                                    start += position_opening_parenthesis
                                     to_skip = result_regex[0].length-1+new_start-i
-                                    stack_stop_char = ['(']
                                     continue
+
                                 else
-                                    position_opening_parenthesis = result_regex[0].indexOf('(')
-                                    if position_opening_parenthesis isnt -1 and result_regex[0].slice(0, position_opening_parenthesis) of context
-                                        # Save the var
-                                        element.real_type = 'json'
-                                        element.type = 'var'
-                                        element.name = result_regex[0].slice(0, position_opening_parenthesis)
-                                        stack.push element
-                                        size_stack++
-                                        if size_stack > @max_size_stack
-                                            return null
-                                        element =
-                                            type: 'function'
-                                            name: '('
-                                            position: position+position_opening_parenthesis+1
-                                            context: context
-                                            complete: 'false'
+                                    if stack[stack.length-1]?.type is 'function' or stack[stack.length-1]?.type is 'var' # We want the query to start with r. or arg.
+                                        element.type = 'function'
+                                        element.name = result_regex[0]
+                                        element.position = position+new_start
+                                        start += new_start-i
+                                        to_skip = result_regex[0].length-1+new_start-i
                                         stack_stop_char = ['(']
-                                        start = position_opening_parenthesis
-                                        to_skip = result_regex[0].length-1
                                         continue
+                                    else
+                                        position_opening_parenthesis = result_regex[0].indexOf('(')
+                                        if position_opening_parenthesis isnt -1 and result_regex[0].slice(0, position_opening_parenthesis) of context
+                                            # Save the var
+                                            element.real_type = @types.value
+                                            element.type = 'var'
+                                            element.name = result_regex[0].slice(0, position_opening_parenthesis)
+                                            stack.push element
+                                            size_stack++
+                                            if size_stack > @max_size_stack
+                                                return null
+                                            element =
+                                                type: 'function'
+                                                name: '('
+                                                position: position+position_opening_parenthesis+1
+                                                context: context
+                                                complete: 'false'
+                                            stack_stop_char = ['(']
+                                            start = position_opening_parenthesis
+                                            to_skip = result_regex[0].length-1
+                                            continue
+                                        ###
+                                        # This last condition is a special case for r(expr)
+                                        else if position_opening_parenthesis isnt -1 and result_regex[0].slice(0, position_opening_parenthesis) is 'r'
+                                            element.type = 'var'
+                                            element.name = 'r'
+                                            element.real_type = @types.value
+                                            element.position = position+new_start
+                                            start += new_start-i
+                                            to_skip = result_regex[0].length-1+new_start-i
+                                            stack_stop_char = ['(']
+                                            continue
+                                        ###
+
 
                             # Check for method without parenthesis r., r.row., doc.
                             result_regex = @regex.method_var.exec query.slice new_start
                             if result_regex isnt null
                                 if result_regex[0].slice(0, result_regex[0].length-1) of context
                                     element.type = 'var'
-                                    element.real_type = 'json'
+                                    element.real_type = @types.value
                                 else
                                     element.type = 'function'
                                 element.position = position+new_start
                                 element.name = result_regex[0].slice(0, result_regex[0].length-1).replace(/\s/, '')
-                                start += new_start-i
                                 element.complete = true
                                 to_skip = element.name.length-1+new_start-i
                                 stack.push element

                else if result.status is 'look_for_state'
                    if element.type is 'function' and element.complete is true
                        result.state = element.name
                        if @map_state[element.name]
                            hash_suggestions = {} # To avoid redundancy. add() can returns string OR number, and add() works on both
                            for state in @map_state[element.name]
                                if @suggestions[state]?
                                    for suggestion in @suggestions[state]
                                        if result.suggestions_regex.test(suggestion) is true
                                            hash_suggestions[suggestion] = true
                            for suggestion of hash_suggestions
                                result.suggestions.push suggestion
                        #else # This is a non valid ReQL function.
                        # It may be a personalized function defined in the data explorer...
                        result.status = 'done'
                    else if element.type is 'var' and element.complete is true
                        result.state = element.real_type
                        if @suggestions[result.state]?
                            for suggestion in @suggestions[result.state]
                                if result.suggestions_regex.test(suggestion) is true
                                    result.suggestions.push suggestion
                        result.status = 'done'
                    #else # Is that possible? A function can only be preceded by a function (except for r)


                        stack: stack
                        query: query_before_cursor
                        result: result
                    result.suggestions = @uniq result.suggestions

                    if result.suggestions?.length > 0
                        for suggestion, i in result.suggestions
                            result.suggestions.sort() # We could eventually sort things earlier with a merge sort but for now that should be enough
                            @current_suggestions.push suggestion
                            @.$('.suggestion_name_list').append @template_suggestion_name
                                id: i
