Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/smalltalk.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-07 06:07 +0000

1""" 

2 pygments.lexers.smalltalk 

3 ~~~~~~~~~~~~~~~~~~~~~~~~~ 

4 

5 Lexers for Smalltalk and related languages. 

6 

7 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS. 

8 :license: BSD, see LICENSE for details. 

9""" 

10 

11from pygments.lexer import RegexLexer, include, bygroups, default 

12from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ 

13 Number, Punctuation 

14 

15__all__ = ['SmalltalkLexer', 'NewspeakLexer'] 

16 

17 

18class SmalltalkLexer(RegexLexer): 

19 """ 

20 For Smalltalk syntax. 

21 Contributed by Stefan Matthias Aust. 

22 Rewritten by Nils Winter. 

23 

24 .. versionadded:: 0.10 

25 """ 

26 name = 'Smalltalk' 

27 url = 'http://www.smalltalk.org/' 

28 filenames = ['*.st'] 

29 aliases = ['smalltalk', 'squeak', 'st'] 

30 mimetypes = ['text/x-smalltalk'] 

31 

32 tokens = { 

33 'root': [ 

34 (r'(<)(\w+:)(.*?)(>)', bygroups(Text, Keyword, Text, Text)), 

35 include('squeak fileout'), 

36 include('whitespaces'), 

37 include('method definition'), 

38 (r'(\|)([\w\s]*)(\|)', bygroups(Operator, Name.Variable, Operator)), 

39 include('objects'), 

40 (r'\^|\:=|\_', Operator), 

41 # temporaries 

42 (r'[\]({}.;!]', Text), 

43 ], 

44 'method definition': [ 

45 # Not perfect can't allow whitespaces at the beginning and the 

46 # without breaking everything 

47 (r'([a-zA-Z]+\w*:)(\s*)(\w+)', 

48 bygroups(Name.Function, Text, Name.Variable)), 

49 (r'^(\b[a-zA-Z]+\w*\b)(\s*)$', bygroups(Name.Function, Text)), 

50 (r'^([-+*/\\~<>=|&!?,@%]+)(\s*)(\w+)(\s*)$', 

51 bygroups(Name.Function, Text, Name.Variable, Text)), 

52 ], 

53 'blockvariables': [ 

54 include('whitespaces'), 

55 (r'(:)(\s*)(\w+)', 

56 bygroups(Operator, Text, Name.Variable)), 

57 (r'\|', Operator, '#pop'), 

58 default('#pop'), # else pop 

59 ], 

60 'literals': [ 

61 (r"'(''|[^'])*'", String, 'afterobject'), 

62 (r'\$.', String.Char, 'afterobject'), 

63 (r'#\(', String.Symbol, 'parenth'), 

64 (r'\)', Text, 'afterobject'), 

65 (r'(\d+r)?-?\d+(\.\d+)?(e-?\d+)?', Number, 'afterobject'), 

66 ], 

67 '_parenth_helper': [ 

68 include('whitespaces'), 

69 (r'(\d+r)?-?\d+(\.\d+)?(e-?\d+)?', Number), 

70 (r'[-+*/\\~<>=|&#!?,@%\w:]+', String.Symbol), 

71 # literals 

72 (r"'(''|[^'])*'", String), 

73 (r'\$.', String.Char), 

74 (r'#*\(', String.Symbol, 'inner_parenth'), 

75 ], 

76 'parenth': [ 

77 # This state is a bit tricky since 

78 # we can't just pop this state 

79 (r'\)', String.Symbol, ('root', 'afterobject')), 

80 include('_parenth_helper'), 

81 ], 

82 'inner_parenth': [ 

83 (r'\)', String.Symbol, '#pop'), 

84 include('_parenth_helper'), 

85 ], 

86 'whitespaces': [ 

87 # skip whitespace and comments 

88 (r'\s+', Text), 

89 (r'"(""|[^"])*"', Comment), 

90 ], 

91 'objects': [ 

92 (r'\[', Text, 'blockvariables'), 

93 (r'\]', Text, 'afterobject'), 

94 (r'\b(self|super|true|false|nil|thisContext)\b', 

95 Name.Builtin.Pseudo, 'afterobject'), 

96 (r'\b[A-Z]\w*(?!:)\b', Name.Class, 'afterobject'), 

97 (r'\b[a-z]\w*(?!:)\b', Name.Variable, 'afterobject'), 

98 (r'#("(""|[^"])*"|[-+*/\\~<>=|&!?,@%]+|[\w:]+)', 

99 String.Symbol, 'afterobject'), 

100 include('literals'), 

101 ], 

102 'afterobject': [ 

103 (r'! !$', Keyword, '#pop'), # squeak chunk delimiter 

104 include('whitespaces'), 

105 (r'\b(ifTrue:|ifFalse:|whileTrue:|whileFalse:|timesRepeat:)', 

106 Name.Builtin, '#pop'), 

107 (r'\b(new\b(?!:))', Name.Builtin), 

108 (r'\:=|\_', Operator, '#pop'), 

109 (r'\b[a-zA-Z]+\w*:', Name.Function, '#pop'), 

110 (r'\b[a-zA-Z]+\w*', Name.Function), 

111 (r'\w+:?|[-+*/\\~<>=|&!?,@%]+', Name.Function, '#pop'), 

112 (r'\.', Punctuation, '#pop'), 

113 (r';', Punctuation), 

114 (r'[\])}]', Text), 

115 (r'[\[({]', Text, '#pop'), 

116 ], 

117 'squeak fileout': [ 

118 # Squeak fileout format (optional) 

119 (r'^"(""|[^"])*"!', Keyword), 

120 (r"^'(''|[^'])*'!", Keyword), 

121 (r'^(!)(\w+)( commentStamp: )(.*?)( prior: .*?!\n)(.*?)(!)', 

122 bygroups(Keyword, Name.Class, Keyword, String, Keyword, Text, Keyword)), 

123 (r"^(!)(\w+(?: class)?)( methodsFor: )('(?:''|[^'])*')(.*?!)", 

124 bygroups(Keyword, Name.Class, Keyword, String, Keyword)), 

125 (r'^(\w+)( subclass: )(#\w+)' 

126 r'(\s+instanceVariableNames: )(.*?)' 

127 r'(\s+classVariableNames: )(.*?)' 

128 r'(\s+poolDictionaries: )(.*?)' 

129 r'(\s+category: )(.*?)(!)', 

130 bygroups(Name.Class, Keyword, String.Symbol, Keyword, String, Keyword, 

131 String, Keyword, String, Keyword, String, Keyword)), 

132 (r'^(\w+(?: class)?)(\s+instanceVariableNames: )(.*?)(!)', 

133 bygroups(Name.Class, Keyword, String, Keyword)), 

134 (r'(!\n)(\].*)(! !)$', bygroups(Keyword, Text, Keyword)), 

135 (r'! !$', Keyword), 

136 ], 

137 } 

138 

139 

140class NewspeakLexer(RegexLexer): 

141 """ 

142 For Newspeak syntax. 

143 

144 .. versionadded:: 1.1 

145 """ 

146 name = 'Newspeak' 

147 url = 'http://newspeaklanguage.org/' 

148 filenames = ['*.ns2'] 

149 aliases = ['newspeak', ] 

150 mimetypes = ['text/x-newspeak'] 

151 

152 tokens = { 

153 'root': [ 

154 (r'\b(Newsqueak2)\b', Keyword.Declaration), 

155 (r"'[^']*'", String), 

156 (r'\b(class)(\s+)(\w+)(\s*)', 

157 bygroups(Keyword.Declaration, Text, Name.Class, Text)), 

158 (r'\b(mixin|self|super|private|public|protected|nil|true|false)\b', 

159 Keyword), 

160 (r'(\w+\:)(\s*)([a-zA-Z_]\w+)', 

161 bygroups(Name.Function, Text, Name.Variable)), 

162 (r'(\w+)(\s*)(=)', 

163 bygroups(Name.Attribute, Text, Operator)), 

164 (r'<\w+>', Comment.Special), 

165 include('expressionstat'), 

166 include('whitespace') 

167 ], 

168 

169 'expressionstat': [ 

170 (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float), 

171 (r'\d+', Number.Integer), 

172 (r':\w+', Name.Variable), 

173 (r'(\w+)(::)', bygroups(Name.Variable, Operator)), 

174 (r'\w+:', Name.Function), 

175 (r'\w+', Name.Variable), 

176 (r'\(|\)', Punctuation), 

177 (r'\[|\]', Punctuation), 

178 (r'\{|\}', Punctuation), 

179 

180 (r'(\^|\+|\/|~|\*|<|>|=|@|%|\||&|\?|!|,|-|:)', Operator), 

181 (r'\.|;', Punctuation), 

182 include('whitespace'), 

183 include('literals'), 

184 ], 

185 'literals': [ 

186 (r'\$.', String), 

187 (r"'[^']*'", String), 

188 (r"#'[^']*'", String.Symbol), 

189 (r"#\w+:?", String.Symbol), 

190 (r"#(\+|\/|~|\*|<|>|=|@|%|\||&|\?|!|,|-)+", String.Symbol) 

191 ], 

192 'whitespace': [ 

193 (r'\s+', Text), 

194 (r'"[^"]*"', Comment) 

195 ], 

196 }