Coverage for C:\leo.repo\leo-editor\leo\plugins\importers\csharp.py: 97%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#@+leo-ver=5-thin
2#@+node:ekr.20140723122936.18140: * @file ../plugins/importers/csharp.py
3"""The @auto importer for the csharp language."""
4from leo.plugins.importers import linescanner
5Importer = linescanner.Importer
6#@+others
7#@+node:ekr.20161121200106.3: ** class Csharp_Importer
8class Csharp_Importer(Importer):
9 """The importer for the csharp lanuage."""
11 def __init__(self, importCommands, **kwargs):
12 """Csharp_Importer.__init__"""
13 super().__init__(
14 importCommands,
15 language='csharp',
16 state_class=Csharp_ScanState,
17 strict=False,
18 )
20 #@+others
21 #@+node:ekr.20161121200106.5: *3* csharp.clean_headline
22 def clean_headline(self, s, p=None):
23 """Return a cleaned up headline s."""
24 s = s.strip()
25 if s.endswith('{'):
26 s = s[:-1].strip()
27 return s
28 #@-others
29#@+node:ekr.20161121200106.7: ** class class Csharp_ScanState
30class Csharp_ScanState:
31 """A class representing the state of the csharp line-oriented scan."""
33 def __init__(self, d=None):
34 """Csharp_ScanState.__init__"""
35 if d:
36 prev = d.get('prev')
37 self.context = prev.context
38 self.curlies = prev.curlies
39 else:
40 self.context = ''
41 self.curlies = 0
43 def __repr__(self):
44 """Csharp_ScanState.__repr__"""
45 return "Csharp_ScanState context: %r curlies: %s" % (
46 self.context, self.curlies)
48 __str__ = __repr__
50 #@+others
51 #@+node:ekr.20161121200106.8: *3* csharp_state.level
52 def level(self):
53 """Csharp_ScanState.level."""
54 return self.curlies
55 #@+node:ekr.20161121200106.9: *3* csharp_state.update
56 def update(self, data):
57 """
58 Csharp_ScanState.update.
60 Update the state using the 6-tuple returned by i.scan_line.
61 Return i = data[1]
62 """
63 context, i, delta_c, delta_p, delta_s, bs_nl = data
64 self.context = context
65 self.curlies += delta_c
66 return i
67 #@-others
69#@-others
70importer_dict = {
71 'func': Csharp_Importer.do_import(),
72 'extensions': ['.cs', '.c#'],
73}
74#@@language python
75#@@tabwidth -4
76#@-leo