# Path: penman/types.py

# 
# Path: penman/exceptions.py
# class ConstantError(PenmanError):
#     """Raised when working with invalid constant values."""


from typing import Union
from enum import Enum
from penman.types import Constant
from penman.exceptions import ConstantError
import json
    float constants, this function returns the equivalent Python
    :py:class:`int` or :py:class:`float` objects.

    Examples:
        >>> from penman import constant
        >>> constant.evaluate('-')
        '-'
        >>> constant.evaluate('"foo"')
        'foo'
        >>> constant.evaluate('1')
        1
        >>> constant.evaluate('1.2')
        1.2
        >>> constant.evaluate('') is None
        True
    """
    value: Constant = constant_string
    if value is None or value == '':
        value = None
    else:
        assert isinstance(constant_string, str)
        if constant_string.startswith('"') ^ constant_string.endswith('"'):
            raise ConstantError(f'unbalanced quotes: {constant_string}')
        if constant_string not in ('true', 'false', 'null'):
            try:
                value = json.loads(constant_string, parse_constant=str)
            except json.JSONDecodeError:
                value = constant_string

    if not (value is None or isinstance(value, (str, int, float))):

# Path: penman/types.py

# 
# Path: penman/exceptions.py
# class ConstantError(PenmanError):
#     """Raised when working with invalid constant values."""


# Path: penman/constant.py
from typing import Union
from enum import Enum
from penman.types import Constant
from penman.exceptions import ConstantError
import json

    float constants, this function returns the equivalent Python
    :py:class:`int` or :py:class:`float` objects.

    Examples:
        >>> from penman import constant
        >>> constant.evaluate('-')
        '-'
        >>> constant.evaluate('"foo"')
        'foo'
        >>> constant.evaluate('1')
        1
        >>> constant.evaluate('1.2')
        1.2
        >>> constant.evaluate('') is None
        True
    """
    value: Constant = constant_string
    if value is None or value == '':
        value = None
    else:
        assert isinstance(constant_string, str)
        if constant_string.startswith('"') ^ constant_string.endswith('"'):
            raise ConstantError(f'unbalanced quotes: {constant_string}')
        if constant_string not in ('true', 'false', 'null'):
            try:
                value = json.loads(constant_string, parse_constant=str)
            except json.JSONDecodeError:
                value = constant_string

    if not (value is None or isinstance(value, (str, int, float))):

        raise ConstantError(f'invalid constant: {value!r}')