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

199
test3.py
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,88 +17,131 @@ 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 = {
# basic stuff 'perl': {
'escaped': 'lpurple', # basic stuff
'null': 'white', 'escaped': 'lpurple',
'delimiter': 'white', 'null': 'white',
'sub': 'lcyan', 'delimiter': 'white',
'number': 'white', 'sub': 'lcyan',
'operator': 'white', 'number': 'white',
'endblock': 'lred', 'operator': 'white',
'keyword': 'lpurple', 'endblock': 'lred',
'scalar': 'yellow', 'keyword': 'lpurple',
'array': 'yellow', 'scalar': 'yellow',
'deref': 'yellow', 'array': 'yellow',
'hash': 'yellow', 'deref': 'yellow',
'hash_key': 'lgreen', 'hash': 'yellow',
'comment': 'lred', 'hash_key': 'lgreen',
'function': 'lcyan', 'comment': 'lred',
'builtin': 'lpurple', 'function': 'lcyan',
'method': 'lcyan', 'builtin': 'lpurple',
'bareword': 'white', 'method': 'lcyan',
'label': 'lcyan', 'bareword': 'white',
'package': 'lcyan', 'label': 'lcyan',
'class': 'lcyan', 'package': 'lcyan',
'use': 'lcyan', 'class': 'lcyan',
'method': 'lcyan', 'use': 'lcyan',
'method': 'lcyan',
# heredoc # heredoc
'heredoc1.start': 'lgreen', 'heredoc1.start': 'lgreen',
'heredoc1.null': 'lgreen', 'heredoc1.null': 'lgreen',
'heredoc1.end': 'lgreen', 'heredoc1.end': 'lgreen',
'heredoc2.start': 'lgreen', 'heredoc2.start': 'lgreen',
'heredoc2.null': 'lgreen', 'heredoc2.null': 'lgreen',
'heredoc2.end': 'lgreen', 'heredoc2.end': 'lgreen',
'eval_heredoc.start': 'lcyan', 'eval_heredoc.start': 'lcyan',
'eval_heredoc.null': 'lcyan', 'eval_heredoc.null': 'lcyan',
'eval_heredoc.end': 'lcyan', 'eval_heredoc.end': 'lcyan',
# pod # pod
'pod.start': 'lred', 'pod.start': 'lred',
'pod.null': 'lred', 'pod.null': 'lred',
'pod.entry': 'lpurple', 'pod.entry': 'lpurple',
'pod.end': 'lred', 'pod.end': 'lred',
# "" strings # "" strings
'string1.start': 'lgreen', 'string1.start': 'lgreen',
'string1.null': 'lgreen', 'string1.null': 'lgreen',
'string1.escaped': 'lpurple', 'string1.escaped': 'lpurple',
'string1.deref': 'yellow', 'string1.deref': 'yellow',
'string1.end': 'lgreen', 'string1.end': 'lgreen',
# '' strings # '' strings
'string2.start': 'lgreen', 'string2.start': 'lgreen',
'string2.null': 'lgreen', 'string2.null': 'lgreen',
'string2.end': 'lgreen', 'string2.end': 'lgreen',
# `` strings # `` strings
'evalstring': 'lcyan', 'evalstring': 'lcyan',
# quoted region # quoted region
'quoted': 'lcyan', 'quoted': 'lcyan',
'quoted.start': 'lcyan', 'quoted.start': 'lcyan',
'quoted.null': 'lcyan', 'quoted.null': 'lcyan',
'quoted.end': 'lcyan', 'quoted.end': 'lcyan',
# match regex # match regex
'match.start': 'lcyan', 'match.start': 'lcyan',
'match.end': 'lcyan', 'match.end': 'lcyan',
'match.null': 'lcyan', 'match.null': 'lcyan',
# replace regex # replace regex
'replace.start': 'lcyan', 'replace.start': 'lcyan',
'replace.middle': 'lcyan', 'replace.middle': 'lcyan',
'replace.end': 'lcyan', 'replace.end': 'lcyan',
'replace.null': 'lcyan', 'replace.null': 'lcyan',
# translate regex # translate regex
'translate.start': 'lpurple', 'translate.start': 'lpurple',
'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)