File: smalltalk.rb

package info (click to toggle)
ruby-rugments 1.0.0~beta8-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 820 kB
  • sloc: ruby: 10,293; makefile: 2
file content (114 lines) | stat: -rw-r--r-- 3,076 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
module Rugments
  module Lexers
    class Smalltalk < RegexLexer
      title 'Smalltalk'
      desc 'The Smalltalk programming language'

      tag 'smalltalk'
      aliases 'st', 'squeak'
      filenames '*.st'
      mimetypes 'text/x-smalltalk'

      ops = %r{[-+*/\\~<>=|&!?,@%]}

      state :root do
        rule /(<)(\w+:)(.*?)(>)/ do
          groups Punctuation, Keyword, Text, Punctuation
        end

        # mixin :squeak_fileout
        mixin :whitespaces
        mixin :method_definition
        rule /([|])([\w\s]*)([|])/ do
          groups Punctuation, Name::Variable, Punctuation
        end
        mixin :objects
        rule /\^|:=|_/, Operator

        rule /[)}\]]/, Punctuation, :after_object
        rule /[({\[!]/, Punctuation
      end

      state :method_definition do
        rule /([a-z]\w*:)(\s*)(\w+)/i do
          groups Name::Function, Text, Name::Variable
        end

        rule /^(\s*)(\b[a-z]\w*\b)(\s*)$/i do
          groups Text, Name::Function, Text
        end

        rule %r{^(\s*)(#{ops}+)(\s*)(\w+)(\s*)$} do
          groups Text, Name::Function, Text, Name::Variable, Text
        end
      end

      state :block_variables do
        mixin :whitespaces
        rule /(:)(\s*)(\w+)/ do
          groups Operator, Text, Name::Variable
        end

        rule /[|]/, Punctuation, :pop!

        rule(//) { pop! }
      end

      state :literals do
        rule /'(''|.)*?'/m, Str, :after_object
        rule /[$]./, Str::Char, :after_object
        rule /#[(]/, Str::Symbol, :parenth
        rule /(\d+r)?-?\d+(\.\d+)?(e-?\d+)?/,
             Num, :after_object
        rule /#("[^"]*"|#{ops}+|[\w:]+)/,
             Str::Symbol, :after_object
      end

      state :parenth do
        rule /[)]/ do
          token Str::Symbol
          goto :after_object
        end

        mixin :inner_parenth
      end

      state :inner_parenth do
        rule /#[(]/, Str::Symbol, :inner_parenth
        rule /[)]/, Str::Symbol, :pop!
        mixin :whitespaces
        mixin :literals
        rule /(#{ops}|[\w:])+/, Str::Symbol
      end

      state :whitespaces do
        rule /! !$/, Keyword # squeak chunk delimiter
        rule /\s+/m, Text
        rule /".*?"/m, Comment
      end

      state :objects do
        rule /\[/, Punctuation, :block_variables
        rule /(self|super|true|false|nil|thisContext)\b/,
             Name::Builtin::Pseudo, :after_object
        rule /[A-Z]\w*(?!:)\b/, Name::Class, :after_object
        rule /[a-z]\w*(?!:)\b/, Name::Variable, :after_object
        mixin :literals
      end

      state :after_object do
        mixin :whitespaces
        rule /(ifTrue|ifFalse|whileTrue|whileFalse|timesRepeat):/,
             Name::Builtin, :pop!
        rule /new(?!:)\b/, Name::Builtin
        rule /:=|_/, Operator, :pop!
        rule /[a-z]+\w*:/i, Name::Function, :pop!
        rule /[a-z]+\w*/i, Name::Function
        rule /#{ops}+/, Name::Function, :pop!
        rule /[.]/, Punctuation, :pop!
        rule /;/, Punctuation
        rule(//) { pop! }
      end
    end
  end
end