# Path: plugins/lib/view_utils.py
# def coorded_substr(view, reg1=None, reg2=None, rel=None):
#     """Returns the string of two coordinate pairs forming a region.
# 
#     The pairs are supporsed to be indexable and have a length of 2.
#     Tuples are preferred.
# 
#     Defaults to the whole buffer.
# 
#         For examples, see `coorded_region`.
#     """
#     return view.substr(coorded_region(view, reg1, reg2))
# 
# def base_scope(view):
#     """Returns the view's base scope.
#     """
#     return view.scope_name(0).split(' ', 1)[0]
# 
# def get_text(view):
#     """Returns the whole string of a buffer. Alias for `coorded_substr(view)`.
#     """
#     return coorded_substr(view)


import re
import os
import json
import yaml
import plistlib
import sublime
from sublime_lib import OutputPanel
from ..view_utils import coorded_substr, base_scope, get_text
    from xml.parsers.expat import ExpatError, ErrorString
    from . import plist_parser
            from xml.sax._exceptions import SAXReaderNotAvailable
            text = strip_js_comments(text)
            data = json.loads(text)
        except ValueError as e:
            self.output.print(self.debug_base % (self.file_path, str(e)))
        else:
            return data


class PlistLoader(LoaderProto):
    name = "Property List"
    ext  = "plist"
    debug_base = 'Error parsing ' + name + ' "%s": %s, line %s, column %s'
    file_regex = re.escape(debug_base).replace(r'\%', '%') % (r'(.*?)', r'.*?', r'(\d+)', r'(\d+)')
    opt_regex = r'^\s*<!--\s+\[PackageDev\]\s+(.+)-->'
    DOCTYPE = "<!DOCTYPE plist"

    @classmethod
    def file_is_valid(cls, view, file_path=None):
        file_path = file_path or view and view.file_name()
        if not file_path:
            return None

        if (cls.get_ext_appendix(file_path) is not None
                or os.path.splitext(file_path)[1] == '.' + cls.ext):
            return True

        # Plists have no scope (syntax definition) since they are XML.
        # Instead, check for the DOCTYPE in the first three lines.
        if view:
            for i in range(3):  # This would be a really terrible one-liner

# Path: plugins/lib/view_utils.py
# def coorded_substr(view, reg1=None, reg2=None, rel=None):
#     """Returns the string of two coordinate pairs forming a region.
# 
#     The pairs are supporsed to be indexable and have a length of 2.
#     Tuples are preferred.
# 
#     Defaults to the whole buffer.
# 
#         For examples, see `coorded_region`.
#     """
#     return view.substr(coorded_region(view, reg1, reg2))
# 
# def base_scope(view):
#     """Returns the view's base scope.
#     """
#     return view.scope_name(0).split(' ', 1)[0]
# 
# def get_text(view):
#     """Returns the whole string of a buffer. Alias for `coorded_substr(view)`.
#     """
#     return coorded_substr(view)


# Path: plugins/lib/fileconv/loaders.py
import re
import os
import json
import yaml
import plistlib
import sublime
from sublime_lib import OutputPanel
from ..view_utils import coorded_substr, base_scope, get_text
    from xml.parsers.expat import ExpatError, ErrorString
    from . import plist_parser
            from xml.sax._exceptions import SAXReaderNotAvailable

            text = strip_js_comments(text)
            data = json.loads(text)
        except ValueError as e:
            self.output.print(self.debug_base % (self.file_path, str(e)))
        else:
            return data


class PlistLoader(LoaderProto):
    name = "Property List"
    ext  = "plist"
    debug_base = 'Error parsing ' + name + ' "%s": %s, line %s, column %s'
    file_regex = re.escape(debug_base).replace(r'\%', '%') % (r'(.*?)', r'.*?', r'(\d+)', r'(\d+)')
    opt_regex = r'^\s*<!--\s+\[PackageDev\]\s+(.+)-->'
    DOCTYPE = "<!DOCTYPE plist"

    @classmethod
    def file_is_valid(cls, view, file_path=None):
        file_path = file_path or view and view.file_name()
        if not file_path:
            return None

        if (cls.get_ext_appendix(file_path) is not None
                or os.path.splitext(file_path)[1] == '.' + cls.ext):
            return True

        # Plists have no scope (syntax definition) since they are XML.
        # Instead, check for the DOCTYPE in the first three lines.
        if view:
            for i in range(3):  # This would be a really terrible one-liner

                text = coorded_substr(view, (i, 0), (i, len(cls.DOCTYPE)))