summaryrefslogtreecommitdiff
path: root/pygments
diff options
context:
space:
mode:
authorgbrandl <devnull@localhost>2008-11-16 17:17:26 +0100
committergbrandl <devnull@localhost>2008-11-16 17:17:26 +0100
commita67c6790451090a4b1a370775be1c73b86ab8e43 (patch)
treeae0e138e8b2da0a5753fcdc16098e78bffc97836 /pygments
parent8f36c075e766fe82259fdffa69acf45852bc0c0d (diff)
downloadpygments-a67c6790451090a4b1a370775be1c73b86ab8e43.tar.gz
#374: Update to SmalltalkLexer by Nils Winter.
Diffstat (limited to 'pygments')
-rw-r--r--pygments/lexers/other.py117
1 files changed, 80 insertions, 37 deletions
diff --git a/pygments/lexers/other.py b/pygments/lexers/other.py
index be9d3662..3f696898 100644
--- a/pygments/lexers/other.py
+++ b/pygments/lexers/other.py
@@ -532,6 +532,7 @@ class SmalltalkLexer(RegexLexer):
"""
For `Smalltalk <http://www.smalltalk.org/>`_ syntax.
Contributed by Stefan Matthias Aust.
+ Rewritten by Nils Winter.
*New in Pygments 0.10.*
"""
@@ -542,6 +543,85 @@ class SmalltalkLexer(RegexLexer):
tokens = {
'root' : [
+ (r'(<)(\w+:)(.*?)(>)', bygroups(Text, Keyword, Text, Text)),
+ include('squeak fileout'),
+ include('whitespaces'),
+ include('method definition'),
+ (r'(\|)([\w\s]*)(\|)', bygroups(Operator, Name.Variable, Operator)),
+ include('objects'),
+ (r'\^|\:=|\_', Operator),
+ # temporaries
+ (r'[\]({}.;!]', Text),
+
+ ],
+ 'method definition' : [
+ # Not perfect can't allow whitespaces at the beginning and the
+ # without breaking everything
+ (r'([a-zA-Z]+\w*:)(\s*)(\w+)', bygroups(Name.Function, Text, Name.Variable)),
+ (r'^(\b[a-zA-Z]+\w*\b)(\s*)$', bygroups(Name.Function, Text)),
+ (r'^([-+*/\\~<>=|&!?,@%]+)(\s*)(\w+)(\s*)$', bygroups(Name.Function, Text, Name.Variable, Text)),
+ ],
+ 'blockvariables' : [
+ include('whitespaces'),
+ (r'(:)(\s*)([A-Za-z\w]+)', bygroups(Operator, Text, Name.Variable)),
+ (r'\|', Operator, '#pop'),
+ (r'', Text, '#pop'), # else pop
+ ],
+ 'literals' : [
+ (r'\'[^\']*\'', String, 'afterobject'),
+ (r'\$.', String.Char, 'afterobject'),
+ (r'#\(', String.Symbol, 'parenth'),
+ (r'\)', Text, 'afterobject'),
+ (r'(\d+r)?-?\d+(\.\d+)?(e-?\d+)?', Number, 'afterobject'),
+ ],
+ '_parenth_helper' : [
+ include('whitespaces'),
+ (r'[-+*/\\~<>=|&#!?,@%\w+:]+', String.Symbol),
+ # literals
+ (r'\'[^\']*\'', String),
+ (r'\$.', String.Char),
+ (r'(\d+r)?-?\d+(\.\d+)?(e-?\d+)?', Number),
+ (r'#*\(', String.Symbol, 'inner_parenth'),
+ ],
+ 'parenth' : [
+ # This state is a bit tricky since
+ # we can't just pop this state
+ (r'\)', String.Symbol, ('root','afterobject')),
+ include('_parenth_helper'),
+ ],
+ 'inner_parenth': [
+ (r'\)', String.Symbol, '#pop'),
+ include('_parenth_helper'),
+ ],
+ 'whitespaces' : [
+ # skip whitespace and comments
+ (r'\s+', Text),
+ (r'"[^"]*"', Comment),
+ ],
+ 'objects' : [
+ (r'\[', Text, 'blockvariables'),
+ (r'\]', Text, 'afterobject'),
+ (r'\b(self|super|true|false|nil|thisContext)\b', Name.Builtin.Pseudo, 'afterobject'),
+ (r'\b[A-Z]\w*(?!:)\b', Name.Class, 'afterobject'),
+ (r'\b[a-z]\w*(?!:)\b', Name.Variable, 'afterobject'),
+ (r'#("[^"]*"|[-+*/\\~<>=|&!?,@%]+|[\w:]+)', String.Symbol, 'afterobject'),
+ include('literals'),
+ ],
+ 'afterobject' : [
+ (r'! !$', Keyword , '#pop'), # squeak chunk delimeter
+ include('whitespaces'),
+ (r'\b(ifTrue:|ifFalse:|whileTrue:|whileFalse:|timesRepeat:)', Name.Builtin, '#pop'),
+ (r'\b(new\b(?!:))', Name.Builtin),
+ (r'\:=|\_', Operator, '#pop'),
+ (r'\b[a-zA-Z]+\w*:', Name.Function, '#pop'),
+ (r'\b[a-zA-Z]+\w*', Name.Function),
+ (r'\w+:?|[-+*/\\~<>=|&!?,@%]+', Name.Function, '#pop'),
+ (r'\.', Punctuation, '#pop'),
+ (r';', Punctuation),
+ (r'[\])}]', Text),
+ (r'[\[({]', Text, '#pop'),
+ ],
+ 'squeak fileout' : [
# Squeak fileout format (optional)
(r'^"[^"]*"!', Keyword),
(r"^'[^']*'!", Keyword),
@@ -560,46 +640,9 @@ class SmalltalkLexer(RegexLexer):
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'),
],
}
-
class TcshLexer(RegexLexer):
"""
Lexer for tcsh scripts.