summaryrefslogtreecommitdiff
path: root/pygments/lexers/esoteric.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2014-09-19 21:14:43 +0200
committerGeorg Brandl <georg@python.org>2014-09-19 21:14:43 +0200
commit78a45160ef63837dbaa18f5a49e1bd342354705a (patch)
treeaf9e90aa4c12c951fb1a9405c7f735a7f8fbd9ae /pygments/lexers/esoteric.py
parentd1a7453489a4c29d3613e738ecec83bee816d3f2 (diff)
downloadpygments-78a45160ef63837dbaa18f5a49e1bd342354705a.tar.gz
reorganization of other.py, part 2
Diffstat (limited to 'pygments/lexers/esoteric.py')
-rw-r--r--pygments/lexers/esoteric.py64
1 files changed, 48 insertions, 16 deletions
diff --git a/pygments/lexers/esoteric.py b/pygments/lexers/esoteric.py
index 775945fd..2efc057b 100644
--- a/pygments/lexers/esoteric.py
+++ b/pygments/lexers/esoteric.py
@@ -9,15 +9,11 @@
:license: BSD, see LICENSE for details.
"""
-import re
-
-from pygments.lexer import RegexLexer, include, bygroups, using, \
- this, inherit, default, words
-from pygments.util import get_bool_opt
+from pygments.lexer import RegexLexer, include
from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
Number, Punctuation, Error
-__all__ = ['BrainfuckLexer', 'BefungeLexer']
+__all__ = ['BrainfuckLexer', 'BefungeLexer', 'RedcodeLexer']
class BrainfuckLexer(RegexLexer):
@@ -67,16 +63,52 @@ class BefungeLexer(RegexLexer):
tokens = {
'root': [
(r'[0-9a-f]', Number),
- (r'[\+\*/%!`-]', Operator), # Traditional math
- (r'[<>^v?\[\]rxjk]', Name.Variable), # Move, imperatives
- (r'[:\\$.,n]', Name.Builtin), # Stack ops, imperatives
+ (r'[\+\*/%!`-]', Operator), # Traditional math
+ (r'[<>^v?\[\]rxjk]', Name.Variable), # Move, imperatives
+ (r'[:\\$.,n]', Name.Builtin), # Stack ops, imperatives
(r'[|_mw]', Keyword),
- (r'[{}]', Name.Tag), # Befunge-98 stack ops
- (r'".*?"', String.Double), # Strings don't appear to allow escapes
- (r'\'.', String.Single), # Single character
- (r'[#;]', Comment), # Trampoline... depends on direction hit
- (r'[pg&~=@iotsy]', Keyword), # Misc
- (r'[()A-Z]', Comment), # Fingerprints
- (r'\s+', Text), # Whitespace doesn't matter
+ (r'[{}]', Name.Tag), # Befunge-98 stack ops
+ (r'".*?"', String.Double), # Strings don't appear to allow escapes
+ (r'\'.', String.Single), # Single character
+ (r'[#;]', Comment), # Trampoline... depends on direction hit
+ (r'[pg&~=@iotsy]', Keyword), # Misc
+ (r'[()A-Z]', Comment), # Fingerprints
+ (r'\s+', Text), # Whitespace doesn't matter
+ ],
+ }
+
+
+class RedcodeLexer(RegexLexer):
+ """
+ A simple Redcode lexer based on ICWS'94.
+ Contributed by Adam Blinkinsop <blinks@acm.org>.
+
+ .. versionadded:: 0.8
+ """
+ name = 'Redcode'
+ aliases = ['redcode']
+ filenames = ['*.cw']
+
+ opcodes = ('DAT', 'MOV', 'ADD', 'SUB', 'MUL', 'DIV', 'MOD',
+ 'JMP', 'JMZ', 'JMN', 'DJN', 'CMP', 'SLT', 'SPL',
+ 'ORG', 'EQU', 'END')
+ modifiers = ('A', 'B', 'AB', 'BA', 'F', 'X', 'I')
+
+ tokens = {
+ 'root': [
+ # Whitespace:
+ (r'\s+', Text),
+ (r';.*$', Comment.Single),
+ # Lexemes:
+ # Identifiers
+ (r'\b(%s)\b' % '|'.join(opcodes), Name.Function),
+ (r'\b(%s)\b' % '|'.join(modifiers), Name.Decorator),
+ (r'[A-Za-z_][A-Za-z_0-9]+', Name),
+ # Operators
+ (r'[-+*/%]', Operator),
+ (r'[#$@<>]', Operator), # mode
+ (r'[.,]', Punctuation), # mode
+ # Numbers
+ (r'[-+]?\d+', Number.Integer),
],
}