-
-
Save isao/4003960 to your computer and use it in GitHub Desktop.
Script to display compiler output messages in BBEdit browser window
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
# BBErrors: Script to display compiler output messages in BBEdit browser window | |
# Copyright Jay Lieske Jr. | |
# 14 July 2012 | |
import sys, re, os | |
if sys.stdin.isatty(): | |
print "usage: ... | bberrors" | |
print "Filters standard input for compiler error messages, " | |
print "and tells BBEdit to display the messages in an error browser window." | |
sys.exit(1) | |
# Matches just the error messages from the compiler: | |
# a file name, followed by a colon and line number, an optional column number, | |
# and then the error message. | |
# Since BBEdit doesn't accept column numbers, it doesn't try to parse | |
# other positional feedback from the compiler. | |
# To avoid false matches, this version doesn't allow spaces in file names. | |
pat = re.compile(r"^([^: ]+):(\d+)(?:[.:-]\d+)*[:\s]+(.+)$") | |
# Distinguish warning from errors. | |
warning = re.compile(r"warning", re.IGNORECASE) | |
# Accumulate the set of errors found on stdin. | |
errors = [] | |
for line in sys.stdin: | |
sys.stdout.write(line) # echo everything | |
match = pat.match(line) | |
if match: | |
file, line, message = match.groups() | |
kind = "warning_kind" if warning.match(message) else "error_kind" | |
errors.append(dict(file=os.path.abspath(file), line=int(line), | |
kind=kind, message=message)) | |
if not errors: sys.exit(0) | |
# AppleScript expression for a single entry in the BBEdit brower. | |
template = u""" | |
{result_kind: %(kind)s, ¬ | |
result_file: "%(file)s", result_line: %(line)d, ¬ | |
message: "%(message)s"}""" | |
# Generate the full AppleScript. | |
script = (u"""tell application "BBEdit" | |
set error_list to { ¬"""+ | |
u", ¬".join(template % error for error in errors)+ | |
u""" ¬ | |
} | |
make new results browser with data error_list ¬ | |
with properties {name:"Errors"} | |
end tell""") | |
# osascript insists on printing out the value of the last AppleScript statement. | |
script += '''\n"Opened BBEdit browser."''' | |
os.execl("/usr/bin/osascript", "osascript", "-e", script) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment