diff options
author | gbrandl <devnull@localhost> | 2007-12-14 23:25:43 +0100 |
---|---|---|
committer | gbrandl <devnull@localhost> | 2007-12-14 23:25:43 +0100 |
commit | 0182784abdb8868be299135918a32cc5624dd573 (patch) | |
tree | 29f27fa6c1e760a9bea2a25a43ddeb2230782f71 | |
parent | 46be17df1fa6309d163f8721bfbc7320c75e4b40 (diff) | |
download | pygments-0182784abdb8868be299135918a32cc5624dd573.tar.gz |
Add Smalltalk lexer, #300.
-rwxr-xr-x | pygments/formatters/_mapping.py | 2 | ||||
-rw-r--r-- | pygments/lexers/_mapping.py | 3 | ||||
-rw-r--r-- | pygments/lexers/other.py | 74 | ||||
-rw-r--r-- | scripts/find_error.py | 7 |
4 files changed, 82 insertions, 4 deletions
diff --git a/pygments/formatters/_mapping.py b/pygments/formatters/_mapping.py index e2ed1a83..776bc4d3 100755 --- a/pygments/formatters/_mapping.py +++ b/pygments/formatters/_mapping.py @@ -33,7 +33,7 @@ FORMATTERS = { NullFormatter: ('Text only', ('text', 'null'), ('*.txt',), 'Output the text unchanged without any formatting.'), RawTokenFormatter: ('Raw tokens', ('raw', 'tokens'), ('*.raw',), 'Format tokens as a raw representation for storing token streams.'), RtfFormatter: ('RTF', ('rtf',), ('*.rtf',), 'Format tokens as RTF markup. This formatter automatically outputs full RTF documents with color information and other useful stuff. Perfect for Copy and Paste into Microsoft\xc2\xae Word\xc2\xae documents.'), - SvgFormatter: ('SVG', ('svg',), ('*.svg',), 'Format tokens as an SVG graphics file. This formatter is still experimental.'), + SvgFormatter: ('SVG', ('svg',), ('*.svg',), 'Format tokens as an SVG graphics file. This formatter is still experimental. Each line of code is a ``<text>`` element with explicit ``x`` and ``y`` coordinates containing ``<tspan>`` elements with the individual token styles.'), Terminal256Formatter: ('Terminal256', ('terminal256', 'console256', '256'), (), 'Format tokens with ANSI color sequences, for output in a 256-color terminal or console. Like in `TerminalFormatter` color sequences are terminated at newlines, so that paging the output works correctly.'), TerminalFormatter: ('Terminal', ('terminal', 'console'), (), 'Format tokens with ANSI color sequences, for output in a text console. Color sequences are terminated at newlines, so that paging the output works correctly.') } diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index 26905d9b..38cae698 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -26,7 +26,7 @@ LEXERS = { 'CObjdumpLexer': ('pygments.lexers.asm', 'c-objdump', ('c-objdump',), ('*.c-objdump',), ('text/x-c-objdump',)), 'CSharpLexer': ('pygments.lexers.dotnet', 'C#', ('csharp', 'c#'), ('*.cs',), ('text/x-csharp',)), 'CommonLispLexer': ('pygments.lexers.functional', 'Common Lisp', ('common-lisp', 'cl'), ('*.cl', '*.lisp', '*.el'), ('text/x-common-lisp',)), - 'CppLexer': ('pygments.lexers.compiled', 'C++', ('cpp', 'c++'), ('*.cpp', '*.hpp', '*.c++', '*.h++'), ('text/x-c++hdr', 'text/x-c++src')), + 'CppLexer': ('pygments.lexers.compiled', 'C++', ('cpp', 'c++'), ('*.cpp', '*.hpp', '*.c++', '*.h++', '*.cc', '*.hh', '*.cxx', '*.hxx'), ('text/x-c++hdr', 'text/x-c++src')), 'CppObjdumpLexer': ('pygments.lexers.asm', 'cpp-objdump', ('cpp-objdump', 'c++-objdumb', 'cxx-objdump'), ('*.cpp-objdump', '*.c++-objdump', '*.cxx-objdump'), ('text/x-cpp-objdump',)), 'CssDjangoLexer': ('pygments.lexers.templates', 'CSS+Django/Jinja', ('css+django', 'css+jinja'), (), ('text/css+django', 'text/css+jinja')), 'CssErbLexer': ('pygments.lexers.templates', 'CSS+Ruby', ('css+erb', 'css+ruby'), (), ('text/css+ruby',)), @@ -100,6 +100,7 @@ LEXERS = { 'RubyConsoleLexer': ('pygments.lexers.agile', 'Ruby irb session', ('rbcon', 'irb'), (), ('text/x-ruby-shellsession',)), 'RubyLexer': ('pygments.lexers.agile', 'Ruby', ('rb', 'ruby'), ('*.rb', '*.rbw', 'Rakefile', '*.rake', '*.gemspec', '*.rbx'), ('text/x-ruby', 'application/x-ruby')), 'SchemeLexer': ('pygments.lexers.functional', 'Scheme', ('scheme', 'scm'), ('*.scm',), ('text/x-scheme', 'application/x-scheme')), + 'SmalltalkLexer': ('pygments.lexers.other', 'Smalltalk', ('smalltalk', 'squeak'), ('*.st',), ('text/x-smalltalk',)), 'SmartyLexer': ('pygments.lexers.templates', 'Smarty', ('smarty',), ('*.tpl',), ('application/x-smarty',)), 'SourcesListLexer': ('pygments.lexers.text', 'Debian Sourcelist', ('sourceslist', 'sources.list'), ('sources.list',), ()), 'SqlLexer': ('pygments.lexers.other', 'SQL', ('sql',), ('*.sql',), ('text/x-sql',)), diff --git a/pygments/lexers/other.py b/pygments/lexers/other.py index 6d2ecf20..3598b890 100644 --- a/pygments/lexers/other.py +++ b/pygments/lexers/other.py @@ -18,7 +18,8 @@ from pygments.util import shebang_matches __all__ = ['SqlLexer', 'MySqlLexer', 'BrainfuckLexer', 'BashLexer', - 'BatchLexer', 'BefungeLexer', 'RedcodeLexer', 'MOOCodeLexer'] + 'BatchLexer', 'BefungeLexer', 'RedcodeLexer', 'MOOCodeLexer', + 'SmalltalkLexer'] class SqlLexer(RegexLexer): @@ -469,3 +470,74 @@ class MOOCodeLexer(RegexLexer): (r'([a-zA-Z_0-9]+)', Text), ] } + +class SmalltalkLexer(RegexLexer): + """ + For `Smalltalk <http://www.smalltalk.org/>`_ syntax. + Contributed by Stefan Matthias Aust. + + *New in Pygments 1.0.* + """ + name = 'Smalltalk' + filenames = ['*.st'] + aliases = ['smalltalk', 'squeak'] + mimetypes = ['text/x-smalltalk'] + + tokens = { + 'root' : [ + # Squeak fileout format (optional) + (r'^"[^"]*"!', Keyword), + (r"^'[^']*'!", Keyword), + (r'^(!)(\w+)( commentStamp: )(.*?)( prior: .*?!\n)(.*?)(!)', + bygroups(Keyword, Name.Class, Keyword, String, Keyword, Text, Keyword)), + (r'^(!)(\w+(?: class)?)( methodsFor: )(\'[^\']*\')(.*?!)', + bygroups(Keyword, Name.Class, Keyword, String, Keyword)), + (r'^(\w+)( subclass: )(#\w+)' + r'(\s+instanceVariableNames: )(.*?)' + r'(\s+classVariableNames: )(.*?)' + r'(\s+poolDictionaries: )(.*?)' + r'(\s+category: )(.*?)(!)', + bygroups(Name.Class, Keyword, String.Symbol, Keyword, String, Keyword, + String, Keyword, String, Keyword, String, Keyword)), + (r'^(\w+(?: class)?)(\s+instanceVariableNames: )(.*?)(!)', + bygroups(Name.Class, Keyword, String, Keyword)), + (r'(!\n)(\].*)(! !)$', bygroups(Keyword, Text, Keyword)), + (r'! !$', Keyword), + # skip whitespace and comments + (r'\s+', Text), + (r'"[^"]*"', Comment), + # method patterns + (r'^(\w+)(\s*:\s*)(\w+\s*)', bygroups(Name.Function, Punctuation, + Name.Variable), 'pattern'), + (r'^([-+*/\\~<>=|&!?,@%]+\s*)(\w+)', bygroups(Name.Function, Name.Variable)), + (r'^(\w+)', Name.Function), + # literals + (r'\'[^\']*\'', String), + (r'\$.', String.Char), + (r'#\(', String.Symbol, 'parenth'), + (r'(\d+r)?-?\d+(\.\d+)?(e-?\d+)?', Number), + (r'#("[^"]*"|[-+*/\\~<>=|&!?,@%]+|[\w:]+)', String.Symbol), + # blocks variables + (r'(\[\s*)((?::\w+\s*)+)(\|)', bygroups(Text, Name.Variable, Text)), + # temporaries + (r'(\|)([\w\s]*)(\|)', bygroups(Operator, Name.Variable, Operator)), + # names + (r'\b(ifTrue:|ifFalse:|whileTrue:|whileFalse:|timesRepeat:)', Name.Builtin), + (r'\b(self|super)\b', Name.Builtin.Pseudo), + (r'\b[A-Z]\w*:', Name), + (r'\b[A-Z]\w*\b', Name), #Name.Class), + (r'\w+:?|[-+*/\\~<>=|&!?,@%]+', Name), #Name.Function), + # syntax + (r'\^|:=', Operator), + (r'[\[\](){}.;]', Text), + ], + 'parenth' : [ + (r'\)', String.Symbol, '#pop'), + include('root'), + ], + 'pattern' : [ + (r'(\w+)(\s*:\s*)(\w+\s*)', bygroups(Name.Function, Punctuation, + Name.Variable)), + (r'', Text, '#pop'), + ], + } diff --git a/scripts/find_error.py b/scripts/find_error.py index e210028a..a7719b3f 100644 --- a/scripts/find_error.py +++ b/scripts/find_error.py @@ -40,12 +40,17 @@ def main(fn): for type, val in lx.get_tokens(text): if type == Error: print "Error parsing", fn - print "\n".join([' ' + repr(x) for x in ntext[-5:]]) + print "\n".join([' ' + repr(x) for x in ntext[-num:]]) print `val` + "<<<" return ntext.append((type,val)) +num = 10 + if __name__ == "__main__": + if sys.argv[1][:2] == '-n': + num = int(sys.argv[1][2:]) + del sys.argv[1] for f in sys.argv[1:]: main(f) |