129 lines
4.6 KiB
Python
129 lines
4.6 KiB
Python
import sys
|
|
import lex2, lex2_perl, highlight2
|
|
|
|
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 = {
|
|
'escaped': 'lpurple',
|
|
'null': 'white',
|
|
'delimiter': 'white',
|
|
'pod.start': 'lred',
|
|
'pod.null': 'lred',
|
|
'pod.end': 'lred',
|
|
'pod.header': 'lpurple',
|
|
'pod.indent_level': 'lpurple',
|
|
'pod.item_entry': 'lpurple',
|
|
'pod.format': 'lpurple',
|
|
'pod.encoding_type': 'lpurple',
|
|
'sub': 'lcyan',
|
|
'number': 'white',
|
|
'operator': 'white',
|
|
'heredoc': 'lgreen',
|
|
'endblock': 'lred',
|
|
'pod': 'lred',
|
|
'comment': 'lred',
|
|
#'string1': 'lgreen',
|
|
'string1.start': 'lgreen',
|
|
'string1.null': 'lgreen',
|
|
'string1.escaped': 'lpurple',
|
|
#'string1.scalar': 'yellow',
|
|
#'string1.system_scalar': 'yellow',
|
|
'string1.hash_deref': 'yellow',
|
|
#'string1.hash_bareword_index': 'lgreen',
|
|
'string1.end': 'lgreen',
|
|
#'string2': 'lgreen',
|
|
'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
|
|
'quoted_region1': 'lcyan',
|
|
'quoted_region1.start': 'lcyan',
|
|
'quoted_region1.null': 'lcyan',
|
|
'quoted_region1.end': 'lcyan',
|
|
'quoted_region2': 'lcyan',
|
|
'quoted_region2.start': 'lcyan',
|
|
'quoted_region2.null': 'lcyan',
|
|
'quoted_region2.end': 'lcyan',
|
|
|
|
# match regex
|
|
'match_regex1.start': 'lcyan',
|
|
'match_regex1.end': 'lcyan',
|
|
'match_regex1.null': 'lcyan',
|
|
'match_regex2.start': 'lcyan',
|
|
'match_regex2.end': 'lcyan',
|
|
'match_regex2.null': 'lcyan',
|
|
'match_regex3.start': 'lcyan',
|
|
'match_regex3.end': 'lcyan',
|
|
'match_regex3.null': 'lcyan',
|
|
|
|
# replace regex
|
|
'replace_regex1.start': 'lcyan',
|
|
'replace_regex1.middle': 'lcyan',
|
|
'replace_regex1.end': 'lcyan',
|
|
'replace_regex1.null': 'lcyan',
|
|
'replace_regex2.start': 'lcyan',
|
|
'replace_regex2.middle': 'lcyan',
|
|
'replace_regex2.end': 'lcyan',
|
|
'replace_regex2.null': 'lcyan',
|
|
|
|
#
|
|
'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',
|
|
#'bareword': 'yellow',
|
|
'bizzaro': 'lpurple',
|
|
}
|
|
|
|
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)
|
|
highlighter = highlight2.Highlighter(lexer)
|
|
|
|
highlighter.highlight(lines)
|
|
highlighter.display(token_colors)
|