2014-12-23 14:39:07 +03:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
2018-03-15 11:31:17 +03:00
|
|
|
wakatime.dependencies.dotnet
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2014-12-23 14:39:07 +03:00
|
|
|
|
|
|
|
Parse dependencies from .NET code.
|
|
|
|
|
|
|
|
:copyright: (c) 2014 Alan Hamlett.
|
|
|
|
:license: BSD, see LICENSE for more details.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from . import TokenParser
|
2015-10-01 22:41:50 +03:00
|
|
|
from ..compat import u
|
2014-12-23 14:39:07 +03:00
|
|
|
|
|
|
|
|
|
|
|
class CSharpParser(TokenParser):
|
2015-10-01 22:41:50 +03:00
|
|
|
exclude = [
|
|
|
|
r'^system$',
|
|
|
|
r'^microsoft$',
|
|
|
|
]
|
|
|
|
state = None
|
|
|
|
buffer = u('')
|
2014-12-23 14:39:07 +03:00
|
|
|
|
2015-09-29 13:11:25 +03:00
|
|
|
def parse(self):
|
2014-12-23 14:39:07 +03:00
|
|
|
for index, token, content in self.tokens:
|
|
|
|
self._process_token(token, content)
|
|
|
|
return self.dependencies
|
|
|
|
|
|
|
|
def _process_token(self, token, content):
|
2015-10-01 22:41:50 +03:00
|
|
|
if self.partial(token) == 'Keyword':
|
|
|
|
self._process_keyword(token, content)
|
|
|
|
if self.partial(token) == 'Namespace' or self.partial(token) == 'Name':
|
2014-12-23 14:39:07 +03:00
|
|
|
self._process_namespace(token, content)
|
2015-10-01 22:41:50 +03:00
|
|
|
elif self.partial(token) == 'Punctuation':
|
|
|
|
self._process_punctuation(token, content)
|
2014-12-23 14:39:07 +03:00
|
|
|
else:
|
|
|
|
self._process_other(token, content)
|
|
|
|
|
2015-10-01 22:41:50 +03:00
|
|
|
def _process_keyword(self, token, content):
|
|
|
|
if content == 'using':
|
|
|
|
self.state = 'import'
|
|
|
|
self.buffer = u('')
|
|
|
|
|
2014-12-23 14:39:07 +03:00
|
|
|
def _process_namespace(self, token, content):
|
2015-10-01 22:41:50 +03:00
|
|
|
if self.state == 'import':
|
|
|
|
if u(content) != u('import') and u(content) != u('package') and u(content) != u('namespace') and u(content) != u('static'):
|
|
|
|
if u(content) == u(';'): # pragma: nocover
|
|
|
|
self._process_punctuation(token, content)
|
|
|
|
else:
|
|
|
|
self.buffer += u(content)
|
|
|
|
|
|
|
|
def _process_punctuation(self, token, content):
|
|
|
|
if self.state == 'import':
|
|
|
|
if u(content) == u(';'):
|
|
|
|
self.append(self.buffer, truncate=True)
|
|
|
|
self.buffer = u('')
|
|
|
|
self.state = None
|
|
|
|
elif u(content) == u('='):
|
|
|
|
self.buffer = u('')
|
|
|
|
else:
|
|
|
|
self.buffer += u(content)
|
2014-12-23 14:39:07 +03:00
|
|
|
|
|
|
|
def _process_other(self, token, content):
|
|
|
|
pass
|