Fix error_codes scope + more informative lexer error
This commit is contained in:
parent
7416655535
commit
3644dc0619
1 changed files with 8 additions and 3 deletions
|
|
@ -42,6 +42,8 @@ context["styles"] = {
|
||||||
"reverse": 7, "conceal": 8
|
"reverse": 7, "conceal": 8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error_codes = {"UnknownColor": 1, "DuplicatedPalette": 2, "MixedModes": 3, "UnknownLexer": 4}
|
||||||
|
|
||||||
# Available color names in 8-colors mode.
|
# Available color names in 8-colors mode.
|
||||||
eight_colors = ["black","red","green","yellow","blue","magenta","cyan","white"]
|
eight_colors = ["black","red","green","yellow","blue","magenta","cyan","white"]
|
||||||
# Given in that order, the ASCII code is the index.
|
# Given in that order, the ASCII code is the index.
|
||||||
|
|
@ -929,8 +931,6 @@ def write_all( as_all, stream_in, stream_out, function, *args ):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
global context
|
global context
|
||||||
error_codes = {"UnknownColor":1, "DuplicatedPalette":2, "MixedModes":3}
|
|
||||||
|
|
||||||
usage = "A regular expression based formatter that color up an arbitrary text stream."
|
usage = "A regular expression based formatter that color up an arbitrary text stream."
|
||||||
|
|
||||||
#####################
|
#####################
|
||||||
|
|
@ -1075,7 +1075,12 @@ def main():
|
||||||
# if pygments
|
# if pygments
|
||||||
elif as_source:
|
elif as_source:
|
||||||
logging.debug("asked for lexer: %s" % pattern.lower())
|
logging.debug("asked for lexer: %s" % pattern.lower())
|
||||||
assert(pattern.lower() in context["lexers"])
|
if pattern.lower() not in context["lexers"]:
|
||||||
|
logging.error("Lexer %r is not one of %s" % (
|
||||||
|
pattern,
|
||||||
|
", ".join(repr(lexer) for lexer in context["lexers"]),
|
||||||
|
))
|
||||||
|
sys.exit(error_codes["UnknownLexer"])
|
||||||
lexer = get_lexer_by_name(pattern.lower())
|
lexer = get_lexer_by_name(pattern.lower())
|
||||||
# Python => 256 colors, python => 8 colors
|
# Python => 256 colors, python => 8 colors
|
||||||
ask_256 = pattern[0].isupper()
|
ask_256 = pattern[0].isupper()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue