# Path: strip_comments.py
# def strip_comments(contents):
#     """Strips the comments from coq code in contents.
# 
#     The strings in contents are only preserved if there are no
#     comment-like tokens inside of strings.  Stripping should be
#     successful and correct, regardless of whether or not there are
#     comment-like tokens in strings.
# 
#     The behavior of this method is undefined if there are any
#     notations which change the meaning of '(*', '*)', or '"'.
# 
#     Note that we take some extra care to leave *) untouched when it
#     does not terminate a comment.
#     """
#     contents = contents.replace('(*', ' (* ').replace('*)', ' *) ')
#     tokens = contents.split(' ')
#     rtn = []
#     is_string = False
#     comment_level = 0
#     for token in tokens:
#         do_append = (comment_level == 0)
#         if is_string:
#             if token.count('"') % 2 == 1: # there are an odd number of '"' characters, indicating that we've ended the string
#                 is_string = False
#         elif token.count('"') % 2 == 1: # there are an odd number of '"' characters, so we're starting a string
#             is_string = True
#         elif token == '(*':
#             comment_level += 1
#             do_append = False
#         elif comment_level > 0 and token == '*)':
#             comment_level -= 1
#         if do_append:
#             rtn.append(token)
#     return ' '.join(rtn).replace(' (* ', '(*').replace(' *) ', '*)').strip('\n\t ')
# 
# Path: custom_arguments.py
# DEFAULT_LOG = make_logger([(DEFAULT_VERBOSITY, sys.stderr)])
# 
# Path: coq_version.py
# def get_coq_accepts_time(coqc_prog, **kwargs):
#     return get_coq_accepts_option(coqc_prog, '-time', **kwargs)
# 
# Path: util.py
# PY3 = False


from strip_comments import strip_comments
from custom_arguments import DEFAULT_LOG
from coq_version import get_coq_accepts_time
from util import PY3
if PY3: from util import raw_input
import subprocess
import re
import util
                    cur = i
                else:
                    cur += i
            else:
                comment_level += i2.count('(*') - i2.count('*)')
                if cur is None:
                    cur = i
                else:
                    cur += i
            if cur is not None:
                curs = list(split_leading_braces(cur))
                while curs and curs[0].strip() in BRACES:
                    yield curs.pop(0)
                cur = ''.join(curs) if curs else None
            if cur is not None and is_genuine_ending(cur) and comment_level == 0: # clear out cur, if we're done with it
                yield cur
                cur = None
    if cur is not None:
        print('Unterminated comment')
        yield cur


def split_coq_file_contents(contents):
    """Splits the contents of a coq file into multiple statements.

    This is done by finding one or three periods followed by
    whitespace.  This is a dumb algorithm, but it seems to be (nearly)
    the one that ProofGeneral and CoqIDE use.

    We additionally merge lines inside of quotations."""

# Path: strip_comments.py
# def strip_comments(contents):
#     """Strips the comments from coq code in contents.
# 
#     The strings in contents are only preserved if there are no
#     comment-like tokens inside of strings.  Stripping should be
#     successful and correct, regardless of whether or not there are
#     comment-like tokens in strings.
# 
#     The behavior of this method is undefined if there are any
#     notations which change the meaning of '(*', '*)', or '"'.
# 
#     Note that we take some extra care to leave *) untouched when it
#     does not terminate a comment.
#     """
#     contents = contents.replace('(*', ' (* ').replace('*)', ' *) ')
#     tokens = contents.split(' ')
#     rtn = []
#     is_string = False
#     comment_level = 0
#     for token in tokens:
#         do_append = (comment_level == 0)
#         if is_string:
#             if token.count('"') % 2 == 1: # there are an odd number of '"' characters, indicating that we've ended the string
#                 is_string = False
#         elif token.count('"') % 2 == 1: # there are an odd number of '"' characters, so we're starting a string
#             is_string = True
#         elif token == '(*':
#             comment_level += 1
#             do_append = False
#         elif comment_level > 0 and token == '*)':
#             comment_level -= 1
#         if do_append:
#             rtn.append(token)
#     return ' '.join(rtn).replace(' (* ', '(*').replace(' *) ', '*)').strip('\n\t ')
# 
# Path: custom_arguments.py
# DEFAULT_LOG = make_logger([(DEFAULT_VERBOSITY, sys.stderr)])
# 
# Path: coq_version.py
# def get_coq_accepts_time(coqc_prog, **kwargs):
#     return get_coq_accepts_option(coqc_prog, '-time', **kwargs)
# 
# Path: util.py
# PY3 = False


# Path: split_file.py
from strip_comments import strip_comments
from custom_arguments import DEFAULT_LOG
from coq_version import get_coq_accepts_time
from util import PY3
if PY3: from util import raw_input
import subprocess
import re
import util

                    cur = i
                else:
                    cur += i
            else:
                comment_level += i2.count('(*') - i2.count('*)')
                if cur is None:
                    cur = i
                else:
                    cur += i
            if cur is not None:
                curs = list(split_leading_braces(cur))
                while curs and curs[0].strip() in BRACES:
                    yield curs.pop(0)
                cur = ''.join(curs) if curs else None
            if cur is not None and is_genuine_ending(cur) and comment_level == 0: # clear out cur, if we're done with it
                yield cur
                cur = None
    if cur is not None:
        print('Unterminated comment')
        yield cur


def split_coq_file_contents(contents):
    """Splits the contents of a coq file into multiple statements.

    This is done by finding one or three periods followed by
    whitespace.  This is a dumb algorithm, but it seems to be (nearly)
    the one that ProofGeneral and CoqIDE use.

    We additionally merge lines inside of quotations."""

    return list(merge_quotations(re.split('(?<=[^\.]\.\.\.)\s|(?<=[^\.]\.)\s', strip_comments(contents))))