from typing import Any


def escape(val: Any) -> str:
    """Escapes a primitive value for inclusion within a Daikon file."""
    if isinstance(val, str):
        val = val.replace('\\', '\\\\').replace('"', '\\"')
        return f'"{val}"'
    if isinstance(val, bool):
        return 'true' if val else 'false'
    return val