Beispiel #1
0
def inferValueType(props):
    vals = []
    if "default" in props:
        vals.extend(props["default"].split("|"))
    if "values" in props:
        vals.extend(utilities.translateToSpace(props["values"].replace("..", " "), "[]<>").split())
    vals.extend(a.value for a in props["arguments"] if a.value)
    if not vals:
        argNames = set(o.argument for o in props["arguments"] if o.flags)
        if len(argNames) == 1:
            argName = list(argNames)[0]
            if argName in constants.IntegerArguments:
                return "int"
        return "std::string"
    types = set(v for v in [getValueType(s) for s in vals] if v)
    if len(types) == 1:
        return list(types)[0]
    elif len(types) == 2 and "int" in types and "double" in types:
        return "double"
    elif types:
        raise Error(
            "%s: unable to infer correct value type, can be any of %s." % (props["name"], ", ".join(types)),
            joinLineNos(*props["arguments"]),
        )
    else:
        raise Error(
            "%s: unable to infer correct value type. "
            '(String values must be enclosed by quotes, e.g. "foo")' % (props["name"]),
            joinLineNos(*props["arguments"]),
        )
Beispiel #2
0
def variableName(s):
    return "_".join(utilities.translateToSpace(
                        s, "'!\"#$%&/()=?+*@.:,;<>^`-[]{}").split())