rouge 3.6.0 → 3.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/lib/rouge/demos/ada +26 -0
- data/lib/rouge/demos/apex +9 -0
- data/lib/rouge/demos/armasm +12 -0
- data/lib/rouge/demos/batchfile +3 -0
- data/lib/rouge/demos/bbcbasic +6 -0
- data/lib/rouge/demos/clean +6 -0
- data/lib/rouge/demos/cmhg +8 -0
- data/lib/rouge/demos/csvs +8 -0
- data/lib/rouge/demos/cuda +11 -0
- data/lib/rouge/demos/cython +6 -0
- data/lib/rouge/demos/eex +1 -0
- data/lib/rouge/demos/epp +4 -0
- data/lib/rouge/demos/gdscript +18 -0
- data/lib/rouge/demos/haxe +5 -0
- data/lib/rouge/demos/hocon +8 -0
- data/lib/rouge/demos/hql +5 -0
- data/lib/rouge/demos/jsl +3 -0
- data/lib/rouge/demos/liquid +0 -1
- data/lib/rouge/demos/lustre +6 -0
- data/lib/rouge/demos/lutin +18 -0
- data/lib/rouge/demos/mason +22 -0
- data/lib/rouge/demos/minizinc +23 -0
- data/lib/rouge/demos/msgtrans +4 -0
- data/lib/rouge/demos/opentype_feature_file +6 -0
- data/lib/rouge/demos/plist +1 -132
- data/lib/rouge/demos/reasonml +12 -0
- data/lib/rouge/demos/robot_framework +27 -0
- data/lib/rouge/demos/sas +13 -0
- data/lib/rouge/demos/sparql +6 -0
- data/lib/rouge/demos/terraform +0 -15
- data/lib/rouge/formatters/html_line_table.rb +3 -1
- data/lib/rouge/formatters/tex.rb +14 -12
- data/lib/rouge/guessers/disambiguation.rb +17 -0
- data/lib/rouge/lexer.rb +3 -0
- data/lib/rouge/lexers/ada.rb +162 -0
- data/lib/rouge/lexers/apex.rb +126 -0
- data/lib/rouge/lexers/armasm.rb +145 -0
- data/lib/rouge/lexers/batchfile.rb +164 -0
- data/lib/rouge/lexers/bbcbasic.rb +112 -0
- data/lib/rouge/lexers/clean.rb +156 -0
- data/lib/rouge/lexers/cmhg.rb +34 -0
- data/lib/rouge/lexers/common_lisp.rb +1 -1
- data/lib/rouge/lexers/console.rb +1 -1
- data/lib/rouge/lexers/coq.rb +12 -9
- data/lib/rouge/lexers/cpp.rb +4 -1
- data/lib/rouge/lexers/csvs.rb +44 -0
- data/lib/rouge/lexers/cuda.rb +35 -0
- data/lib/rouge/lexers/cython.rb +151 -0
- data/lib/rouge/lexers/eex.rb +52 -0
- data/lib/rouge/lexers/elixir.rb +20 -9
- data/lib/rouge/lexers/epp.rb +51 -0
- data/lib/rouge/lexers/escape.rb +3 -0
- data/lib/rouge/lexers/gdscript.rb +171 -0
- data/lib/rouge/lexers/gherkin.rb +4 -2
- data/lib/rouge/lexers/graphql.rb +10 -3
- data/lib/rouge/lexers/handlebars.rb +14 -3
- data/lib/rouge/lexers/haxe.rb +246 -0
- data/lib/rouge/lexers/hocon.rb +86 -0
- data/lib/rouge/lexers/hql.rb +139 -0
- data/lib/rouge/lexers/html.rb +2 -2
- data/lib/rouge/lexers/http.rb +5 -5
- data/lib/rouge/lexers/igorpro.rb +1 -1
- data/lib/rouge/lexers/javascript.rb +1 -1
- data/lib/rouge/lexers/jsl.rb +55 -0
- data/lib/rouge/lexers/json.rb +43 -5
- data/lib/rouge/lexers/julia.rb +1 -1
- data/lib/rouge/lexers/kotlin.rb +21 -28
- data/lib/rouge/lexers/liquid.rb +82 -108
- data/lib/rouge/lexers/lustre.rb +79 -0
- data/lib/rouge/lexers/lutin.rb +33 -0
- data/lib/rouge/lexers/make.rb +39 -12
- data/lib/rouge/lexers/markdown.rb +7 -1
- data/lib/rouge/lexers/mason.rb +110 -0
- data/lib/rouge/lexers/matlab.rb +4 -2
- data/lib/rouge/lexers/matlab/builtins.yml +3515 -0
- data/lib/rouge/lexers/minizinc.rb +87 -0
- data/lib/rouge/lexers/msgtrans.rb +26 -0
- data/lib/rouge/lexers/ocaml.rb +12 -48
- data/lib/rouge/lexers/ocaml/common.rb +53 -0
- data/lib/rouge/lexers/opentype_feature_file.rb +113 -0
- data/lib/rouge/lexers/perl.rb +1 -1
- data/lib/rouge/lexers/php.rb +31 -9
- data/lib/rouge/lexers/php/builtins.rb +181 -174
- data/lib/rouge/lexers/plain_text.rb +1 -1
- data/lib/rouge/lexers/puppet.rb +2 -2
- data/lib/rouge/lexers/q.rb +1 -1
- data/lib/rouge/lexers/r.rb +2 -3
- data/lib/rouge/lexers/reasonml.rb +65 -0
- data/lib/rouge/lexers/robot_framework.rb +249 -0
- data/lib/rouge/lexers/rust.rb +12 -9
- data/lib/rouge/lexers/sas.rb +563 -0
- data/lib/rouge/lexers/sed.rb +1 -1
- data/lib/rouge/lexers/shell.rb +5 -3
- data/lib/rouge/lexers/smarty.rb +10 -10
- data/lib/rouge/lexers/sparql.rb +129 -0
- data/lib/rouge/lexers/sql.rb +26 -6
- data/lib/rouge/lexers/swift.rb +1 -1
- data/lib/rouge/lexers/terraform.rb +8 -0
- data/lib/rouge/plugins/redcarpet.rb +7 -1
- data/lib/rouge/tex_theme_renderer.rb +5 -1
- data/lib/rouge/themes/magritte.rb +3 -3
- data/lib/rouge/themes/thankful_eyes.rb +1 -1
- data/lib/rouge/themes/tulip.rb +1 -1
- data/lib/rouge/version.rb +1 -1
- data/rouge.gemspec +4 -3
- metadata +63 -6
- data/lib/rouge/lexers/matlab/builtins.rb +0 -13
@@ -0,0 +1,51 @@
|
|
1
|
+
# -*- coding: utf-8 -*- #
|
2
|
+
|
3
|
+
module Rouge
|
4
|
+
module Lexers
|
5
|
+
class EPP < TemplateLexer
|
6
|
+
title "EPP"
|
7
|
+
desc "Embedded Puppet template files"
|
8
|
+
|
9
|
+
tag 'epp'
|
10
|
+
|
11
|
+
filenames '*.epp'
|
12
|
+
|
13
|
+
def initialize(opts={})
|
14
|
+
super(opts)
|
15
|
+
@parent = lexer_option(:parent) { PlainText.new(opts) }
|
16
|
+
@puppet_lexer = Puppet.new(opts)
|
17
|
+
end
|
18
|
+
|
19
|
+
start do
|
20
|
+
parent.reset!
|
21
|
+
@puppet_lexer.reset!
|
22
|
+
end
|
23
|
+
|
24
|
+
open = /<%%|<%=|<%#|(<%-|<%)(\s*\|)?/
|
25
|
+
close = /%%>|(\|\s*)?(-%>|%>)/
|
26
|
+
|
27
|
+
state :root do
|
28
|
+
rule %r/<%#/, Comment, :comment
|
29
|
+
|
30
|
+
rule open, Comment::Preproc, :puppet
|
31
|
+
|
32
|
+
rule %r/.+?(?=#{open})|.+/m do
|
33
|
+
delegate parent
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
state :comment do
|
38
|
+
rule close, Comment, :pop!
|
39
|
+
rule %r/.+?(?=#{close})|.+/m, Comment
|
40
|
+
end
|
41
|
+
|
42
|
+
state :puppet do
|
43
|
+
rule close, Comment::Preproc, :pop!
|
44
|
+
|
45
|
+
rule %r/.+?(?=#{close})|.+/m do
|
46
|
+
delegate @puppet_lexer
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/rouge/lexers/escape.rb
CHANGED
@@ -0,0 +1,171 @@
|
|
1
|
+
# -*- coding: utf-8 -*- #
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Rouge
|
5
|
+
module Lexers
|
6
|
+
class GDScript < RegexLexer
|
7
|
+
title "GDScript"
|
8
|
+
desc "The Godot Engine programming language (https://godotengine.org/)"
|
9
|
+
tag 'gdscript'
|
10
|
+
aliases 'gd', 'gdscript'
|
11
|
+
filenames '*.gd'
|
12
|
+
mimetypes 'text/x-gdscript', 'application/x-gdscript'
|
13
|
+
|
14
|
+
def self.keywords
|
15
|
+
@keywords = %w(
|
16
|
+
and in not or as breakpoint class class_name extends is func setget
|
17
|
+
signal tool const enum export onready static var break continue
|
18
|
+
if elif else for pass return match while remote master puppet
|
19
|
+
remotesync mastersync puppetsync
|
20
|
+
).join('|')
|
21
|
+
end
|
22
|
+
|
23
|
+
# Reserved for future implementation
|
24
|
+
def self.keywords_reserved
|
25
|
+
@keywords_reserved = %w(
|
26
|
+
do switch case
|
27
|
+
).join('|')
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.builtins
|
31
|
+
builtins = %w(
|
32
|
+
Color8 ColorN abs acos asin assert atan atan2 bytes2var ceil char
|
33
|
+
clamp convert cos cosh db2linear decimals dectime deg2rad dict2inst
|
34
|
+
ease exp floor fmod fposmod funcref hash inst2dict instance_from_id
|
35
|
+
is_inf is_nan lerp linear2db load log max min nearest_po2 pow
|
36
|
+
preload print print_stack printerr printraw prints printt rad2deg
|
37
|
+
rand_range rand_seed randf randi randomize range round seed sign
|
38
|
+
sin sinh sqrt stepify str str2var tan tan tanh type_exist typeof
|
39
|
+
var2bytes var2str weakref yield
|
40
|
+
).join('|')
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.builtins_type
|
44
|
+
@builtins_type = %w(
|
45
|
+
bool int float String Vector2 Rect2 Transform2D Vector3 AABB
|
46
|
+
Plane Quat Basis Transform Color RID Object NodePath Dictionary
|
47
|
+
Array PoolByteArray PoolIntArray PoolRealArray PoolStringArray
|
48
|
+
PoolVector2Array PoolVector3Array PoolColorArray null
|
49
|
+
).join('|')
|
50
|
+
end
|
51
|
+
|
52
|
+
state :root do
|
53
|
+
rule %r/\n/, Text
|
54
|
+
rule %r/[^\S\n]+/, Text
|
55
|
+
rule %r/#.*/, Comment::Single
|
56
|
+
rule %r/[\[\]{}:(),;]/, Punctuation
|
57
|
+
rule %r/\\\n/, Text
|
58
|
+
rule %r/(in|and|or|not)\b/, Operator::Word
|
59
|
+
rule %r/!=|==|<<|>>|&&|\+=|-=|\*=|\/=|%=|&=|\|=|\|\||[-~+\/*%=<>&^.!|$]/, Operator
|
60
|
+
rule %r/(func)((?:\s|\\)+)/ do
|
61
|
+
groups Keyword, Text
|
62
|
+
push :funcname
|
63
|
+
end
|
64
|
+
rule %r/(class)((?:\s|\\)+)/ do
|
65
|
+
groups Keyword, Text
|
66
|
+
push :classname
|
67
|
+
end
|
68
|
+
mixin :keywords
|
69
|
+
mixin :builtins
|
70
|
+
rule %r/"""/, Str::Double, :escape_tdqs
|
71
|
+
rule %r/'''/, Str::Double, :escape_tsqs
|
72
|
+
rule %r/"/, Str::Double, :escape_dqs
|
73
|
+
rule %r/'/, Str::Double, :escape_sqs
|
74
|
+
mixin :name
|
75
|
+
mixin :numbers
|
76
|
+
end
|
77
|
+
|
78
|
+
state :keywords do
|
79
|
+
rule %r/\b(#{GDScript.keywords})\b/, Keyword
|
80
|
+
rule %r/\b(#{GDScript.keywords_reserved})\b/, Keyword::Reserved
|
81
|
+
end
|
82
|
+
|
83
|
+
state :builtins do
|
84
|
+
rule %r/\b(#{GDScript.builtins})\b/, Name::Builtin
|
85
|
+
rule %r/\b((self|false|true)|(PI|TAU|NAN|INF))\b/, Name::Builtin::Pseudo
|
86
|
+
rule %r/\b(#{GDScript.builtins_type})\b/, Keyword::Type
|
87
|
+
end
|
88
|
+
|
89
|
+
state :numbers do
|
90
|
+
rule %r/(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?j?/, Num::Float
|
91
|
+
rule %r/\d+[eE][+-]?[0-9]+j?/, Num::Float
|
92
|
+
rule %r/0[xX][a-fA-F0-9]+/, Num::Hex
|
93
|
+
rule %r/\d+j?/, Num::Integer
|
94
|
+
end
|
95
|
+
|
96
|
+
state :name do
|
97
|
+
rule %r/[a-zA-Z_]\w*/, Name
|
98
|
+
end
|
99
|
+
|
100
|
+
state :funcname do
|
101
|
+
rule %r/[a-zA-Z_]\w*/, Name::Function, :pop!
|
102
|
+
end
|
103
|
+
|
104
|
+
state :classname do
|
105
|
+
rule %r/[a-zA-Z_]\w*/, Name::Class, :pop!
|
106
|
+
end
|
107
|
+
|
108
|
+
state :string_escape do
|
109
|
+
rule %r/\\([\\abfnrtv"\']|\n|N\{.*?\}|u[a-fA-F0-9]{4}|U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})/, Str::Escape
|
110
|
+
end
|
111
|
+
|
112
|
+
state :strings_single do
|
113
|
+
rule %r/%(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?[hlL]?[E-GXc-giorsux%]/, Str::Interpol
|
114
|
+
rule %r/[^\\'%\n]+/, Str::Single
|
115
|
+
rule %r/["\\]/, Str::Single
|
116
|
+
rule %r/%/, Str::Single
|
117
|
+
end
|
118
|
+
|
119
|
+
state :strings_double do
|
120
|
+
rule %r/%(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?[hlL]?[E-GXc-giorsux%]/, Str::Interpol
|
121
|
+
rule %r/[^\\"%\n]+/, Str::Double
|
122
|
+
rule %r/['\\]/, Str::Double
|
123
|
+
rule %r/%/, Str::Double
|
124
|
+
end
|
125
|
+
|
126
|
+
state :dqs do
|
127
|
+
rule %r/"/, Str::Double, :pop!
|
128
|
+
rule %r/\\\\|\\"|\\\n/, Str::Escape
|
129
|
+
mixin :strings_double
|
130
|
+
end
|
131
|
+
|
132
|
+
state :escape_dqs do
|
133
|
+
mixin :string_escape
|
134
|
+
mixin :dqs
|
135
|
+
end
|
136
|
+
|
137
|
+
state :sqs do
|
138
|
+
rule %r/'/, Str::Single, :pop!
|
139
|
+
rule %r/\\\\|\\'|\\\n/, Str::Escape
|
140
|
+
mixin :strings_single
|
141
|
+
end
|
142
|
+
|
143
|
+
state :escape_sqs do
|
144
|
+
mixin :string_escape
|
145
|
+
mixin :sqs
|
146
|
+
end
|
147
|
+
|
148
|
+
state :tdqs do
|
149
|
+
rule %r/"""/, Str::Double, :pop!
|
150
|
+
mixin :strings_double
|
151
|
+
rule %r/\n/, Str::Double
|
152
|
+
end
|
153
|
+
|
154
|
+
state :escape_tdqs do
|
155
|
+
mixin :string_escape
|
156
|
+
mixin :tdqs
|
157
|
+
end
|
158
|
+
|
159
|
+
state :tsqs do
|
160
|
+
rule %r/'''/, Str::Single, :pop!
|
161
|
+
mixin :strings_single
|
162
|
+
rule %r/\n/, Str::Single
|
163
|
+
end
|
164
|
+
|
165
|
+
state :escape_tsqs do
|
166
|
+
mixin :string_escape
|
167
|
+
mixin :tsqs
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
data/lib/rouge/lexers/gherkin.rb
CHANGED
@@ -8,7 +8,7 @@ module Rouge
|
|
8
8
|
aliases 'cucumber', 'behat'
|
9
9
|
|
10
10
|
title "Gherkin"
|
11
|
-
desc 'A business-readable spec DSL (
|
11
|
+
desc 'A business-readable spec DSL (github.com/cucumber/cucumber/wiki/Gherkin)'
|
12
12
|
|
13
13
|
filenames '*.feature'
|
14
14
|
mimetypes 'text/x-gherkin'
|
@@ -30,6 +30,8 @@ module Rouge
|
|
30
30
|
keywords[:step].map do |w|
|
31
31
|
if w.end_with? '<'
|
32
32
|
Regexp.escape(w.chop)
|
33
|
+
elsif w.end_with?(' ')
|
34
|
+
Regexp.escape(w)
|
33
35
|
else
|
34
36
|
"#{Regexp.escape(w)}\\b"
|
35
37
|
end
|
@@ -130,7 +132,7 @@ module Rouge
|
|
130
132
|
mixin :basic
|
131
133
|
rule %r/<.*?>/, Name::Variable
|
132
134
|
rule %r/".*?"/, Str
|
133
|
-
rule %r/\S
|
135
|
+
rule %r/\S[^\s<]*/, Text
|
134
136
|
rule rest_of_line, Text, :pop!
|
135
137
|
end
|
136
138
|
end
|
data/lib/rouge/lexers/graphql.rb
CHANGED
@@ -20,19 +20,26 @@ module Rouge
|
|
20
20
|
end
|
21
21
|
|
22
22
|
rule %r/\bfragment\b/, Keyword, :fragment_definition
|
23
|
+
|
24
|
+
rule %r/\bscalar\b/, Keyword, :value
|
23
25
|
|
24
26
|
rule %r/\b(?:type|interface|enum)\b/, Keyword, :type_definition
|
27
|
+
|
25
28
|
rule %r/\b(?:input|schema)\b/, Keyword, :type_definition
|
26
29
|
|
27
30
|
rule %r/\bunion\b/, Keyword, :union_definition
|
28
31
|
|
32
|
+
rule %r/\bextend\b/, Keyword
|
33
|
+
|
29
34
|
mixin :basic
|
30
35
|
|
31
36
|
# Markdown descriptions
|
32
|
-
rule %r/(""")(.*?)(""")/m do |m|
|
37
|
+
rule %r/(""")(\n)(.*?)(\n)(""")/m do |m|
|
33
38
|
token Str::Double, m[1]
|
34
|
-
|
35
|
-
|
39
|
+
token Text::Whitespace, m[2]
|
40
|
+
delegate Markdown, m[3]
|
41
|
+
token Text::Whitespace, m[4]
|
42
|
+
token Str::Double, m[5]
|
36
43
|
end
|
37
44
|
end
|
38
45
|
|
@@ -27,7 +27,15 @@ module Rouge
|
|
27
27
|
push :open_sym
|
28
28
|
end
|
29
29
|
|
30
|
-
rule(/(.+?)(?=\\|{{)/m)
|
30
|
+
rule(/(.+?)(?=\\|{{)/m) do
|
31
|
+
delegate parent
|
32
|
+
|
33
|
+
# if parent state is attr, then we have an html attribute without quotes
|
34
|
+
# pop the parent state to return to the tag state
|
35
|
+
if parent.state?('attr')
|
36
|
+
parent.pop!
|
37
|
+
end
|
38
|
+
end
|
31
39
|
|
32
40
|
# if we get here, there's no more mustache tags, so we eat
|
33
41
|
# the rest of the doc
|
@@ -43,9 +51,12 @@ module Rouge
|
|
43
51
|
|
44
52
|
state :stache do
|
45
53
|
rule %r/}}}?/, Keyword, :pop!
|
54
|
+
rule %r/\|/, Punctuation
|
55
|
+
rule %r/~/, Keyword
|
46
56
|
rule %r/\s+/m, Text
|
47
57
|
rule %r/[=]/, Operator
|
48
58
|
rule %r/[\[\]]/, Punctuation
|
59
|
+
rule %r/[\(\)]/, Punctuation
|
49
60
|
rule %r/[.](?=[}\s])/, Name::Variable
|
50
61
|
rule %r/[.][.]/, Name::Variable
|
51
62
|
rule %r([/.]), Punctuation
|
@@ -65,7 +76,7 @@ module Rouge
|
|
65
76
|
goto :block_name
|
66
77
|
end
|
67
78
|
|
68
|
-
rule %r/[
|
79
|
+
rule %r/[>^&~]/, Keyword
|
69
80
|
|
70
81
|
rule(//) { pop! }
|
71
82
|
end
|
@@ -77,4 +88,4 @@ module Rouge
|
|
77
88
|
end
|
78
89
|
end
|
79
90
|
end
|
80
|
-
end
|
91
|
+
end
|
@@ -0,0 +1,246 @@
|
|
1
|
+
# -*- coding: utf-8 -*- #
|
2
|
+
|
3
|
+
module Rouge
|
4
|
+
module Lexers
|
5
|
+
class Haxe < RegexLexer
|
6
|
+
title "Haxe"
|
7
|
+
desc "Haxe Cross-platform Toolkit (http://haxe.org)"
|
8
|
+
|
9
|
+
tag 'haxe'
|
10
|
+
aliases 'hx', 'haxe'
|
11
|
+
filenames '*.hx'
|
12
|
+
mimetypes 'text/haxe', 'text/x-haxe', 'text/x-hx'
|
13
|
+
|
14
|
+
def self.detect?(text)
|
15
|
+
return true if text.shebang? "haxe"
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.keywords
|
19
|
+
@keywords ||= Set.new %w(
|
20
|
+
break case cast catch class continue default do else enum false for
|
21
|
+
function if import interface macro new null override package private
|
22
|
+
public return switch this throw true try untyped while
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.imports
|
27
|
+
@imports ||= Set.new %w(
|
28
|
+
import using
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.declarations
|
33
|
+
@declarations ||= Set.new %w(
|
34
|
+
abstract dynamic extern extends from implements inline static to
|
35
|
+
typedef var
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.reserved
|
40
|
+
@reserved ||= Set.new %w(
|
41
|
+
super trace inline build autoBuild enum
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.constants
|
46
|
+
@constants ||= Set.new %w(true false null)
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.builtins
|
50
|
+
@builtins ||= %w(
|
51
|
+
Void Dynamic Math Class Any Float Int UInt String StringTools Sys
|
52
|
+
EReg isNaN parseFloat parseInt this Array Map Date DateTools Bool
|
53
|
+
Lambda Reflect Std File FileSystem
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
id = /[$a-zA-Z_][a-zA-Z0-9_]*/
|
58
|
+
|
59
|
+
state :comments_and_whitespace do
|
60
|
+
rule %r/\s+/, Text
|
61
|
+
rule %r(//.*?$), Comment::Single
|
62
|
+
rule %r(/\*.*?\*/)m, Comment::Multiline
|
63
|
+
end
|
64
|
+
|
65
|
+
state :expr_start do
|
66
|
+
mixin :comments_and_whitespace
|
67
|
+
|
68
|
+
rule %r/#(?:if|elseif|else|end).*/, Comment::Preproc
|
69
|
+
|
70
|
+
rule %r(~) do
|
71
|
+
token Str::Regex
|
72
|
+
goto :regex
|
73
|
+
end
|
74
|
+
|
75
|
+
rule %r/[{]/, Punctuation, :object
|
76
|
+
|
77
|
+
rule %r//, Text, :pop!
|
78
|
+
end
|
79
|
+
|
80
|
+
state :regex do
|
81
|
+
rule %r(/) do
|
82
|
+
token Str::Regex
|
83
|
+
goto :regex_end
|
84
|
+
end
|
85
|
+
|
86
|
+
rule %r([^/]\n), Error, :pop!
|
87
|
+
|
88
|
+
rule %r/\n/, Error, :pop!
|
89
|
+
rule %r/\[\^/, Str::Escape, :regex_group
|
90
|
+
rule %r/\[/, Str::Escape, :regex_group
|
91
|
+
rule %r/\\./, Str::Escape
|
92
|
+
rule %r{[(][?][:=<!]}, Str::Escape
|
93
|
+
rule %r/[{][\d,]+[}]/, Str::Escape
|
94
|
+
rule %r/[()?]/, Str::Escape
|
95
|
+
rule %r/./, Str::Regex
|
96
|
+
end
|
97
|
+
|
98
|
+
state :regex_end do
|
99
|
+
rule %r/[gim]+/, Str::Regex, :pop!
|
100
|
+
rule(//) { pop! }
|
101
|
+
end
|
102
|
+
|
103
|
+
state :regex_group do
|
104
|
+
# specially highlight / in a group to indicate that it doesn't
|
105
|
+
# close the regex
|
106
|
+
rule %r/\//, Str::Escape
|
107
|
+
|
108
|
+
rule %r([^/]\n) do
|
109
|
+
token Error
|
110
|
+
pop! 2
|
111
|
+
end
|
112
|
+
|
113
|
+
rule %r/\]/, Str::Escape, :pop!
|
114
|
+
rule %r/\\./, Str::Escape
|
115
|
+
rule %r/./, Str::Regex
|
116
|
+
end
|
117
|
+
|
118
|
+
state :bad_regex do
|
119
|
+
rule %r/[^\n]+/, Error, :pop!
|
120
|
+
end
|
121
|
+
|
122
|
+
state :root do
|
123
|
+
rule %r/\n/, Text, :statement
|
124
|
+
rule %r(\{), Punctuation, :expr_start
|
125
|
+
|
126
|
+
mixin :comments_and_whitespace
|
127
|
+
|
128
|
+
rule %r/@/, Name::Decorator, :metadata
|
129
|
+
rule %r(\+\+ | -- | ~ | && | \|\| | \\(?=\n) | << | >> | ==
|
130
|
+
| != )x,
|
131
|
+
Operator, :expr_start
|
132
|
+
rule %r([-:<>+*%&|\^/!=]=?), Operator, :expr_start
|
133
|
+
rule %r/[(\[,]/, Punctuation, :expr_start
|
134
|
+
rule %r/;/, Punctuation, :statement
|
135
|
+
rule %r/[)\]}.]/, Punctuation
|
136
|
+
|
137
|
+
rule %r/[?]/ do
|
138
|
+
token Punctuation
|
139
|
+
push :ternary
|
140
|
+
push :expr_start
|
141
|
+
end
|
142
|
+
|
143
|
+
rule id do |m|
|
144
|
+
if self.class.keywords.include? m[0]
|
145
|
+
token Keyword
|
146
|
+
push :expr_start
|
147
|
+
elsif self.class.imports.include? m[0]
|
148
|
+
token Keyword
|
149
|
+
push :namespace
|
150
|
+
elsif self.class.declarations.include? m[0]
|
151
|
+
token Keyword::Declaration
|
152
|
+
push :expr_start
|
153
|
+
elsif self.class.reserved.include? m[0]
|
154
|
+
token Keyword::Reserved
|
155
|
+
elsif self.class.constants.include? m[0]
|
156
|
+
token Keyword::Constant
|
157
|
+
elsif self.class.builtins.include? m[0]
|
158
|
+
token Name::Builtin
|
159
|
+
else
|
160
|
+
token Name::Other
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
rule %r/\-?\d+\.\d+(?:[eE]\d+)?[fd]?/, Num::Float
|
165
|
+
rule %r/0x\h+/, Num::Hex
|
166
|
+
rule %r/\-?[0-9]+/, Num::Integer
|
167
|
+
rule %r/"/, Str::Double, :str_double
|
168
|
+
rule %r/'/, Str::Single, :str_single
|
169
|
+
end
|
170
|
+
|
171
|
+
# braced parts that aren't object literals
|
172
|
+
state :statement do
|
173
|
+
rule %r/(#{id})(\s*)(:)/ do
|
174
|
+
groups Name::Label, Text, Punctuation
|
175
|
+
end
|
176
|
+
|
177
|
+
mixin :expr_start
|
178
|
+
end
|
179
|
+
|
180
|
+
# object literals
|
181
|
+
state :object do
|
182
|
+
mixin :comments_and_whitespace
|
183
|
+
rule %r/[}]/ do
|
184
|
+
token Punctuation
|
185
|
+
goto :statement
|
186
|
+
end
|
187
|
+
|
188
|
+
rule %r/(#{id})(\s*)(:)/ do
|
189
|
+
groups Name::Attribute, Text, Punctuation
|
190
|
+
push :expr_start
|
191
|
+
end
|
192
|
+
|
193
|
+
rule %r/:/, Punctuation
|
194
|
+
mixin :root
|
195
|
+
end
|
196
|
+
|
197
|
+
state :metadata do
|
198
|
+
rule %r/(#{id})(\()?/ do |m|
|
199
|
+
groups Name::Decorator, Punctuation
|
200
|
+
pop! unless m[2]
|
201
|
+
end
|
202
|
+
rule %r/:#{id}(?:\.#{id})*/, Name::Decorator, :pop!
|
203
|
+
rule %r/\)/, Name::Decorator, :pop!
|
204
|
+
mixin :root
|
205
|
+
end
|
206
|
+
|
207
|
+
# ternary expressions, where <id>: is not a label!
|
208
|
+
state :ternary do
|
209
|
+
rule %r/:/ do
|
210
|
+
token Punctuation
|
211
|
+
goto :expr_start
|
212
|
+
end
|
213
|
+
|
214
|
+
mixin :root
|
215
|
+
end
|
216
|
+
|
217
|
+
state :str_double do
|
218
|
+
mixin :str_escape
|
219
|
+
rule %r/"/, Str::Double, :pop!
|
220
|
+
rule %r/[^\\"]+/, Str::Double
|
221
|
+
end
|
222
|
+
|
223
|
+
state :str_single do
|
224
|
+
mixin :str_escape
|
225
|
+
rule %r/'/, Str::Single, :pop!
|
226
|
+
rule %r/\$\$/, Str::Single
|
227
|
+
rule %r/\$#{id}/, Str::Interpol
|
228
|
+
rule %r/\$\{/, Str::Interpol, :str_interpol
|
229
|
+
rule %r/[^\\$']+/, Str::Single
|
230
|
+
end
|
231
|
+
|
232
|
+
state :str_escape do
|
233
|
+
rule %r/\\[\\tnr'"]/, Str::Escape
|
234
|
+
rule %r/\\[0-7]{3}/, Str::Escape
|
235
|
+
rule %r/\\x\h{2}/, Str::Escape
|
236
|
+
rule %r/\\u\h{4}/, Str::Escape
|
237
|
+
rule %r/\\u\{\h{1,6}\}/, Str::Escape
|
238
|
+
end
|
239
|
+
|
240
|
+
state :str_interpol do
|
241
|
+
rule %r/\}/, Str::Interpol, :pop!
|
242
|
+
mixin :root
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|