branch : pmacs2
This commit is contained in:
moculus 2007-04-08 14:34:49 +00:00
parent e597ea1402
commit 9878252505
1 changed files with 129 additions and 82 deletions

View File

@ -1,5 +1,5 @@
import sys import sys
import lex2, lex2_perl, highlight2 import lex2, lex2_perl, lex2_python, highlight2
color_list = [] color_list = []
color_list.extend(['\033[3%dm' % x for x in range(0, 8)]) color_list.extend(['\033[3%dm' % x for x in range(0, 8)])
@ -17,6 +17,7 @@ for i in range(0, len(color_list)):
color_dict[color_names[i]] = color_list[i] color_dict[color_names[i]] = color_list[i]
token_colors = { token_colors = {
'perl': {
# basic stuff # basic stuff
'escaped': 'lpurple', 'escaped': 'lpurple',
'null': 'white', 'null': 'white',
@ -96,9 +97,51 @@ token_colors = {
'translate.middle': 'lpurple', 'translate.middle': 'lpurple',
'translate.end': 'lpurple', 'translate.end': 'lpurple',
'translate.null': 'lpurple', 'translate.null': 'lpurple',
},
'python': {
'keyword': 'lcyan',
'builtin_method': 'lcyan',
'methodname': 'lblue',
'classname': 'lgreen',
'string.start': 'lgreen',
'string.null': 'lgreen',
'string.escaped': 'lpurple',
'string.octal': 'lpurple',
'string.format': 'yellow',
'string.end': 'lgreen',
'tq_string.start': 'lgreen',
'tq_string.null': 'lgreen',
'tq_string.end': 'lgreen',
'docstring.start': 'lgreen',
'docstring.null': 'lgreen',
'docstring.end': 'lgreen',
'comment': 'lred',
'continuation': 'lred',
#'operator': 'yellow',
#'delimiter': 'lpurple',
'system_identifier': 'lcyan',
#'bound method': color.build('yellow', 'default'),
'import': 'lpurple',
#'bizzaro': 'lpurple',
},
} }
grammars = {
'perl': lex2_perl.PerlGrammar,
'python': lex2_python.PythonGrammar,
}
#t = 'perl'
t = 'python'
m = True
#m = False
paths = sys.argv[1:] paths = sys.argv[1:]
for path in paths: for path in paths:
f = open(path, 'r') f = open(path, 'r')
@ -106,10 +149,14 @@ for path in paths:
f.close() f.close()
lines = data.split('\n') lines = data.split('\n')
lexer = lex2.Lexer('lexer', grammars[t]())
grammar = lex2_perl.PerlGrammar() if m:
lexer = lex2.Lexer('lexer', grammar)
highlighter = highlight2.Highlighter(lexer) highlighter = highlight2.Highlighter(lexer)
highlighter.highlight(lines) highlighter.highlight(lines)
highlighter.display(token_colors) highlighter.display(token_colors[t])
else:
lexer.lex(lines)
for token in lexer:
print '%-28s| %r' % (token.name, token.string)