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-04-01 01:35:10 -04:00
|
|
|
# basic stuff
|
|
|
|
'escaped': 'lpurple',
|
|
|
|
'null': 'white',
|
|
|
|
'delimiter': 'white',
|
|
|
|
'sub': 'lcyan',
|
|
|
|
'number': 'white',
|
|
|
|
'operator': 'white',
|
|
|
|
'endblock': 'lred',
|
|
|
|
'keyword': 'lpurple',
|
|
|
|
'scalar': 'yellow',
|
|
|
|
'array': 'yellow',
|
|
|
|
'deref': 'yellow',
|
|
|
|
'hash': 'yellow',
|
|
|
|
'hash_key': 'lgreen',
|
|
|
|
'comment': 'lred',
|
|
|
|
'function': 'lcyan',
|
|
|
|
'builtin': 'lpurple',
|
|
|
|
'method': 'lcyan',
|
|
|
|
'bareword': 'white',
|
|
|
|
'label': 'lcyan',
|
|
|
|
'package': 'lcyan',
|
|
|
|
'class': 'lcyan',
|
|
|
|
'use': 'lcyan',
|
|
|
|
'method': 'lcyan',
|
|
|
|
|
|
|
|
# heredoc
|
|
|
|
'heredoc1.start': 'lgreen',
|
|
|
|
'heredoc1.null': 'lgreen',
|
|
|
|
'heredoc1.end': 'lgreen',
|
|
|
|
'heredoc2.start': 'lgreen',
|
|
|
|
'heredoc2.null': 'lgreen',
|
|
|
|
'heredoc2.end': 'lgreen',
|
|
|
|
'eval_heredoc.start': 'lcyan',
|
|
|
|
'eval_heredoc.null': 'lcyan',
|
|
|
|
'eval_heredoc.end': 'lcyan',
|
|
|
|
|
|
|
|
# pod
|
|
|
|
'pod.start': 'lred',
|
|
|
|
'pod.null': 'lred',
|
|
|
|
'pod.entry': 'lpurple',
|
|
|
|
'pod.end': 'lred',
|
|
|
|
|
|
|
|
# "" strings
|
|
|
|
'string1.start': 'lgreen',
|
|
|
|
'string1.null': 'lgreen',
|
|
|
|
'string1.escaped': 'lpurple',
|
|
|
|
'string1.deref': 'yellow',
|
|
|
|
'string1.end': 'lgreen',
|
|
|
|
|
|
|
|
# '' strings
|
|
|
|
'string2.start': 'lgreen',
|
|
|
|
'string2.null': 'lgreen',
|
|
|
|
'string2.end': 'lgreen',
|
|
|
|
|
|
|
|
# `` strings
|
|
|
|
'evalstring': 'lcyan',
|
2007-04-01 00:54:52 -04:00
|
|
|
|
|
|
|
# quoted region
|
2007-04-01 01:35:10 -04:00
|
|
|
'quoted': 'lcyan',
|
|
|
|
'quoted.start': 'lcyan',
|
|
|
|
'quoted.null': 'lcyan',
|
|
|
|
'quoted.end': 'lcyan',
|
2007-04-01 00:54:52 -04:00
|
|
|
|
|
|
|
# match regex
|
2007-04-01 01:35:10 -04:00
|
|
|
'match.start': 'lcyan',
|
|
|
|
'match.end': 'lcyan',
|
|
|
|
'match.null': 'lcyan',
|
2007-04-01 00:54:52 -04:00
|
|
|
|
|
|
|
# replace regex
|
2007-04-01 01:35:10 -04:00
|
|
|
'replace.start': 'lcyan',
|
|
|
|
'replace.middle': 'lcyan',
|
|
|
|
'replace.end': 'lcyan',
|
|
|
|
'replace.null': 'lcyan',
|
|
|
|
|
|
|
|
# translate regex
|
|
|
|
'translate.start': 'lpurple',
|
|
|
|
'translate.middle': 'lpurple',
|
|
|
|
'translate.end': 'lpurple',
|
|
|
|
'translate.null': '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)
|