pmacs3/test3.py

97 lines
3.5 KiB
Python
Raw Normal View History

2007-03-28 18:38:32 -04:00
import sys
2007-03-29 18:37:34 -04:00
import lex2, lex2_perl, highlight2
2007-03-28 18:38:32 -04:00
color_list = []
color_list.extend(['\033[3%dm' % x for x in range(0, 8)])
color_list.extend(['\033[3%d;1m' % x for x in range(0, 8)])
color_list.append('\033[0m')
color_names = [
'black', 'dred', 'dgreen', 'brown', 'dblue', 'dpurple', 'dcyan', 'lgrey',
'dgrey', 'lred', 'lgreen', 'yellow', 'lblue', 'lpurple', 'lcyan', 'white',
'unset',
]
color_dict ={}
for i in range(0, len(color_list)):
color_dict[color_names[i]] = color_list[i]
token_colors = {
2007-03-31 21:37:42 -04:00
'null': 'white',
'delimiter': 'white',
'pod.start': 'lred',
'pod.null': 'lred',
'pod.end': 'lred',
'pod.header': 'lpurple',
'sub': 'lcyan',
'number': 'white',
'operator': 'white',
'heredoc': 'lgreen',
'endblock': 'lred',
'pod': 'lred',
'comment': 'lred',
2007-03-31 22:39:37 -04:00
#'string1': 'lgreen',
2007-03-31 21:37:42 -04:00
'string1.start': 'lgreen',
'string1.null': 'lgreen',
'string1.escaped': 'lpurple',
2007-03-31 22:39:37 -04:00
#'string1.scalar': 'yellow',
#'string1.system_scalar': 'yellow',
2007-03-31 21:37:42 -04:00
'string1.hash_deref': 'yellow',
2007-03-31 22:39:37 -04:00
#'string1.hash_bareword_index': 'lgreen',
2007-03-31 21:37:42 -04:00
'string1.end': 'lgreen',
2007-03-31 22:39:37 -04:00
#'string2': 'lgreen',
2007-03-31 21:37:42 -04:00
'string2.start': 'lgreen',
'string2.null': 'lgreen',
'string2.end': 'lgreen',
'evalstring': 'lcyan',
'default_string': 'lgreen',
'keyword': 'lpurple',
'length_scalar': 'yellow',
'system_scalar': 'yellow',
'system_array': 'yellow',
'scalar': 'yellow',
'dereference': 'yellow',
'array': 'yellow',
'hash': 'yellow',
'bareword_hash_index': 'lgreen',
'quoted_region': 'lcyan',
'match_regex': 'lcyan',
2007-03-31 22:39:37 -04:00
'replace_regex.start': 'lcyan',
'replace_regex.middle': 'lcyan',
'replace_regex.end': 'lcyan',
'replace_regex.null': 'lcyan',
2007-03-31 21:37:42 -04:00
'bareword_hash_key': 'lgreen',
'interpolated_scalar': 'yellow',
'interpolated_system_scalar': 'yellow',
'interpolated_array': 'yellow',
'interpolated_system_array': 'yellow',
'interpolated_hash': 'yellow',
'label': 'lcyan',
'package': 'lcyan',
'use': 'lcyan',
'method': 'lcyan',
'methodref': 'lcyan',
'method_declaration': 'lcyan',
'instance_method': 'lcyan',
'static_method': 'lcyan',
'builtin_method': 'lpurple',
'bareword_method': 'lcyan',
2007-03-31 22:39:37 -04:00
#'bareword': 'yellow',
2007-03-31 21:37:42 -04:00
'bizzaro': 'lpurple',
2007-03-28 18:38:32 -04:00
}
paths = sys.argv[1:]
for path in paths:
f = open(path, 'r')
data = f.read()
f.close()
lines = data.split('\n')
grammar = lex2_perl.PerlGrammar()
lexer = lex2.Lexer('lexer', grammar)
2007-03-29 18:37:34 -04:00
highlighter = highlight2.Highlighter(lexer)
2007-03-28 18:38:32 -04:00
2007-03-29 18:37:34 -04:00
highlighter.highlight(lines)
highlighter.display(token_colors)