Works like Symbol.__str__(), but allows a custom format to be used for
        all symbol/choice references. See expr_str().
1531
def custom_str(self, sc_expr_str_fn):
        
        return "\n\n".join(node.custom_str(sc_expr_str_fn)
                           for node in self.nodes)
1018255
def method(self, symbol_name):
        

        s = self.symbol(symbol_name)

        def bind(fn):
            setattr(s, fn.__name__, fn)
        return bind
311791
def symbol(self, index):
        """"""
        #if index is actually a string, just return it
        if isinstance(index, str):
            return index
        elif (index < 0) or (index >= self.symtab.table_len):
            self.error("symbol table index out of range")
        sym = self.symtab.table[index]
        #local variables are located at negative offset from frame pointer register
        if sym.kind == SharedData.KINDS.LOCAL_VAR:
            return "-{0}(1:%14)".format(sym.attribute * 4 + 4)
        #parameters are located at positive offset from frame pointer register
        elif sym.kind == SharedData.KINDS.PARAMETER:
            return "{0}(1:%14)".format(8 + sym.attribute * 4)
        elif sym.kind == SharedData.KINDS.CONSTANT:
            return "${0}".format(sym.name)
        else:
            return "{0}".format(sym.name)
719688
def operator_from_str(op):
    
    d = {"==": operator.eq,
         "!=": operator.ne,
         ">": operator.gt,
         ">=": operator.ge,
         "<": operator.lt,
         "<=": operator.le,
         '+': operator.add,
         '-': operator.sub,
         '*': operator.mul,
         '%': operator.mod,
         '^': operator.xor,
         }

    try:
        d['/'] = operator.truediv
    except AttributeError:
        pass

    return d[op]
1038222
def pretty_str(self, indent=0):
        
        if self.parenthesis:
            return '{}({})'.format(' ' * indent, pretty_str(self.value))
        return pretty_str(self.value, indent=indent)
368591
def abbreviate_str(string, max_len=80, indicator="..."):
  
  if not string or not max_len or len(string) <= max_len:
    return string
  elif max_len <= len(indicator):
    return string[0:max_len]
  else:
    return string[0:max_len - len(indicator)] + indicator
46129
def p_string_expr_lp(p):
    
    if p[2].type_ != TYPE.string:
        syntax_error(p.lexer.lineno,
                     "Expected a string type expression. "
                     "Got %s type instead" % TYPE.to_string(p[2].type_))
        p[0] = None
    else:
        p[0] = make_strslice(p.lexer.lineno, p[2], p[4][0], p[4][1])
423044
def str_repl(self, inputstring, **kwargs):
        """"""
        out = []
        comment = None
        string = None

        for i, c in enumerate(append_it(inputstring, None)):
            try:

                if comment is not None:
                    if c is not None and c in nums:
                        comment += c
                    elif c == unwrapper and comment:
                        ref = self.get_ref("comment", comment)
                        if out and not out[-1].endswith("\n"):
                            out[-1] = out[-1].rstrip(" ")
                            if not self.minify:
                                out[-1] += "  "  # put two spaces before comment
                        out.append("#" + ref)
                        comment = None
                    else:
                        raise CoconutInternalException("invalid comment marker in", getline(i, inputstring))
                elif string is not None:
                    if c is not None and c in nums:
                        string += c
                    elif c == unwrapper and string:
                        text, strchar = self.get_ref("str", string)
                        out.append(strchar + text + strchar)
                        string = None
                    else:
                        raise CoconutInternalException("invalid string marker in", getline(i, inputstring))
                elif c is not None:
                    if c == "#":
                        comment = ""
                    elif c == strwrapper:
                        string = ""
                    else:
                        out.append(c)

            except CoconutInternalException as err:
                complain(err)
                if comment is not None:
                    out.append(comment)
                    comment = None
                if string is not None:
                    out.append(string)
                    string = None
                out.append(c)

        return "".join(out)
438179
def pretty_str(self, indent=0):
        
        if self.parenthesis:
            return (' ' * indent) + '(' + self.name + ')'
        return (' ' * indent) + self.name
498228
def expr_to_str(n, l=None):
    
    op = n[0]
    if op.startswith('_') and op.endswith('_'):
        op = op.strip('_')
        if op == 'var':
            return n[1]
        elif op == 'literal':
            if isinstance(n[1], basestring):
                return "'%s'" % n[1]
            return str(n[1])
        elif op == 'cast':
            return "(%s)::%s" % (expr_to_str(n[1]), n[2])
    elif op in '+-*/':
        return "(%s) %s (%s)" % (expr_to_str(n[1]), op, expr_to_str(n[2]))
    elif op == "extract":
        return "extract( %s from %s )" % (n[1], expr_to_str(n[2]))
    else:
        arg = ','.join(map(expr_to_str, n[1:]))
        return "%s(%s)" % (op, arg)
1216480
def to_str(self, s):
        '''
        
        '''
        if s.__class__ != str:
            if not IS_PY3K:
                s = s.encode('utf-8')
            else:
                raise AssertionError('Expected to have str on Python 3. Found: %s (%s)' % (s, s.__class__))
        return s
205032
def default(self):
        
        if isinstance(self.__default, (str, unicode)):
            return self.valueFromString(self.__default)
        else:
            return self.__default
327865
def define(cls, expr):
        

        try:
            lang = cls.lang
            items = items_(expr)
            for item in items:
                op, term = item
                full_op = operators.get(op)
                if full_op:
                    class_ = lang.ops[full_op.id]
                    clauses = {k: jx_expression(v) for k, v in expr.items() if k != op}
                    break
            else:
                if not items:
                    return NULL
                raise Log.error("{{operator|quote}} is not a known operator", operator=expr)

            if term == None:
                return class_([], **clauses)
            elif is_list(term):
                terms = [jx_expression(t) for t in term]
                return class_(terms, **clauses)
            elif is_data(term):
                items = items_(term)
                if class_.has_simple_form:
                    if len(items) == 1:
                        k, v = items[0]
                        return class_([Variable(k), Literal(v)], **clauses)
                    else:
                        return class_({k:  Literal(v) for k, v in items}, **clauses)
                else:
                    return class_(_jx_expression(term, lang), **clauses)
            else:
                if op in ["literal", "date", "offset"]:
                    return class_(term, **clauses)
                else:
                    return class_(_jx_expression(term, lang), **clauses)
        except Exception as e:
            Log.error("programmer error expr = {{value|quote}}", value=expr, cause=e)
29830
def get_representation(self, prefix="", suffix="\n"):
        
        res = []
        if self.hidden:
            res.append(prefix + " - " + str(self._name)
                       + " : xxxxxxxx" + suffix)
        else:
            default = self.default
            if default is None:
                default = " - "
            a = prefix + " - "
            a += str(self._name) + " : "
            if isinstance(default, types.UnicodeType):
                a += default
            else:
                a += str(default)
            a += suffix
            res.append(a)
        return res
591761
def str_func(name):
    
    def func(mapping, bind, values):
        for v in values:
            if isinstance(v, six.string_types):
                v = getattr(v, name)()
            yield v
    return func
1096975
def str_def(self):
        
        return "classname={!r}; connect_retries={!r}; message={!r};". \
            format(self.__class__.__name__, self.connect_retries, self.args[0])
770197
def create_str(help_string=NO_HELP, default=NO_DEFAULT):
        # type: (str, Union[str, NO_DEFAULT_TYPE]) -> str
        
        # noinspection PyTypeChecker
        return ParamFunctions(
            help_string=help_string,
            default=default,
            type_name="str",
            function_s2t=convert_string_to_string,
            function_t2s=convert_string_to_string,
        )