rouge 3.5.1 → 3.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/lib/rouge.rb +1 -0
  4. data/lib/rouge/cli.rb +19 -11
  5. data/lib/rouge/demos/ada +26 -0
  6. data/lib/rouge/demos/armasm +12 -0
  7. data/lib/rouge/demos/batchfile +3 -0
  8. data/lib/rouge/demos/bbcbasic +6 -0
  9. data/lib/rouge/demos/clean +6 -0
  10. data/lib/rouge/demos/cmhg +8 -0
  11. data/lib/rouge/demos/cuda +11 -0
  12. data/lib/rouge/demos/cython +6 -0
  13. data/lib/rouge/demos/eex +1 -0
  14. data/lib/rouge/demos/epp +4 -0
  15. data/lib/rouge/demos/gdscript +18 -0
  16. data/lib/rouge/demos/haxe +5 -0
  17. data/lib/rouge/demos/hocon +8 -0
  18. data/lib/rouge/demos/hql +5 -0
  19. data/lib/rouge/demos/jsl +3 -0
  20. data/lib/rouge/demos/lustre +6 -0
  21. data/lib/rouge/demos/lutin +18 -0
  22. data/lib/rouge/demos/mason +22 -0
  23. data/lib/rouge/demos/msgtrans +4 -0
  24. data/lib/rouge/demos/openedge +4 -0
  25. data/lib/rouge/demos/opentype_feature_file +6 -0
  26. data/lib/rouge/demos/plist +1 -132
  27. data/lib/rouge/demos/powershell +12 -48
  28. data/lib/rouge/demos/reasonml +12 -0
  29. data/lib/rouge/demos/sas +13 -0
  30. data/lib/rouge/demos/sparql +6 -0
  31. data/lib/rouge/demos/terraform +0 -15
  32. data/lib/rouge/demos/xojo +2 -1
  33. data/lib/rouge/demos/xpath +2 -0
  34. data/lib/rouge/demos/xquery +22 -0
  35. data/lib/rouge/formatters/html.rb +18 -2
  36. data/lib/rouge/formatters/html_line_table.rb +53 -0
  37. data/lib/rouge/formatters/tex.rb +14 -12
  38. data/lib/rouge/guessers/disambiguation.rb +12 -0
  39. data/lib/rouge/guessers/modeline.rb +1 -1
  40. data/lib/rouge/lexers/ada.rb +162 -0
  41. data/lib/rouge/lexers/apache.rb +1 -1
  42. data/lib/rouge/lexers/armasm.rb +145 -0
  43. data/lib/rouge/lexers/batchfile.rb +164 -0
  44. data/lib/rouge/lexers/bbcbasic.rb +112 -0
  45. data/lib/rouge/lexers/bpf.rb +12 -12
  46. data/lib/rouge/lexers/ceylon.rb +5 -5
  47. data/lib/rouge/lexers/clean.rb +156 -0
  48. data/lib/rouge/lexers/cmhg.rb +34 -0
  49. data/lib/rouge/lexers/common_lisp.rb +1 -1
  50. data/lib/rouge/lexers/console.rb +1 -1
  51. data/lib/rouge/lexers/cpp.rb +4 -1
  52. data/lib/rouge/lexers/cuda.rb +35 -0
  53. data/lib/rouge/lexers/cython.rb +151 -0
  54. data/lib/rouge/lexers/docker.rb +2 -2
  55. data/lib/rouge/lexers/eex.rb +51 -0
  56. data/lib/rouge/lexers/elixir.rb +25 -11
  57. data/lib/rouge/lexers/elm.rb +1 -1
  58. data/lib/rouge/lexers/epp.rb +51 -0
  59. data/lib/rouge/lexers/escape.rb +3 -0
  60. data/lib/rouge/lexers/fsharp.rb +4 -4
  61. data/lib/rouge/lexers/gdscript.rb +171 -0
  62. data/lib/rouge/lexers/gherkin.rb +4 -2
  63. data/lib/rouge/lexers/glsl.rb +1 -1
  64. data/lib/rouge/lexers/graphql.rb +10 -3
  65. data/lib/rouge/lexers/handlebars.rb +14 -3
  66. data/lib/rouge/lexers/haxe.rb +246 -0
  67. data/lib/rouge/lexers/hocon.rb +86 -0
  68. data/lib/rouge/lexers/hql.rb +139 -0
  69. data/lib/rouge/lexers/html.rb +2 -2
  70. data/lib/rouge/lexers/http.rb +6 -6
  71. data/lib/rouge/lexers/idlang.rb +1 -1
  72. data/lib/rouge/lexers/igorpro.rb +1 -1
  73. data/lib/rouge/lexers/javascript.rb +1 -1
  74. data/lib/rouge/lexers/jsl.rb +55 -0
  75. data/lib/rouge/lexers/json.rb +44 -6
  76. data/lib/rouge/lexers/jsp.rb +3 -3
  77. data/lib/rouge/lexers/julia.rb +1 -1
  78. data/lib/rouge/lexers/liquid.rb +23 -0
  79. data/lib/rouge/lexers/lustre.rb +79 -0
  80. data/lib/rouge/lexers/lutin.rb +33 -0
  81. data/lib/rouge/lexers/magik.rb +2 -1
  82. data/lib/rouge/lexers/make.rb +44 -16
  83. data/lib/rouge/lexers/mason.rb +115 -0
  84. data/lib/rouge/lexers/matlab.rb +4 -2
  85. data/lib/rouge/lexers/matlab/builtins.yml +3515 -0
  86. data/lib/rouge/lexers/mosel.rb +43 -43
  87. data/lib/rouge/lexers/msgtrans.rb +26 -0
  88. data/lib/rouge/lexers/nim.rb +2 -1
  89. data/lib/rouge/lexers/nix.rb +1 -1
  90. data/lib/rouge/lexers/ocaml.rb +12 -48
  91. data/lib/rouge/lexers/ocaml/common.rb +53 -0
  92. data/lib/rouge/lexers/openedge.rb +429 -0
  93. data/lib/rouge/lexers/opentype_feature_file.rb +113 -0
  94. data/lib/rouge/lexers/perl.rb +12 -14
  95. data/lib/rouge/lexers/php.rb +31 -9
  96. data/lib/rouge/lexers/php/builtins.rb +181 -174
  97. data/lib/rouge/lexers/plain_text.rb +1 -1
  98. data/lib/rouge/lexers/powershell.rb +181 -635
  99. data/lib/rouge/lexers/puppet.rb +2 -2
  100. data/lib/rouge/lexers/q.rb +1 -1
  101. data/lib/rouge/lexers/r.rb +2 -3
  102. data/lib/rouge/lexers/reasonml.rb +65 -0
  103. data/lib/rouge/lexers/ruby.rb +2 -2
  104. data/lib/rouge/lexers/rust.rb +12 -9
  105. data/lib/rouge/lexers/sas.rb +563 -0
  106. data/lib/rouge/lexers/scala.rb +1 -1
  107. data/lib/rouge/lexers/sed.rb +1 -1
  108. data/lib/rouge/lexers/shell.rb +1 -1
  109. data/lib/rouge/lexers/smarty.rb +10 -10
  110. data/lib/rouge/lexers/sparql.rb +129 -0
  111. data/lib/rouge/lexers/sql.rb +26 -6
  112. data/lib/rouge/lexers/swift.rb +4 -4
  113. data/lib/rouge/lexers/terraform.rb +8 -0
  114. data/lib/rouge/lexers/tex.rb +1 -1
  115. data/lib/rouge/lexers/toml.rb +1 -1
  116. data/lib/rouge/lexers/vala.rb +1 -1
  117. data/lib/rouge/lexers/vhdl.rb +1 -1
  118. data/lib/rouge/lexers/wollok.rb +1 -1
  119. data/lib/rouge/lexers/xml.rb +1 -1
  120. data/lib/rouge/lexers/xojo.rb +4 -4
  121. data/lib/rouge/lexers/xpath.rb +332 -0
  122. data/lib/rouge/lexers/xquery.rb +145 -0
  123. data/lib/rouge/lexers/yaml.rb +5 -3
  124. data/lib/rouge/regex_lexer.rb +14 -13
  125. data/lib/rouge/tex_theme_renderer.rb +7 -3
  126. data/lib/rouge/themes/magritte.rb +3 -3
  127. data/lib/rouge/themes/monokai_sublime.rb +2 -1
  128. data/lib/rouge/themes/pastie.rb +1 -1
  129. data/lib/rouge/themes/thankful_eyes.rb +1 -1
  130. data/lib/rouge/themes/tulip.rb +1 -1
  131. data/lib/rouge/util.rb +2 -2
  132. data/lib/rouge/version.rb +1 -1
  133. data/rouge.gemspec +4 -3
  134. metadata +61 -5
  135. data/lib/rouge/lexers/matlab/builtins.rb +0 -13
@@ -78,7 +78,7 @@ module Rouge
78
78
  (#{keywords.join("|")})\b|
79
79
  (<[%:-]|=>|>:|[#=@_\u21D2\u2190])(\b|(?=\s)|$)
80
80
  )x, Keyword
81
- rule %r/:(?!#{op})/, Keyword, :type
81
+ rule %r/:(?!#{op})/, Keyword, :type
82
82
  rule %r/(true|false|null)\b/, Keyword::Constant
83
83
  rule %r/(import|package)(\s+)/ do
84
84
  groups Keyword, Text
@@ -141,7 +141,7 @@ module Rouge
141
141
  end
142
142
 
143
143
  # alternate regex rage delimiters
144
- rule %r((\\)(.)(\\.|.)*?(\2)) do |m|
144
+ rule %r((\\)(.)((?:\\.|.)*?)(\2)) do |m|
145
145
  token addr_tok, m[1] + m[2]
146
146
  delegate regex, m[3]
147
147
  token addr_tok, m[4]
@@ -52,7 +52,7 @@ module Rouge
52
52
  rule %r/\b(#{BUILTINS})\s*\b(?!(\.|-))/, Name::Builtin
53
53
  rule %r/[.](?=\s)/, Name::Builtin
54
54
 
55
- rule %r/(\b\w+)(=)/ do |m|
55
+ rule %r/(\b\w+)(=)/ do
56
56
  groups Name::Variable, Operator
57
57
  end
58
58
 
@@ -64,18 +64,18 @@ module Rouge
64
64
  rule %r/#[a-zA-Z_]\w*#/, Name::Variable
65
65
  rule %r/\$[a-zA-Z_]\w*(\.\w+)*/, Name::Variable
66
66
  rule %r/(true|false|null)\b/, Keyword::Constant
67
- rule %r/[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?/, Num
68
- rule %r/"(\\.|.)*?"/, Str::Double
67
+ rule %r/[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?/, Num
68
+ rule %r/"(\\.|.)*?"/, Str::Double
69
69
  rule %r/'(\\.|.)*?'/, Str::Single
70
- rule %r/([a-zA-Z_]\w*)/ do |m|
71
- if self.class.builtins.include? m[0]
72
- token Name::Builtin
73
- else
74
- token Name::Attribute
75
- end
76
- end
77
- end
78
70
 
71
+ rule %r/([a-zA-Z_]\w*)/ do |m|
72
+ if self.class.builtins.include? m[0]
73
+ token Name::Builtin
74
+ else
75
+ token Name::Attribute
76
+ end
77
+ end
78
+ end
79
79
  end
80
80
  end
81
81
  end
@@ -0,0 +1,129 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class SPARQL < RegexLexer
7
+ title "SPARQL"
8
+ desc "Semantic Query Language, for RDF data"
9
+ tag 'sparql'
10
+ filenames '*.rq'
11
+ mimetypes 'application/sparql-query'
12
+
13
+ def self.builtins
14
+ @builtins = Set.new %w[
15
+ ABS AVG BNODE BOUND CEIL COALESCE CONCAT CONTAINS COUNT DATATYPE DAY
16
+ ENCODE_FOR_URI FLOOR GROUP_CONCAT HOURS IF IRI isBLANK isIRI
17
+ isLITERAL isNUMERIC isURI LANG LANGMATCHES LCASE MAX MD5 MIN MINUTES
18
+ MONTH NOW RAND REGEX REPLACE ROUND SAMETERM SAMPLE SECONDS SEPARATOR
19
+ SHA1 SHA256 SHA384 SHA512 STR STRAFTER STRBEFORE STRDT STRENDS
20
+ STRLANG STRLEN STRSTARTS STRUUID SUBSTR SUM TIMEZONE TZ UCASE URI
21
+ UUID YEAR
22
+ ]
23
+ end
24
+
25
+ def self.keywords
26
+ @keywords = Set.new %w[
27
+ ADD ALL AS ASC ASK BASE BIND BINDINGS BY CLEAR CONSTRUCT COPY CREATE
28
+ DATA DEFAULT DELETE DESC DESCRIBE DISTINCT DROP EXISTS FILTER FROM
29
+ GRAPH GROUP BY HAVING IN INSERT LIMIT LOAD MINUS MOVE NAMED NOT
30
+ OFFSET OPTIONAL ORDER PREFIX SELECT REDUCED SERVICE SILENT TO UNDEF
31
+ UNION USING VALUES WHERE WITH
32
+ ]
33
+ end
34
+
35
+ state :root do
36
+ rule %r(\s+)m, Text::Whitespace
37
+ rule %r(#.*), Comment::Single
38
+
39
+ rule %r("""), Str::Double, :string_double_literal
40
+ rule %r("), Str::Double, :string_double
41
+ rule %r('''), Str::Single, :string_single_literal
42
+ rule %r('), Str::Single, :string_single
43
+
44
+ rule %r([$?]\w+), Name::Variable
45
+ rule %r((\w*:)(\w+)?) do |m|
46
+ token Name::Namespace, m[1]
47
+ token Str::Symbol, m[2]
48
+ end
49
+ rule %r(<[^>]*>), Name::Namespace
50
+ rule %r(true|false)i, Keyword::Constant
51
+
52
+ rule %r([A-Z]\w+\b)i do |m|
53
+ if self.class.builtins.include? m[0].upcase
54
+ token Name::Builtin
55
+ elsif self.class.keywords.include? m[0].upcase
56
+ token Keyword
57
+ else
58
+ token Error
59
+ end
60
+ end
61
+
62
+ rule %r([+\-]?(?:\d+\.\d*|\.\d+)(?:[e][+\-]?[0-9]+)?)i, Num::Float
63
+ rule %r([+\-]?\d+), Num::Integer
64
+ rule %r([\]\[(){}.,;=]), Punctuation
65
+ rule %r([/?*+=!<>]|&&|\|\||\^\^), Operator
66
+ end
67
+
68
+ state :string_double_common do
69
+ mixin :string_escapes
70
+ rule %r(\\), Str::Double
71
+ rule %r([^"\\]+), Str::Double
72
+ end
73
+
74
+ state :string_double do
75
+ rule %r(") do
76
+ token Str::Double
77
+ goto :string_end
78
+ end
79
+ mixin :string_double_common
80
+ end
81
+
82
+ state :string_double_literal do
83
+ rule %r(""") do
84
+ token Str::Double
85
+ goto :string_end
86
+ end
87
+ rule %r("), Str::Double
88
+ mixin :string_double_common
89
+ end
90
+
91
+ state :string_single_common do
92
+ mixin :string_escapes
93
+ rule %r(\\), Str::Single
94
+ rule %r([^'\\]+), Str::Single
95
+ end
96
+
97
+ state :string_single do
98
+ rule %r(') do
99
+ token Str::Single
100
+ goto :string_end
101
+ end
102
+ mixin :string_single_common
103
+ end
104
+
105
+ state :string_single_literal do
106
+ rule %r(''') do
107
+ token Str::Single
108
+ goto :string_end
109
+ end
110
+ rule %r('), Str::Single
111
+ mixin :string_single_common
112
+ end
113
+
114
+ state :string_escapes do
115
+ rule %r(\\[tbnrf"'\\]), Str::Escape
116
+ rule %r(\\u\h{4}), Str::Escape
117
+ rule %r(\\U\h{8}), Str::Escape
118
+ end
119
+
120
+ state :string_end do
121
+ rule %r((@)([a-zA-Z]+(?:-[a-zA-Z0-9]+)*)) do
122
+ groups Operator, Name::Property
123
+ end
124
+ rule %r(\^\^), Operator
125
+ rule(//) { pop! }
126
+ end
127
+ end
128
+ end
129
+ end
@@ -51,7 +51,7 @@ module Rouge
51
51
  LOCALTIME LOCALTIMESTAMP LOCATION LOCATOR LOCK LOWER MAP MATCH
52
52
  MAX MAXVALUE MESSAGE_LENGTH MESSAGE_OCTET_LENGTH MESSAGE_TEXT
53
53
  METHOD MIN MINUTE MINVALUE MOD MODE MODIFIES MODIFY MONTH
54
- MORE MOVE MUMPS NAMES NATIONAL NATURAL NCHAR NCLOB NEW NEXT
54
+ MORE MOVE MUMPS NAMES NATURAL NCLOB NEW NEXT
55
55
  NO NOCREATEDB NOCREATEUSER NONE NOT NOTHING NOTIFY NOTNULL
56
56
  NULL NULLABLE NULLIF OBJECT OCTET_LENGTH OF OFF OFFSET OIDS
57
57
  OLD ON ONLY OPEN OPERATION OPERATOR OPTION OPTIONS OR ORDER
@@ -59,7 +59,7 @@ module Rouge
59
59
  OWNER PAD PARAMETER PARAMETERS PARAMETER_MODE PARAMATER_NAME
60
60
  PARAMATER_ORDINAL_POSITION PARAMETER_SPECIFIC_CATALOG
61
61
  PARAMETER_SPECIFIC_NAME PARAMATER_SPECIFIC_SCHEMA PARTIAL PASCAL
62
- PENDANT PLACING PLI POSITION POSTFIX PRECISION PREFIX PREORDER
62
+ PENDANT PLACING PLI POSITION POSTFIX PREFIX PREORDER
63
63
  PREPARE PRESERVE PRIMARY PRIOR PRIVILEGES PROCEDURAL PROCEDURE
64
64
  PUBLIC READ READS RECHECK RECURSIVE REF REFERENCES REFERENCING
65
65
  REINDEX RELATIVE RENAME REPEATABLE REPLACE RESET RESTART
@@ -75,7 +75,7 @@ module Rouge
75
75
  STDIN STDOUT STORAGE STRICT STRUCTURE STYPE SUBCLASS_ORIGIN
76
76
  SUBLIST SUBSTRING SUM SYMMETRIC SYSID SYSTEM SYSTEM_USER
77
77
  TABLE TABLE_NAME TEMP TEMPLATE TEMPORARY TERMINATE THAN THEN
78
- TIMESTAMP TIMEZONE_HOUR TIMEZONE_MINUTE TO TOAST TRAILING
78
+ TIMEZONE_HOUR TIMEZONE_MINUTE TO TOAST TRAILING
79
79
  TRANSATION TRANSACTIONS_COMMITTED TRANSACTIONS_ROLLED_BACK
80
80
  TRANSATION_ACTIVE TRANSFORM TRANSFORMS TRANSLATE TRANSLATION
81
81
  TREAT TRIGGER TRIGGER_CATALOG TRIGGER_NAME TRIGGER_SCHEMA TRIM
@@ -84,21 +84,41 @@ module Rouge
84
84
  USAGE USER USER_DEFINED_TYPE_CATALOG USER_DEFINED_TYPE_NAME
85
85
  USER_DEFINED_TYPE_SCHEMA USING VACUUM VALID VALIDATOR VALUES
86
86
  VARIABLE VERBOSE VERSION VIEW VOLATILE WHEN WHENEVER WHERE
87
- WITH WITHOUT WORK WRITE YEAR ZONE
87
+ WITH WITHOUT WORK WRITE ZONE
88
88
  )
89
89
  end
90
90
 
91
+ def self.keywords_type
92
+ # sources:
93
+ # https://dev.mysql.com/doc/refman/5.7/en/numeric-type-overview.html
94
+ # https://dev.mysql.com/doc/refman/5.7/en/date-and-time-type-overview.html
95
+ # https://dev.mysql.com/doc/refman/5.7/en/string-type-overview.html
96
+ @keywords_type ||= Set.new(%w(
97
+ ZEROFILL UNSIGNED SIGNED SERIAL BIT TINYINT BOOL BOOLEAN SMALLINT
98
+ MEDIUMINT INT INTEGER BIGINT DECIMAL DEC NUMERIC FIXED FLOAT DOUBLE
99
+ PRECISION REAL
100
+ DATE DATETIME TIMESTAMP TIME YEAR
101
+ NATIONAL CHAR CHARACTER NCHAR BYTE
102
+ VARCHAR VARYING BINARY VARBINARY TINYBLOB TINYTEXT BLOB TEXT
103
+ MEDIUMBLOB MEDIUMTEXT LONGBLOB LONGTEXT ENUM
104
+ ))
105
+ end
106
+
91
107
  state :root do
92
108
  rule %r/\s+/m, Text
93
109
  rule %r/--.*/, Comment::Single
94
110
  rule %r(/\*), Comment::Multiline, :multiline_comments
95
111
  rule %r/\d+/, Num::Integer
96
112
  rule %r/'/, Str::Single, :single_string
113
+ # A double-quoted string refers to a database object in our default SQL
114
+ # dialect, which is apropriate for e.g. MS SQL and PostgreSQL.
97
115
  rule %r/"/, Name::Variable, :double_string
98
116
  rule %r/`/, Name::Variable, :backtick
99
117
 
100
- rule %r/\w\w*/ do |m|
101
- if self.class.keywords.include? m[0].upcase
118
+ rule %r/\w[\w\d]*/ do |m|
119
+ if self.class.keywords_type.include? m[0].upcase
120
+ token Name::Builtin
121
+ elsif self.class.keywords.include? m[0].upcase
102
122
  token Keyword
103
123
  else
104
124
  token Name
@@ -97,13 +97,13 @@ module Rouge
97
97
  groups Keyword::Declaration, Error, Keyword::Declaration
98
98
  end
99
99
  end
100
-
100
+
101
101
  rule %r/#available\([^)]+\)/, Keyword::Declaration
102
-
102
+
103
103
  rule %r/(#(?:selector|keyPath)\()([^)]+?(?:[(].*?[)])?)(\))/ do
104
104
  groups Keyword::Declaration, Name::Function, Keyword::Declaration
105
105
  end
106
-
106
+
107
107
  rule %r/#(line|file|column|function|dsohandle)/, Keyword::Declaration
108
108
 
109
109
  rule %r/(let|var)\b(\s*)(#{id})/ do
@@ -122,7 +122,7 @@ module Rouge
122
122
  token Name::Function
123
123
  end
124
124
  end
125
-
125
+
126
126
  rule %r/as[?!]?(?=\s)/, Keyword
127
127
  rule %r/try[!]?(?=\s)/, Keyword
128
128
 
@@ -37,6 +37,14 @@ module Rouge
37
37
  @builtins ||= %w()
38
38
  end
39
39
 
40
+ prepend :hash do
41
+ rule %r/[.,()*]/, Punctuation
42
+ end
43
+
44
+ prepend :array do
45
+ rule %r/[.,()*]/, Punctuation
46
+ end
47
+
40
48
  state :strings do
41
49
  rule %r/\\./, Str::Escape
42
50
  rule %r/\$\{/ do
@@ -30,7 +30,7 @@ module Rouge
30
30
  rule %r/\$/, Punctuation, :inlinemath
31
31
  rule %r/\\(begin|end)\{.*?\}/, Name::Tag
32
32
 
33
- rule %r/(\\verb)\b(\S)(.*?)(\2)/ do |m|
33
+ rule %r/(\\verb)\b(\S)(.*?)(\2)/ do
34
34
  groups Name::Builtin, Keyword::Pseudo, Str::Other, Keyword::Pseudo
35
35
  end
36
36
 
@@ -8,7 +8,7 @@ module Rouge
8
8
  desc 'the TOML configuration format (https://github.com/mojombo/toml)'
9
9
  tag 'toml'
10
10
 
11
- filenames '*.toml'
11
+ filenames '*.toml', 'Pipfile'
12
12
  mimetypes 'text/x-toml'
13
13
 
14
14
  identifier = /\S+/
@@ -24,7 +24,7 @@ module Rouge
24
24
  )
25
25
 
26
26
  keywords_type = %w(
27
- bool char double float int int8 int16 int32 int64 long short size_t
27
+ bool char double float int int8 int16 int32 int64 long short size_t
28
28
  ssize_t string unichar uint uint8 uint16 uint32 uint64 ulong ushort
29
29
  )
30
30
 
@@ -59,7 +59,7 @@ module Rouge
59
59
 
60
60
  # Find Attributes
61
61
  rule %r/'#{id}/i, Name::Attribute
62
-
62
+
63
63
  # Punctuations
64
64
  rule %r/[(),:;]/, Punctuation
65
65
 
@@ -1,4 +1,4 @@
1
- # -*- coding: utf-8 -*- #
1
+ # -*- coding: utf-8 -*- #
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Rouge
@@ -9,7 +9,7 @@ module Rouge
9
9
  tag 'xml'
10
10
  filenames '*.xml', '*.xsl', '*.rss', '*.xslt', '*.xsd', '*.wsdl', '*.svg',
11
11
  '*.plist'
12
- mimetypes 'text/xml', 'application/xml', 'image/svg+xml',
12
+ mimetypes 'text/xml', 'application/xml', 'image/svg+xml',
13
13
  'application/rss+xml', 'application/atom+xml'
14
14
 
15
15
  def self.detect?(text)
@@ -8,7 +8,7 @@ module Rouge
8
8
  desc "Xojo"
9
9
  tag 'xojo'
10
10
  aliases 'realbasic'
11
- filenames '*.xojo_code', '*.xojo_window', '*.xojo_toolbar', '*.xojo_menu'
11
+ filenames '*.xojo_code', '*.xojo_window', '*.xojo_toolbar', '*.xojo_menu', '*.xojo_image', '*.rbbas', '*.rbfrm', '*.rbmnu', '*.rbres', '*.rbtbar'
12
12
 
13
13
  keywords = %w(
14
14
  addhandler aggregates array asc assigns attributes begin break
@@ -30,15 +30,15 @@ module Rouge
30
30
  )
31
31
 
32
32
  operator_words = %w(
33
- addressof and as in is isa mod not or xor
33
+ addressof weakaddressof and as in is isa mod not or xor
34
34
  )
35
35
 
36
36
  state :root do
37
37
  rule %r/\s+/, Text::Whitespace
38
38
 
39
39
  rule %r/rem\b.*?$/i, Comment::Single
40
- rule %r(//.*$), Comment::Single
41
- rule %r/\#tag Note.*\#tag EndNote/m, Comment::Preproc
40
+ rule %r([//'].*$), Comment::Single
41
+ rule %r/\#tag Note.*?\#tag EndNote/mi, Comment::Preproc
42
42
  rule %r/\s*[#].*$/x, Comment::Preproc
43
43
 
44
44
  rule %r/".*?"/, Literal::String::Double
@@ -0,0 +1,332 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class XPath < RegexLexer
7
+ title 'XPath'
8
+ desc 'XML Path Language (XPath) 3.1'
9
+ tag 'xpath'
10
+ filenames '*.xpath'
11
+
12
+ # Terminal literals:
13
+ # https://www.w3.org/TR/xpath-31/#terminal-symbols
14
+ def self.digits
15
+ @digits ||= %r/[0-9]+/
16
+ end
17
+
18
+ def self.decimalLiteral
19
+ @decimalLiteral ||= %r/\.#{digits}|#{digits}\.[0-9]*/
20
+ end
21
+
22
+ def self.doubleLiteral
23
+ @doubleLiteral ||= %r/(\.#{digits})|#{digits}(\.[0-9]*)?[eE][+-]?#{digits}/
24
+ end
25
+
26
+ def self.stringLiteral
27
+ @stringLiteral ||= %r/("(("")|[^"])*")|('(('')|[^'])*')/
28
+ end
29
+
30
+ def self.ncName
31
+ @ncName ||= %r/[a-z_][a-z_\-.0-9]*/i
32
+ end
33
+
34
+ def self.qName
35
+ @qName ||= %r/(?:#{ncName})(?::#{ncName})?/
36
+ end
37
+
38
+ def self.uriQName
39
+ @uriQName ||= %r/Q\{[^{}]*\}#{ncName}/
40
+ end
41
+
42
+ def self.eqName
43
+ @eqName ||= %r/(?:#{uriQName}|#{qName})/
44
+ end
45
+
46
+ def self.commentStart
47
+ @commentStart ||= %r/\(:/
48
+ end
49
+
50
+ def self.openParen
51
+ @openParen ||= %r/\((?!:)/
52
+ end
53
+
54
+ # Terminal symbols:
55
+ # https://www.w3.org/TR/xpath-30/#id-terminal-delimitation
56
+ def self.kindTest
57
+ @kindTest ||= Regexp.union %w(
58
+ element attribute schema-element schema-attribute
59
+ comment text node document-node namespace-node
60
+ )
61
+ end
62
+
63
+ def self.kindTestForPI
64
+ @kindTestForPI ||= Regexp.union %w(processing-instruction)
65
+ end
66
+
67
+ def self.axes
68
+ @axes ||= Regexp.union %w(
69
+ child descendant attribute self descendant-or-self
70
+ following-sibling following namespace
71
+ parent ancestor preceding-sibling preceding ancestor-or-self
72
+ )
73
+ end
74
+
75
+ def self.operators
76
+ @operators ||= Regexp.union %w(, => = := : >= >> > <= << < - * != + // / || |)
77
+ end
78
+
79
+ def self.keywords
80
+ @keywords ||= Regexp.union %w(let for some every if then else return in satisfies)
81
+ end
82
+
83
+ def self.word_operators
84
+ @word_operators ||= Regexp.union %w(
85
+ and or eq ge gt le lt ne is
86
+ div mod idiv
87
+ intersect except union
88
+ to
89
+ )
90
+ end
91
+
92
+ def self.constructorTypes
93
+ @constructorTypes ||= Regexp.union %w(function array map empty-sequence)
94
+ end
95
+
96
+ # Mixin states:
97
+
98
+ state :commentsAndWhitespace do
99
+ rule XPath.commentStart, Comment, :comment
100
+ rule %r/\s+/m, Text::Whitespace
101
+ end
102
+
103
+ # Lexical states:
104
+ # https://www.w3.org/TR/xquery-xpath-parsing/#XPath-lexical-states
105
+ # https://lists.w3.org/Archives/Public/public-qt-comments/2004Aug/0127.html
106
+ # https://www.w3.org/TR/xpath-30/#id-revision-log
107
+ # https://www.w3.org/TR/xpath-31/#id-revision-log
108
+
109
+ state :root do
110
+ mixin :commentsAndWhitespace
111
+
112
+ # Literals
113
+ rule XPath.doubleLiteral, Num::Float
114
+ rule XPath.decimalLiteral, Num::Float
115
+ rule XPath.digits, Num
116
+ rule XPath.stringLiteral, Literal::String
117
+
118
+ # Variables
119
+ rule %r/\$/, Name::Variable, :varname
120
+
121
+ # Operators
122
+ rule XPath.operators, Operator
123
+ rule %r/#{XPath.word_operators}\b/, Operator::Word
124
+ rule %r/#{XPath.keywords}\b/, Keyword
125
+ rule %r/[?,{}()\[\]]/, Punctuation
126
+
127
+ # Functions
128
+ rule %r/(function)(\s*)(#{XPath.openParen})/ do # function declaration
129
+ groups Keyword, Text::Whitespace, Punctuation
130
+ end
131
+ rule %r/(map|array|empty-sequence)/, Keyword # constructors
132
+ rule %r/(#{XPath.kindTest})(\s*)(#{XPath.openParen})/ do # kindtest
133
+ groups Keyword, Text::Whitespace, Punctuation
134
+ push :kindtest
135
+ end
136
+ rule %r/(#{XPath.kindTestForPI})(\s*)(#{XPath.openParen})/ do # processing instruction kindtest
137
+ groups Keyword, Text::Whitespace, Punctuation
138
+ push :kindtestforpi
139
+ end
140
+ rule %r/(#{XPath.eqName})(\s*)(#{XPath.openParen})/ do # function call
141
+ groups Name::Function, Text::Whitespace, Punctuation
142
+ end
143
+ rule %r/(#{XPath.eqName})(\s*)(#)(\s*)(\d+)/ do # namedFunctionRef
144
+ groups Name::Function, Text::Whitespace, Name::Function, Text::Whitespace, Name::Function
145
+ end
146
+
147
+ # Type commands
148
+ rule %r/(cast|castable)(\s+)(as)/ do
149
+ groups Keyword, Text::Whitespace, Keyword
150
+ push :singletype
151
+ end
152
+ rule %r/(treat)(\s+)(as)/ do
153
+ groups Keyword, Text::Whitespace, Keyword
154
+ push :itemtype
155
+ end
156
+ rule %r/(instance)(\s+)(of)/ do
157
+ groups Keyword, Text::Whitespace, Keyword
158
+ push :itemtype
159
+ end
160
+ rule %r/(as)\b/ do
161
+ token Keyword
162
+ push :itemtype
163
+ end
164
+
165
+ # Paths
166
+ rule %r/(#{XPath.ncName})(\s*)(:)(\s*)(\*)/ do
167
+ groups Name::Tag, Text::Whitespace, Punctuation, Text::Whitespace, Operator
168
+ end
169
+ rule %r/(\*)(\s*)(:)(\s*)(#{XPath.ncName})/ do
170
+ groups Operator, Text::Whitespace, Punctuation, Text::Whitespace, Name::Tag
171
+ end
172
+ rule %r/(#{XPath.axes})(\s*)(::)/ do
173
+ groups Keyword, Text::Whitespace, Operator
174
+ end
175
+ rule %r/\.\.|\.|\*/, Operator
176
+ rule %r/@/, Name::Attribute, :attrname
177
+ rule XPath.eqName, Name::Tag
178
+ end
179
+
180
+ state :singletype do
181
+ mixin :commentsAndWhitespace
182
+
183
+ # Type name
184
+ rule XPath.eqName do
185
+ token Keyword::Type
186
+ pop!
187
+ end
188
+ end
189
+
190
+ state :itemtype do
191
+ mixin :commentsAndWhitespace
192
+
193
+ # Type tests
194
+ rule %r/(#{XPath.kindTest})(\s*)(#{XPath.openParen})/ do
195
+ groups Keyword::Type, Text::Whitespace, Punctuation
196
+ # go to kindtest then occurrenceindicator
197
+ goto :occurrenceindicator
198
+ push :kindtest
199
+ end
200
+ rule %r/(#{XPath.kindTestForPI})(\s*)(#{XPath.openParen})/ do
201
+ groups Keyword::Type, Text::Whitespace, Punctuation
202
+ # go to kindtestforpi then occurrenceindicator
203
+ goto :occurrenceindicator
204
+ push :kindtestforpi
205
+ end
206
+ rule %r/(item)(\s*)(#{XPath.openParen})(\s*)(\))/ do
207
+ groups Keyword::Type, Text::Whitespace, Punctuation, Text::Whitespace, Punctuation
208
+ goto :occurrenceindicator
209
+ end
210
+ rule %r/(#{XPath.constructorTypes})(\s*)(#{XPath.openParen})/ do
211
+ groups Keyword::Type, Text::Whitespace, Punctuation
212
+ end
213
+
214
+ # Type commands
215
+ rule %r/(cast|castable)(\s+)(as)/ do
216
+ groups Keyword, Text::Whitespace, Keyword
217
+ goto :singletype
218
+ end
219
+ rule %r/(treat)(\s+)(as)/ do
220
+ groups Keyword, Text::Whitespace, Keyword
221
+ goto :itemtype
222
+ end
223
+ rule %r/(instance)(\s+)(of)/ do
224
+ groups Keyword, Text::Whitespace, Keyword
225
+ goto :itemtype
226
+ end
227
+ rule %r/(as)\b/, Keyword
228
+
229
+ # Operators
230
+ rule XPath.operators do
231
+ token Operator
232
+ pop!
233
+ end
234
+ rule %r/#{XPath.word_operators}\b/ do
235
+ token Operator::Word
236
+ pop!
237
+ end
238
+ rule %r/#{XPath.keywords}\b/ do
239
+ token Keyword
240
+ pop!
241
+ end
242
+ rule %r/[\[),]/ do
243
+ token Punctuation
244
+ pop!
245
+ end
246
+
247
+ # Other types (e.g. xs:double)
248
+ rule XPath.eqName do
249
+ token Keyword::Type
250
+ goto :occurrenceindicator
251
+ end
252
+ end
253
+
254
+ # For pseudo-parameters for the KindTest productions
255
+ state :kindtest do
256
+ mixin :commentsAndWhitespace
257
+
258
+ # Pseudo-parameters:
259
+ rule %r/[?*]/, Operator
260
+ rule %r/,/, Punctuation
261
+ rule %r/(element|schema-element)(\s*)(#{XPath.openParen})/ do
262
+ groups Keyword::Type, Text::Whitespace, Punctuation
263
+ push :kindtest
264
+ end
265
+ rule XPath.eqName, Name::Tag
266
+
267
+ # End of pseudo-parameters
268
+ rule %r/\)/, Punctuation, :pop!
269
+ end
270
+
271
+ # Similar to :kindtest, but recognizes NCNames instead of EQNames
272
+ state :kindtestforpi do
273
+ mixin :commentsAndWhitespace
274
+
275
+ # Pseudo-parameters
276
+ rule XPath.ncName, Name
277
+ rule XPath.stringLiteral, Literal::String
278
+
279
+ # End of pseudo-parameters
280
+ rule %r/\)/, Punctuation, :pop!
281
+ end
282
+
283
+ state :occurrenceindicator do
284
+ mixin :commentsAndWhitespace
285
+
286
+ # Occurrence indicator
287
+ rule %r/[?*+]/ do
288
+ token Operator
289
+ pop!
290
+ end
291
+
292
+ # Otherwise, lex it in root state:
293
+ rule %r/(?![?*+])/ do
294
+ pop!
295
+ end
296
+ end
297
+
298
+ state :varname do
299
+ mixin :commentsAndWhitespace
300
+
301
+ # Function call
302
+ rule %r/(#{XPath.eqName})(\s*)(#{XPath.openParen})/ do
303
+ groups Name::Variable, Text::Whitespace, Punctuation
304
+ pop!
305
+ end
306
+
307
+ # Variable name
308
+ rule XPath.eqName, Name::Variable, :pop!
309
+ end
310
+
311
+ state :attrname do
312
+ mixin :commentsAndWhitespace
313
+
314
+ # Attribute name
315
+ rule XPath.eqName, Name::Attribute, :pop!
316
+ rule %r/\*/, Operator, :pop!
317
+ end
318
+
319
+ state :comment do
320
+ # Comment end
321
+ rule %r/:\)/, Comment, :pop!
322
+
323
+ # Nested comment
324
+ rule XPath.commentStart, Comment, :comment
325
+
326
+ # Comment contents
327
+ rule %r/[^:(]+/m, Comment
328
+ rule %r/[:(]/, Comment
329
+ end
330
+ end
331
+ end
332
+ end