rouge 3.20.0 → 3.25.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rouge.rb +1 -0
  3. data/lib/rouge/cli.rb +32 -2
  4. data/lib/rouge/demos/brightscript +6 -0
  5. data/lib/rouge/demos/email +11 -0
  6. data/lib/rouge/demos/j +12 -0
  7. data/lib/rouge/demos/janet +3 -0
  8. data/lib/rouge/demos/postscript +9 -0
  9. data/lib/rouge/demos/ssh +4 -0
  10. data/lib/rouge/demos/systemd +4 -0
  11. data/lib/rouge/formatters/html_line_highlighter.rb +24 -0
  12. data/lib/rouge/formatters/html_line_table.rb +1 -3
  13. data/lib/rouge/formatters/html_linewise.rb +2 -3
  14. data/lib/rouge/lexer.rb +38 -20
  15. data/lib/rouge/lexers/apex.rb +9 -7
  16. data/lib/rouge/lexers/batchfile.rb +3 -2
  17. data/lib/rouge/lexers/brightscript.rb +147 -0
  18. data/lib/rouge/lexers/cpp.rb +6 -5
  19. data/lib/rouge/lexers/css.rb +3 -1
  20. data/lib/rouge/lexers/docker.rb +2 -2
  21. data/lib/rouge/lexers/elm.rb +5 -5
  22. data/lib/rouge/lexers/email.rb +39 -0
  23. data/lib/rouge/lexers/ghc_core.rb +2 -1
  24. data/lib/rouge/lexers/graphql.rb +1 -1
  25. data/lib/rouge/lexers/hack.rb +1 -1
  26. data/lib/rouge/lexers/html.rb +6 -6
  27. data/lib/rouge/lexers/http.rb +8 -2
  28. data/lib/rouge/lexers/isbl.rb +2 -2
  29. data/lib/rouge/lexers/j.rb +244 -0
  30. data/lib/rouge/lexers/janet.rb +218 -0
  31. data/lib/rouge/lexers/javascript.rb +11 -3
  32. data/lib/rouge/lexers/jinja.rb +22 -7
  33. data/lib/rouge/lexers/jsl.rb +1 -1
  34. data/lib/rouge/lexers/jsonnet.rb +4 -3
  35. data/lib/rouge/lexers/jsp.rb +2 -3
  36. data/lib/rouge/lexers/julia.rb +4 -2
  37. data/lib/rouge/lexers/kotlin.rb +8 -4
  38. data/lib/rouge/lexers/opentype_feature_file.rb +0 -1
  39. data/lib/rouge/lexers/perl.rb +27 -7
  40. data/lib/rouge/lexers/php.rb +274 -128
  41. data/lib/rouge/lexers/postscript.rb +93 -0
  42. data/lib/rouge/lexers/powershell.rb +41 -29
  43. data/lib/rouge/lexers/q.rb +1 -1
  44. data/lib/rouge/lexers/rego.rb +27 -12
  45. data/lib/rouge/lexers/ruby.rb +1 -1
  46. data/lib/rouge/lexers/rust.rb +5 -3
  47. data/lib/rouge/lexers/sass/common.rb +1 -0
  48. data/lib/rouge/lexers/smarty.rb +1 -1
  49. data/lib/rouge/lexers/ssh.rb +33 -0
  50. data/lib/rouge/lexers/systemd.rb +34 -0
  51. data/lib/rouge/lexers/twig.rb +4 -4
  52. data/lib/rouge/lexers/velocity.rb +1 -1
  53. data/lib/rouge/lexers/wollok.rb +0 -1
  54. data/lib/rouge/lexers/xml.rb +5 -3
  55. data/lib/rouge/lexers/yaml.rb +5 -3
  56. data/lib/rouge/regex_lexer.rb +56 -1
  57. data/lib/rouge/version.rb +1 -1
  58. metadata +17 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a0ad085dddf353cc95e795e5f556b4f2d9821068cceeeaab4cb34cb11f3ad776
4
- data.tar.gz: f70271022198b1d7e95df35d856274234720d54d4ef3f1a42c782246e2cf4c47
3
+ metadata.gz: 35d2eb9627935d1f4e510d66263bddb55773667d8a441677019a377abaf3784e
4
+ data.tar.gz: 04370e4428e5f4c30a552d455bbf5655beeae8bf3ddc68db09ba0fbf76fee3e9
5
5
  SHA512:
6
- metadata.gz: 473cfdc4ce0c458d0a7b0c3b1e6684723ceb7c15dea4d1080baf201786ecd149e9d21cd25f65735edbbf4b4f763a5d7d1854a4d909bef6902b7d609d30ebcc2b
7
- data.tar.gz: 579d31241b2fe8d4f2b9471dd6bb97b5621051811260d02b21a012e9e35ccf34d83e0e998981e959aa0ce6a1b00932c06f7ed8b8b093fde95d53c7a8ebbb67ce
6
+ metadata.gz: fc847dd05c6d47cdbcc4296b60594faf8477b1c143e8f303c84a09bfbd88345baa5dbe19e4238ef6a37c79e59809616f649679070faf17f556838ce874cb95b9
7
+ data.tar.gz: 272f4948d1935e9e9c1eaae8e5230e5db42933dcf1e2130dad009d6d3e4c57fee656b4aead64d6933cadf836bd7d82287fbc8193032c1af7ebf21e53fc7fb403
@@ -83,6 +83,7 @@ Rouge.load_file 'formatters/html_table'
83
83
  Rouge.load_file 'formatters/html_pygments'
84
84
  Rouge.load_file 'formatters/html_legacy'
85
85
  Rouge.load_file 'formatters/html_linewise'
86
+ Rouge.load_file 'formatters/html_line_highlighter'
86
87
  Rouge.load_file 'formatters/html_line_table'
87
88
  Rouge.load_file 'formatters/html_inline'
88
89
  Rouge.load_file 'formatters/terminal256'
@@ -44,6 +44,7 @@ module Rouge
44
44
  yield %||
45
45
  yield %|where <command> is one of:|
46
46
  yield %| highlight #{Highlight.desc}|
47
+ yield %| debug #{Debug.desc}|
47
48
  yield %| help #{Help.desc}|
48
49
  yield %| style #{Style.desc}|
49
50
  yield %| list #{List.desc}|
@@ -104,6 +105,8 @@ module Rouge
104
105
  Help
105
106
  when 'highlight', 'hi'
106
107
  Highlight
108
+ when 'debug'
109
+ Debug
107
110
  when 'style'
108
111
  Style
109
112
  when 'list'
@@ -215,7 +218,7 @@ module Rouge
215
218
  end
216
219
  end
217
220
 
218
- def self.parse(argv)
221
+ def self.parse_opts(argv)
219
222
  opts = {
220
223
  :formatter => supports_truecolor? ? 'terminal-truecolor' : 'terminal256',
221
224
  :theme => 'thankful_eyes',
@@ -256,7 +259,11 @@ module Rouge
256
259
  end
257
260
  end
258
261
 
259
- new(opts)
262
+ opts
263
+ end
264
+
265
+ def self.parse(argv)
266
+ new(parse_opts(argv))
260
267
  end
261
268
 
262
269
  def input_stream
@@ -344,6 +351,29 @@ module Rouge
344
351
  end
345
352
  end
346
353
 
354
+ class Debug < Highlight
355
+ def self.desc
356
+ end
357
+
358
+ def self.doc
359
+ return enum_for(:doc) unless block_given?
360
+
361
+ yield %|usage: rougify debug [<options>]|
362
+ yield %||
363
+ yield %|Debug a lexer. Similar options to `rougify highlight`, but|
364
+ yield %|defaults to the `null` formatter, and ensures the `debug`|
365
+ yield %|option is enabled, to print debugging information to stdout.|
366
+ end
367
+
368
+ def self.parse_opts(argv)
369
+ out = super(argv)
370
+ out[:lexer_opts]['debug'] = '1'
371
+ out[:formatter] = 'null'
372
+
373
+ out
374
+ end
375
+ end
376
+
347
377
  class Style < CLI
348
378
  def self.desc
349
379
  "print CSS styles"
@@ -0,0 +1,6 @@
1
+ function main(args as dynamic) as void
2
+ screen = CreateObject("roSGScreen")
3
+ 'Create a scene and load /components/helloworld.xml'
4
+ scene = screen.CreateScene("HelloWorld")
5
+ screen.show()
6
+ end function
@@ -0,0 +1,11 @@
1
+ From: Me <me@example.com>
2
+ To: You <you@example.com>
3
+ Date: Tue, 21 Jul 2020 15:14:03 +0000
4
+ Subject: A very important message
5
+
6
+ > Please investigate. Thank you.
7
+
8
+ I have investigated.
9
+
10
+ --
11
+ This message is highly confidential and will self-destruct.
@@ -0,0 +1,12 @@
1
+ NB. Procedural programming
2
+ fizzbuzz=: monad define
3
+ for_i. >:i.y do.
4
+ if. 0 = 15 | i do. echo'FizzBuzz'
5
+ elseif. 0 = 3 | i do. echo'Fizz'
6
+ elseif. 0 = 5 | i do. echo'Buzz'
7
+ else. echo i
8
+ end.
9
+ end.
10
+ )
11
+ NB. Loopless programming
12
+ fizzbuzz=: echo@(, ::] ('Fizz' ; 'Buzz') ;@#~ 0 = 3 5&|)@>:@i.
@@ -0,0 +1,3 @@
1
+ (defn a-fun
2
+ "A function"
3
+ (do-something))
@@ -0,0 +1,9 @@
1
+ %!PS
2
+ /Courier % name the desired font
3
+ 20 selectfont % choose the size in points and establish
4
+ % the font as the current one
5
+ 72 500 moveto % position the current point at
6
+ % coordinates 72, 500 (the origin is at the
7
+ % lower-left corner of the page)
8
+ (Hello world!) show % stroke the text in parentheses
9
+ showpage % print all on the page
@@ -0,0 +1,4 @@
1
+ Host example
2
+ Hostname example.com
3
+ User user
4
+ Port 1234
@@ -0,0 +1,4 @@
1
+ [Unit]
2
+ Description=Snap Daemon
3
+ Requires=snapd.socket
4
+ OnFailure=snapd.failure.service
@@ -0,0 +1,24 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Formatters
6
+ class HTMLLineHighlighter < Formatter
7
+ tag 'html_line_highlighter'
8
+
9
+ def initialize(delegate, opts = {})
10
+ @delegate = delegate
11
+ @highlight_line_class = opts.fetch(:highlight_line_class, 'hll')
12
+ @highlight_lines = opts[:highlight_lines] || []
13
+ end
14
+
15
+ def stream(tokens)
16
+ token_lines(tokens).with_index(1) do |line_tokens, lineno|
17
+ line = %(#{@delegate.format(line_tokens)}\n)
18
+ line = %(<span class="#{@highlight_line_class}">#{line}</span>) if @highlight_lines.include? lineno
19
+ yield line
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -32,10 +32,8 @@ module Rouge
32
32
  end
33
33
 
34
34
  def stream(tokens, &b)
35
- lineno = @start_line - 1
36
35
  buffer = [%(<table class="#@table_class"><tbody>)]
37
- token_lines(tokens) do |line_tokens|
38
- lineno += 1
36
+ token_lines(tokens).with_index(@start_line) do |line_tokens, lineno|
39
37
  buffer << %(<tr id="#{sprintf @line_id, lineno}" class="#@line_class">)
40
38
  buffer << %(<td class="#@gutter_class gl" )
41
39
  buffer << %(style="-moz-user-select: none;-ms-user-select: none;)
@@ -11,9 +11,8 @@ module Rouge
11
11
  end
12
12
 
13
13
  def stream(tokens, &b)
14
- lineno = 0
15
- token_lines(tokens) do |line_tokens|
16
- yield %(<#{@tag_name} class="#{sprintf @class_format, lineno += 1}">)
14
+ token_lines(tokens).with_index(1) do |line_tokens, lineno|
15
+ yield %(<#{@tag_name} class="#{sprintf @class_format, lineno}">)
17
16
  @formatter.stream(line_tokens) {|formatted| yield formatted }
18
17
  yield %(\n</#{@tag_name}>)
19
18
  end
@@ -38,28 +38,15 @@ module Rouge
38
38
  registry[name.to_s]
39
39
  end
40
40
 
41
- # Find a lexer, with fancy shiny features.
42
- #
43
- # * The string you pass can include CGI-style options
44
- #
45
- # Lexer.find_fancy('erb?parent=tex')
46
- #
47
- # * You can pass the special name 'guess' so we guess for you,
48
- # and you can pass a second argument of the code to guess by
49
- #
50
- # Lexer.find_fancy('guess', "#!/bin/bash\necho Hello, world")
41
+ # Same as ::find_fancy, except instead of returning an instantiated
42
+ # lexer, returns a pair of [lexer_class, options], so that you can
43
+ # modify or provide additional options to the lexer.
51
44
  #
52
- # If the code matches more than one lexer then Guesser::Ambiguous
53
- # is raised.
54
- #
55
- # This is used in the Redcarpet plugin as well as Rouge's own
56
- # markdown lexer for highlighting internal code blocks.
57
- #
58
- def find_fancy(str, code=nil, additional_options={})
59
-
45
+ # Please note: the lexer class might be nil!
46
+ def lookup_fancy(str, code=nil, default_options={})
60
47
  if str && !str.include?('?') && str != 'guess'
61
48
  lexer_class = find(str)
62
- return lexer_class && lexer_class.new(additional_options)
49
+ return [lexer_class, default_options]
63
50
  end
64
51
 
65
52
  name, opts = str ? str.split('?', 2) : [nil, '']
@@ -75,7 +62,7 @@ module Rouge
75
62
  [ k.to_s, val ]
76
63
  end
77
64
 
78
- opts = additional_options.merge(Hash[opts])
65
+ opts = default_options.merge(Hash[opts])
79
66
 
80
67
  lexer_class = case name
81
68
  when 'guess', nil
@@ -84,6 +71,29 @@ module Rouge
84
71
  self.find(name)
85
72
  end
86
73
 
74
+ [lexer_class, opts]
75
+ end
76
+
77
+ # Find a lexer, with fancy shiny features.
78
+ #
79
+ # * The string you pass can include CGI-style options
80
+ #
81
+ # Lexer.find_fancy('erb?parent=tex')
82
+ #
83
+ # * You can pass the special name 'guess' so we guess for you,
84
+ # and you can pass a second argument of the code to guess by
85
+ #
86
+ # Lexer.find_fancy('guess', "#!/bin/bash\necho Hello, world")
87
+ #
88
+ # If the code matches more than one lexer then Guesser::Ambiguous
89
+ # is raised.
90
+ #
91
+ # This is used in the Redcarpet plugin as well as Rouge's own
92
+ # markdown lexer for highlighting internal code blocks.
93
+ #
94
+ def find_fancy(str, code=nil, default_options={})
95
+ lexer_class, opts = lookup_fancy(str, code, default_options)
96
+
87
97
  lexer_class && lexer_class.new(opts)
88
98
  end
89
99
 
@@ -317,6 +327,14 @@ module Rouge
317
327
  @debug = Lexer.debug_enabled? && bool_option('debug')
318
328
  end
319
329
 
330
+ # Returns a new lexer with the given options set. Useful for e.g. setting
331
+ # debug flags post hoc, or providing global overrides for certain options
332
+ def with(opts={})
333
+ new_options = @options.dup
334
+ opts.each { |k, v| new_options[k.to_s] = v }
335
+ self.class.new(new_options)
336
+ end
337
+
320
338
  def as_bool(val)
321
339
  case val
322
340
  when nil, false, 0, '0', 'false', 'off'
@@ -49,7 +49,7 @@ module Rouge
49
49
 
50
50
  state :root do
51
51
  rule %r/\s+/m, Text
52
-
52
+
53
53
  rule %r(//.*?$), Comment::Single
54
54
  rule %r(/\*.*?\*/)m, Comment::Multiline
55
55
 
@@ -57,17 +57,19 @@ module Rouge
57
57
  rule %r/import\b/, Keyword::Namespace, :import
58
58
 
59
59
  rule %r/([@$.]?)(#{id})([:(]?)/io do |m|
60
- if self.class.keywords.include? m[0].downcase
60
+ lowercased = m[0].downcase
61
+ uppercased = m[0].upcase
62
+ if self.class.keywords.include? lowercased
61
63
  token Keyword
62
- elsif self.class.soql.include? m[0].upcase
64
+ elsif self.class.soql.include? uppercased
63
65
  token Keyword
64
- elsif self.class.declarations.include? m[0].downcase
66
+ elsif self.class.declarations.include? lowercased
65
67
  token Keyword::Declaration
66
- elsif self.class.types.include? m[0].downcase
68
+ elsif self.class.types.include? lowercased
67
69
  token Keyword::Type
68
- elsif self.class.constants.include? m[0].downcase
70
+ elsif self.class.constants.include? lowercased
69
71
  token Keyword::Constant
70
- elsif 'package'.casecmp m[0]
72
+ elsif lowercased == 'package'
71
73
  token Keyword::Namespace
72
74
  elsif m[1] == "@"
73
75
  token Name::Decorator
@@ -78,7 +78,8 @@ module Rouge
78
78
 
79
79
  state :basic do
80
80
  # Comments
81
- rule %r/\brem\b.*$/i, Comment
81
+ rule %r/@?\brem\b.*$/i, Comment
82
+
82
83
  # Empty Labels
83
84
  rule %r/^::.*$/, Comment
84
85
 
@@ -105,7 +106,7 @@ module Rouge
105
106
  end
106
107
  end
107
108
 
108
- rule %r/([\/\-+][a-z]+)\s*/i, Name::Attribute
109
+ rule %r/((?:[\/\+]|--?)[a-z]+)\s*/i, Name::Attribute
109
110
 
110
111
  mixin :expansions
111
112
 
@@ -0,0 +1,147 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class Brightscript < RegexLexer
7
+ title "BrightScript"
8
+ desc "BrightScript Programming Language (https://developer.roku.com/en-ca/docs/references/brightscript/language/brightscript-language-reference.md)"
9
+ tag 'brightscript'
10
+ aliases 'bs', 'brs'
11
+ filenames '*.brs'
12
+
13
+ # https://developer.roku.com/en-ca/docs/references/brightscript/language/global-utility-functions.md
14
+ # https://developer.roku.com/en-ca/docs/references/brightscript/language/global-string-functions.md
15
+ # https://developer.roku.com/en-ca/docs/references/brightscript/language/global-math-functions.md
16
+ def self.name_builtin
17
+ @name_builtin ||= Set.new %w(
18
+ ABS ASC ATN CDBL CHR CINT CONTROL COPYFILE COS CREATEDIRECTORY CSNG
19
+ DELETEDIRECTORY DELETEFILE EXP FINDMEMBERFUNCTION FINDNODE FIX
20
+ FORMATDRIVEFORMATJSON GETINTERFACE INSTR INT LCASE LEFT LEN LISTDIR
21
+ LOG MATCHFILES MID MOVEFILE OBSERVEFIELD PARSEJSON PARSEXML
22
+ READASCIIFILE REBOOTSYSTEM RIGHT RND RUNGARBAGECOLLECTOR SGN SIN
23
+ SLEEP SQR STR STRI STRING STRINGI STRTOI SUBSTITUTE TANTEXTTOP TEXT
24
+ TRUCASE UPTIME VALVISIBLE VISIBLE WAIT
25
+ )
26
+ end
27
+
28
+ # https://developer.roku.com/en-ca/docs/references/brightscript/language/reserved-words.md
29
+ def self.keyword_reserved
30
+ @keyword_reserved ||= Set.new %w(
31
+ BOX CREATEOBJECT DIM EACH ELSE ELSEIF END ENDFUNCTION ENDIF ENDSUB
32
+ ENDWHILE EVAL EXIT EXITWHILE FALSE FOR FUNCTION GETGLOBALAA
33
+ GETLASTRUNCOMPILEERROR GETLASTRUNRUNTIMEERROR GOTO IF IN INVALID LET
34
+ LINE_NUM M NEXT OBJFUN POS PRINT REM RETURN RUN STEP STOP SUB TAB TO
35
+ TRUE TYPE WHILE
36
+ )
37
+ end
38
+
39
+ # These keywords are present in BrightScript, but not supported in standard .brs files
40
+ def self.keyword_reserved_unsupported
41
+ @keyword_reserved_unsupported ||= Set.new %w(
42
+ CLASS CONST IMPORT LIBRARY NAMESPACE PRIVATE PROTECTED PUBLIC
43
+ )
44
+ end
45
+
46
+ # https://developer.roku.com/en-ca/docs/references/brightscript/language/expressions-variables-types.md
47
+ def self.keyword_type
48
+ @keyword_type ||= Set.new %w(
49
+ BOOLEAN DIM DOUBLE DYNAMIC FLOAT FUNCTION INTEGER INTERFACE INVALID
50
+ LONGINTEGER OBJECT STRING VOID
51
+ )
52
+ end
53
+
54
+ # https://developer.roku.com/en-ca/docs/references/brightscript/language/expressions-variables-types.md#operators
55
+ def self.operator_word
56
+ @operator_word ||= Set.new %w(
57
+ AND AS MOD NOT OR THEN
58
+ )
59
+ end
60
+
61
+ # Scene graph components configured as builtins. See BrightScript component documentation e.g.
62
+ # https://developer.roku.com/en-ca/docs/references/brightscript/components/roappinfo.md
63
+ def self.builtins
64
+ @builtins ||= Set.new %w(
65
+ roAppendFile roAppInfo roAppManager roArray roAssociativeArray
66
+ roAudioGuide roAudioMetadata roAudioPlayer roAudioPlayerEvent
67
+ roAudioResourceroBitmap roBoolean roBoolean roBrightPackage roBrSub
68
+ roButton roByteArray roCaptionRenderer roCaptionRendererEvent
69
+ roCecInterface roCECStatusEvent roChannelStore roChannelStoreEvent
70
+ roClockWidget roCodeRegistrationScreen
71
+ roCodeRegistrationScreenEventroCompositor roControlDown roControlPort
72
+ roControlPort roControlUp roCreateFile roDatagramReceiver
73
+ roDatagramSender roDataGramSocket roDateTime roDeviceInfo
74
+ roDeviceInfoEvent roDoubleroEVPCipher roEVPDigest roFileSystem
75
+ roFileSystemEvent roFloat roFont roFontMetrics roFontRegistry
76
+ roFunction roGlobal roGpio roGridScreen roGridScreenEvent
77
+ roHdmiHotPlugEventroHdmiStatus roHdmiStatusEvent roHMAC roHttpAgent
78
+ roImageCanvas roImageCanvasEvent roImageMetadata roImagePlayer
79
+ roImageWidgetroInput roInputEvent roInt roInt roInvalid roInvalid
80
+ roIRRemote roKeyboard roKeyboardPress roKeyboardScreen
81
+ roKeyboardScreenEventroList roListScreen roListScreenEvent
82
+ roLocalization roLongInteger roMessageDialog roMessageDialogEvent
83
+ roMessagePort roMicrophone roMicrophoneEvent roNetworkConfiguration
84
+ roOneLineDialog roOneLineDialogEventroParagraphScreen
85
+ roParagraphScreenEvent roPath roPinEntryDialog roPinEntryDialogEvent
86
+ roPinentryScreen roPosterScreen roPosterScreenEventroProgramGuide
87
+ roQuadravoxButton roReadFile roRectangleroRegexroRegion roRegistry
88
+ roRegistrySection roResourceManager roRSA roRssArticle roRssParser
89
+ roScreen roSearchHistory roSearchScreen roSearchScreenEvent
90
+ roSerialPort roSGNode roSGNodeEvent roSGScreenroSGScreenEvent
91
+ roSlideShowroSlideShowEvent roSNS5 roSocketAddress roSocketEvent
92
+ roSpringboardScreen roSpringboardScreenEventroSprite roStorageInfo
93
+ roStreamSocket roStringroSystemLogroSystemLogEvent roSystemTime
94
+ roTextFieldroTextScreen roTextScreenEvent roTextToSpeech
95
+ roTextToSpeechEvent roTextureManager roTextureRequest
96
+ roTextureRequestEventroTextWidget roTimer roTimespan roTouchScreen
97
+ roTunerroTunerEvent roUniversalControlEvent roUrlEvent roUrlTransfer
98
+ roVideoEvent roVideoInput roVideoMode roVideoPlayer roVideoPlayerEvent
99
+ roVideoScreen roVideoScreenEventroWriteFile roXMLElement roXMLList
100
+ )
101
+ end
102
+
103
+ id = /[$a-z_][a-z0-9_]*/io
104
+
105
+ state :root do
106
+ rule %r/\s+/m, Text::Whitespace
107
+
108
+ # https://developer.roku.com/en-ca/docs/references/brightscript/language/expressions-variables-types.md#comments
109
+ rule %r/\'.*/, Comment::Single
110
+ rule %r/REM.*/i, Comment::Single
111
+
112
+ # https://developer.roku.com/en-ca/docs/references/brightscript/language/expressions-variables-types.md#operators
113
+ rule %r([~!%^&*+=\|?:<>/-]), Operator
114
+
115
+ rule %r/\d*\.\d+(e-?\d+)?/i, Num::Float
116
+ rule %r/\d+[lu]*/i, Num::Integer
117
+
118
+ rule %r/".*?"/, Str::Double
119
+
120
+ rule %r/#{id}(?=\s*[(])/, Name::Function
121
+
122
+ rule %r/[()\[\],.;{}]/, Punctuation
123
+
124
+ rule id do |m|
125
+ caseSensitiveChunk = m[0]
126
+ caseInsensitiveChunk = m[0].upcase
127
+
128
+ if self.class.builtins.include?(caseSensitiveChunk)
129
+ token Keyword::Reserved
130
+ elsif self.class.keyword_reserved.include?(caseInsensitiveChunk)
131
+ token Keyword::Reserved
132
+ elsif self.class.keyword_reserved_unsupported.include?(caseInsensitiveChunk)
133
+ token Keyword::Reserved
134
+ elsif self.class.keyword_type.include?(caseInsensitiveChunk)
135
+ token Keyword::Type
136
+ elsif self.class.name_builtin.include?(caseInsensitiveChunk)
137
+ token Name::Builtin
138
+ elsif self.class.operator_word.include?(caseInsensitiveChunk)
139
+ token Operator::Word
140
+ else
141
+ token Name
142
+ end
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end