# Path: lib/detect_syntax/variables.py
# SYNTAX = namedtuple('Syntax', _SYNTAX_ATTRIBUTES)(
#     asa='Packages/Network Tech/cisco-asa.sublime-syntax',
#     ace='Packages/Network Tech/cisco-ace.sublime-syntax',
#     ios='Packages/Network Tech/cisco-ios.sublime-syntax',
#     nxos='Packages/Network Tech/cisco-nxos.sublime-syntax',
#     ios_xr='Packages/Network Tech/cisco-ios-xr.sublime-syntax',
# )
# 
# DETECT_SYNTAX = namedtuple('DetectSyntax', _DETECT_SYNTAX_ATTRIBUTES)(
#     cisco=[
#         r'^! Last configuration change at',
#         r'^!Command: show ',
#         r'^: Hardware:\s+ASA\d+',
#         r'^ASA Version \d+\.\d+',
#         r'^Building configuration...$',
#         r'^Current configuration : \d+ bytes$',
#         r'^Generating configuration....',
#         r'\bios-regex\s+',
#         r'^\s*\bnsf\s+cisco\s*$',
#     ],
#     asa=[
#         r'^#\s+set\s+syntax\s*=\s*cisco-asa',
#         r'^ASA Version \d+\.\d+',
#         r'^: Hardware:\s+ASA\d+',
#         r'^\s*security-level \d+$',
#         r'^\s*nameif \S+$',
#         r'^\s*access-list cached ACL log flows:',
#         r'^\s*route\s+\S+\d+',
#         r'^\s*fragment chain \d+ \S+$',
#         r'^\s*asdm image \S+$',
#         r'^\s*same-security-traffic',
#     ],  
#     nxos=[
#         r'^#\s+set\s+syntax\s*=\s*cisco-nxos',
#         r'^!Command: show .*',
#         r'^\s*feature \S+',
#         r'^\s*vrf context \S+',
#     ],
#     ace=[
#         r'^#\s+set\s+syntax\s*=\s*cisco-ace',
#         r'^Generating configuration....',
#     ],
#     ios=[
#         r'^#\s+set\s+syntax\s*=\s*cisco-ios',
#         r'^\s*ip classless$',
#         r'^\s*!! IOS XR Configuration$',
#         r'^\s*ip subnet-zero$',
#         r'^\s*redundancy$',
#         r'^\s*mode sso$',
#         r'^\s*main-cpu$',
#         r'^\s*auto-sync standard$',
#         r'^\s*spanning-tree extend system-id$',
#         r'^\s*vlan internal allocation policy ascending$',
#         r'^Current configuration : \d+ bytes$',
#         r'^Building configuration...$',
#         r'^\s*access-list \d{2,3} ((?:permit)|(?:deny))',
#     ],
#     ios_xr=[
#         r'^#\s+set\s+syntax\s*=\s*cisco-ios-xr',
#         r'^\s*route-policy\s+\S+',
#         r'^\s*tag-set\s+\S+\s*$',
#         r'^\s*extcommunity-set\s+rt\s+\S+\s*$',
#         r'^\s*extcommunity-set\s+cost\s+\S+\s*$',
#         r'^\s*extcommunity-set\s+soo\s+\S+\s*$',
#         r'^\s*prefix-set\s+\S+\s*$',
#         r'^\s*ospf-area-set\s+\S+\s*$',
#         r'^\s*as-path-set\s+\S+\s*$',
#         r'^\s*rpl\s+editor\s+(?:(?:nano)|(?:emacs)|(?:vim))\s*$',
#         r'^\s*rpl\s+maximum\s+(?:(?:lines)|(?:policies))\s+\d+\s*$',
#     ],
# )


import logging
import sublime
import sublime_plugin
from .variables import SYNTAX, DETECT_SYNTAX
class AutoSyntaxDetection(sublime_plugin.ViewEventListener):
    def on_modified_async(self):
        if self.is_plain_text and self.is_cisco:
            if self.is_nxos:
                self.view.set_syntax_file(SYNTAX.nxos)
            elif self.is_asa:
                self.view.set_syntax_file(SYNTAX.asa)
            elif self.is_ios:
                self.view.set_syntax_file(SYNTAX.ios)
            elif self.is_ace:
                self.view.set_syntax_file(SYNTAX.ace)
            elif self.is_ios_xr:
                self.view.set_syntax_file(SYNTAX.ios_xr)

    @property
    def is_plain_text(self):
        return self.view.scope_name(0).strip() == 'text.plain'

    def is_cisco(self):
        for evidence in DETECT_SYNTAX.cisco:
            if self.view.find(evidence, 0):
                return True
        return False

    @property
    def is_asa(self):
        return self._syntax_detection(DETECT_SYNTAX.asa, 'Cisco ASA detected')

    @property
    def is_nxos(self):

# Path: lib/detect_syntax/variables.py
# SYNTAX = namedtuple('Syntax', _SYNTAX_ATTRIBUTES)(
#     asa='Packages/Network Tech/cisco-asa.sublime-syntax',
#     ace='Packages/Network Tech/cisco-ace.sublime-syntax',
#     ios='Packages/Network Tech/cisco-ios.sublime-syntax',
#     nxos='Packages/Network Tech/cisco-nxos.sublime-syntax',
#     ios_xr='Packages/Network Tech/cisco-ios-xr.sublime-syntax',
# )
# 
# DETECT_SYNTAX = namedtuple('DetectSyntax', _DETECT_SYNTAX_ATTRIBUTES)(
#     cisco=[
#         r'^! Last configuration change at',
#         r'^!Command: show ',
#         r'^: Hardware:\s+ASA\d+',
#         r'^ASA Version \d+\.\d+',
#         r'^Building configuration...$',
#         r'^Current configuration : \d+ bytes$',
#         r'^Generating configuration....',
#         r'\bios-regex\s+',
#         r'^\s*\bnsf\s+cisco\s*$',
#     ],
#     asa=[
#         r'^#\s+set\s+syntax\s*=\s*cisco-asa',
#         r'^ASA Version \d+\.\d+',
#         r'^: Hardware:\s+ASA\d+',
#         r'^\s*security-level \d+$',
#         r'^\s*nameif \S+$',
#         r'^\s*access-list cached ACL log flows:',
#         r'^\s*route\s+\S+\d+',
#         r'^\s*fragment chain \d+ \S+$',
#         r'^\s*asdm image \S+$',
#         r'^\s*same-security-traffic',
#     ],  
#     nxos=[
#         r'^#\s+set\s+syntax\s*=\s*cisco-nxos',
#         r'^!Command: show .*',
#         r'^\s*feature \S+',
#         r'^\s*vrf context \S+',
#     ],
#     ace=[
#         r'^#\s+set\s+syntax\s*=\s*cisco-ace',
#         r'^Generating configuration....',
#     ],
#     ios=[
#         r'^#\s+set\s+syntax\s*=\s*cisco-ios',
#         r'^\s*ip classless$',
#         r'^\s*!! IOS XR Configuration$',
#         r'^\s*ip subnet-zero$',
#         r'^\s*redundancy$',
#         r'^\s*mode sso$',
#         r'^\s*main-cpu$',
#         r'^\s*auto-sync standard$',
#         r'^\s*spanning-tree extend system-id$',
#         r'^\s*vlan internal allocation policy ascending$',
#         r'^Current configuration : \d+ bytes$',
#         r'^Building configuration...$',
#         r'^\s*access-list \d{2,3} ((?:permit)|(?:deny))',
#     ],
#     ios_xr=[
#         r'^#\s+set\s+syntax\s*=\s*cisco-ios-xr',
#         r'^\s*route-policy\s+\S+',
#         r'^\s*tag-set\s+\S+\s*$',
#         r'^\s*extcommunity-set\s+rt\s+\S+\s*$',
#         r'^\s*extcommunity-set\s+cost\s+\S+\s*$',
#         r'^\s*extcommunity-set\s+soo\s+\S+\s*$',
#         r'^\s*prefix-set\s+\S+\s*$',
#         r'^\s*ospf-area-set\s+\S+\s*$',
#         r'^\s*as-path-set\s+\S+\s*$',
#         r'^\s*rpl\s+editor\s+(?:(?:nano)|(?:emacs)|(?:vim))\s*$',
#         r'^\s*rpl\s+maximum\s+(?:(?:lines)|(?:policies))\s+\d+\s*$',
#     ],
# )


# Path: lib/detect_syntax/listener.py
import logging
import sublime
import sublime_plugin
from .variables import SYNTAX, DETECT_SYNTAX

class AutoSyntaxDetection(sublime_plugin.ViewEventListener):
    def on_modified_async(self):
        if self.is_plain_text and self.is_cisco:
            if self.is_nxos:
                self.view.set_syntax_file(SYNTAX.nxos)
            elif self.is_asa:
                self.view.set_syntax_file(SYNTAX.asa)
            elif self.is_ios:
                self.view.set_syntax_file(SYNTAX.ios)
            elif self.is_ace:
                self.view.set_syntax_file(SYNTAX.ace)
            elif self.is_ios_xr:
                self.view.set_syntax_file(SYNTAX.ios_xr)

    @property
    def is_plain_text(self):
        return self.view.scope_name(0).strip() == 'text.plain'

    def is_cisco(self):
        for evidence in DETECT_SYNTAX.cisco:
            if self.view.find(evidence, 0):
                return True
        return False

    @property
    def is_asa(self):
        return self._syntax_detection(DETECT_SYNTAX.asa, 'Cisco ASA detected')

    @property
    def is_nxos(self):

        return self._syntax_detection(DETECT_SYNTAX.nxos, 'Cisco NXOS detected')