some C mode improvements, and some tabbing fixes
--HG-- branch : pmacs2
This commit is contained in:
parent
1d720e9934
commit
7f93cf0910
21
mode/c.py
21
mode/c.py
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import color, mode2, tab2
|
import color, mode2, tab2
|
||||||
from lex3 import Grammar, PatternRule, RegionRule
|
from lex3 import Grammar, PatternRule, RegionRule
|
||||||
from mode.python import StringGrammar
|
from mode.python import StringGrammar
|
||||||
|
@ -48,10 +49,16 @@ class CGrammar(Grammar):
|
||||||
PatternRule(r"float", r"[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+"),
|
PatternRule(r"float", r"[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+"),
|
||||||
RegionRule(r'string', '"', StringGrammar, '"'),
|
RegionRule(r'string', '"', StringGrammar, '"'),
|
||||||
PatternRule(r'char', r"'.'|'\\.'|'\\[0-7]{3}'"),
|
PatternRule(r'char', r"'.'|'\\.'|'\\[0-7]{3}'"),
|
||||||
PatternRule(r"eol", r"\n$"),
|
PatternRule(r'spaces', r' +'),
|
||||||
|
PatternRule(r'eol', r"\n$"),
|
||||||
]
|
]
|
||||||
|
|
||||||
class CTabber(tab2.StackTabber):
|
class CTabber(tab2.StackTabber):
|
||||||
|
wst = ('spaces', 'eol', 'comment', 'comment.start', 'comment.null', 'comment.end')
|
||||||
|
def token_is_whitespace(self, y, i):
|
||||||
|
token = self.get_token(y, i)
|
||||||
|
return token.fqname() in self.wst
|
||||||
|
|
||||||
def is_base(self, y):
|
def is_base(self, y):
|
||||||
if y == 0:
|
if y == 0:
|
||||||
return True
|
return True
|
||||||
|
@ -91,7 +98,10 @@ class CTabber(tab2.StackTabber):
|
||||||
token = self.get_token(y, i)
|
token = self.get_token(y, i)
|
||||||
if token.string == '{':
|
if token.string == '{':
|
||||||
self._opt_pop('cond')
|
self._opt_pop('cond')
|
||||||
currlvl = tab2.StackTabber._handle_open_token(self, currlvl, y, i)
|
self._opt_pop('cont')
|
||||||
|
if self.is_leftmost_token(y, i):
|
||||||
|
currlvl = self.get_curr_level()
|
||||||
|
tab2.StackTabber._handle_open_token(self, currlvl, y, i)
|
||||||
return currlvl
|
return currlvl
|
||||||
def _handle_close_token(self, currlvl, y, i):
|
def _handle_close_token(self, currlvl, y, i):
|
||||||
self._opt_pop('cont')
|
self._opt_pop('cont')
|
||||||
|
@ -101,9 +111,10 @@ class CTabber(tab2.StackTabber):
|
||||||
if token.string == '}':
|
if token.string == '}':
|
||||||
self._opt_pop('cond')
|
self._opt_pop('cond')
|
||||||
self._opt_pop('cont')
|
self._opt_pop('cont')
|
||||||
elif self._peek_name() == 'cond':
|
elif self._has_markers() and self._peek_name() == 'cond':
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
if token.fqname() != 'macro.delimiter':
|
||||||
self._opt_append('cont', currlvl + 4)
|
self._opt_append('cont', currlvl + 4)
|
||||||
return currlvl
|
return currlvl
|
||||||
def _handle_other_token(self, currlvl, y, i):
|
def _handle_other_token(self, currlvl, y, i):
|
||||||
|
@ -113,6 +124,7 @@ class CTabber(tab2.StackTabber):
|
||||||
self._opt_pop('cond')
|
self._opt_pop('cond')
|
||||||
self._opt_pop('cont')
|
self._opt_pop('cont')
|
||||||
self._opt_pop('cond')
|
self._opt_pop('cond')
|
||||||
|
self._opt_pop('cont')
|
||||||
|
|
||||||
elif fqname == 'keyword':
|
elif fqname == 'keyword':
|
||||||
if token.string in ('do', 'else', 'for', 'if', 'while'):
|
if token.string in ('do', 'else', 'for', 'if', 'while'):
|
||||||
|
@ -156,7 +168,8 @@ class CTabber(tab2.StackTabber):
|
||||||
not fqname.startswith('macro') and
|
not fqname.startswith('macro') and
|
||||||
not fqname == 'delimiter' and
|
not fqname == 'delimiter' and
|
||||||
not fqname == 'header' and
|
not fqname == 'header' and
|
||||||
not fqname == 'null' and
|
#not fqname == 'null' and
|
||||||
|
not fqname == 'spaces' and
|
||||||
not fqname == 'eol' and
|
not fqname == 'eol' and
|
||||||
token.string not in ('}', ';', '(', '{', '[', ',')):
|
token.string not in ('}', ';', '(', '{', '[', ',')):
|
||||||
self._opt_append('cont', currlvl + 4)
|
self._opt_append('cont', currlvl + 4)
|
||||||
|
|
2
tab2.py
2
tab2.py
|
@ -26,7 +26,7 @@ class Tabber:
|
||||||
|
|
||||||
def token_is_whitespace(self, y, i):
|
def token_is_whitespace(self, y, i):
|
||||||
token = self.get_token(y, i)
|
token = self.get_token(y, i)
|
||||||
return token.name in self.wst and self.wsre.match(token.string)
|
return token.fqname() in self.wst and self.wsre.match(token.string)
|
||||||
def token_is_space(self, y, i):
|
def token_is_space(self, y, i):
|
||||||
token = self.get_token(y, i)
|
token = self.get_token(y, i)
|
||||||
return token.name in self.st and self.sre.match(token.string)
|
return token.name in self.st and self.sre.match(token.string)
|
||||||
|
|
Loading…
Reference in New Issue