Exemplo n.º 1
0
def _parse_value(code: str) -> Tuple[data.Value, str]:
    if code.startswith('\''):
        value, rest_code = _parse_value(code[1:])
        return _make_quote(value), rest_code

    if code.startswith('('):
        values, rest_code = _parse_list(code[1:])
        rest_code = _parse_skip(rest_code)
        if not rest_code.startswith(')'):
            raise ParseError(rest_code)
        return data.from_native_list(values), rest_code[1:]

    match = _TOKEN_RE.search(code)
    if not match:
        raise ParseError(code)
    token = match.group()
    if _NUM_RE.search(token):
        value = data.Int(int(token))
    elif token == '#f':
        value = data.Bool(False)
    elif token == '#t':
        value = data.Bool(True)
    else:
        value = data.Symbol(token)
    return value, code[match.end():]
Exemplo n.º 2
0
def _builtin_or(args: List[data.Value]) -> data.Value:
    result = False
    for value in args:
        result = result or value != data.FALSE
    return data.Bool(result)
Exemplo n.º 3
0
def _builtin_and(args: List[data.Value]) -> data.Value:
    result = True
    for value in args:
        result = result and value != data.FALSE
    return data.Bool(result)
Exemplo n.º 4
0
def _builtin_gte(args: List[data.Value]) -> data.Value:
    assert len(args) == 2
    lhs, rhs = args
    assert isinstance(lhs, data.Int), 'not integer'
    assert isinstance(rhs, data.Int), 'not integer'
    return data.Bool(lhs.raw_value >= rhs.raw_value)
Exemplo n.º 5
0
def _builtin_eq_check(args: List[data.Value]) -> data.Value:
    assert len(args) == 2
    lhs, rhs = args
    return data.Bool(lhs is rhs)
Exemplo n.º 6
0
def _builtin_not(args: List[data.Value]) -> data.Value:
    assert len(args) == 1
    value = args[0]
    return data.Bool(not (value != data.FALSE))