From 55b6a3f313670d2cb13847d1f1b04fe3e4b21d63 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 8 Apr 2010 20:09:16 +0000 Subject: Tuplr -> Resp (RESource Processing). git-svn-id: http://svn.drobilla.net/resp/resp@252 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- tuplr_highlight.py | 152 ----------------------------------------------------- 1 file changed, 152 deletions(-) delete mode 100755 tuplr_highlight.py (limited to 'tuplr_highlight.py') diff --git a/tuplr_highlight.py b/tuplr_highlight.py deleted file mode 100755 index c48831d..0000000 --- a/tuplr_highlight.py +++ /dev/null @@ -1,152 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -import sys -import pygments -import re -from pygments import highlight -from pygments.lexers import SchemeLexer -from pygments.formatters import HtmlFormatter, LatexFormatter -from pygments.lexer import RegexLexer, bygroups -from pygments.token import * -from pygments.style import Style - -#from pygments.styles import STYLE_MAP -#print STYLE_MAP.keys() - -class TuplrLexer(RegexLexer): - name = 'Tuplr' - aliases = ['tuplr', 'tpr'] - filenames = ['*.tpr'] - mimetypes = ['text/x-tuplr', 'application/x-tuplr'] - - keywords = [ 'fn', 'def', 'if', 'match', 'ns', 'type' ] - builtins = [ 'cons', 'car', 'cdr' ] - - valid_name = r'[.a-zA-Z0-9!$%&*+,/:<=>?@^_~|-]+' - - tokens = { - 'root' : [ - # types - (r':?[A-Z][a-zA-Z.]*|:\([A-Z][a-zA-Z.\ ]*\)', Keyword.Type), - - # line comments - (r';.*$', Comment.Single), - - # whitespace - (r'\s+', Text), - - # numbers - (r'-?\d+\.\d+', Number.Float), - (r'-?\d+', Number.Integer), - - # strings, symbols and characters - (r'"(\\\\|\\"|[^"])*"', String), - (r"'" + valid_name, String.Symbol), - (r"#\\([()/'\".'_!ยง$%& ?=+-]{1}|[a-zA-Z0-9]+)", String.Char), - - # constants - (r'(#t|#f)', Name.Constant), - - # highlight keywords - ('(%s)' % '|'.join([ - re.escape(entry) + ' ' for entry in keywords]), - Keyword - ), - - # highlight builtins - ("(?<=\()(%s)" % '|'.join([ - re.escape(entry) + ' ' for entry in builtins]), - Name.Builtin - ), - - # remaining functions - (r'(?<=\()' + valid_name, Name.Function), - - # remaining variables - (valid_name, Name.Variable), - - # parenthesis - (r'(\(|\))', Punctuation), - ], - } - -class TuplrStyleDark(Style): - default_style = "#FFF" - background_color = "#222" - styles = { - Comment: '#79E', - Keyword: '#EE5', - Name: '#DDD', - Text: '#DDD', - String: '#F88', - Keyword.Type: '#5E5', - Punctuation: '#AAA', - Number: '#F88' - } - -class TuplrStyleLight(Style): - default_style = "#FFF" - background_color = "#EEE" - styles = { - Comment: '#57C', - Keyword: '#AA0', - Name: '#777', - Text: '#777', - String: '#D66', - Keyword.Type: '#3C3', - Punctuation: '#888', - Number: '#D66' - } - -if len(sys.argv) != 3: - print 'USAGE: %s IN OUT' % sys.argv[0] - sys.exit(1) - -infile = open(sys.argv[1], 'r') -text = infile.read() -infile.close() - - -if re.match('.*\.html$', sys.argv[2]): - style = TuplrStyleDark - formatter = HtmlFormatter(style=style) -elif re.match('.*\.tex$', sys.argv[2]): - style = TuplrStyleLight - formatter = LatexFormatter(style=style) - -if re.match('.*\.html$', sys.argv[2]): - outfile = open(sys.argv[2], 'w') - print >>outfile, ''' - - - - %s - - - - ''' - print >>outfile, highlight(text, TuplrLexer(), formatter) - print >>outfile, ''' - - ''' - outfile.close() - -if re.match('.*\.tex$', sys.argv[2]): - outfile = open(sys.argv[2], 'w') - print >>outfile, '''\\documentclass[10pt]{article} -\\usepackage{fancyvrb} -\\usepackage{color}''' - print >>outfile, formatter.get_style_defs() - print >>outfile, '\\newcommand\\PYlambda{$\\lambda$}' - print >>outfile, '\\newcommand\\PYbiglambda{$\\Lambda$}' - print >>outfile, '\\begin{document}' - out = highlight(text, TuplrLexer(), formatter) - out = out.replace('[fn', '[@PYlambda') - out = out.replace('[Fn', '[@PYbiglambda') - print >>outfile, out - print >>outfile, '\\end{document}' - outfile.close() - -- cgit v1.2.1