rouge 3.6.0 → 3.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/lib/rouge/demos/ada +26 -0
  4. data/lib/rouge/demos/apex +9 -0
  5. data/lib/rouge/demos/armasm +12 -0
  6. data/lib/rouge/demos/batchfile +3 -0
  7. data/lib/rouge/demos/bbcbasic +6 -0
  8. data/lib/rouge/demos/clean +6 -0
  9. data/lib/rouge/demos/cmhg +8 -0
  10. data/lib/rouge/demos/csvs +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/liquid +0 -1
  21. data/lib/rouge/demos/lustre +6 -0
  22. data/lib/rouge/demos/lutin +18 -0
  23. data/lib/rouge/demos/mason +22 -0
  24. data/lib/rouge/demos/msgtrans +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/reasonml +12 -0
  28. data/lib/rouge/demos/robot_framework +27 -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/formatters/html_line_table.rb +3 -1
  33. data/lib/rouge/formatters/tex.rb +14 -12
  34. data/lib/rouge/guessers/disambiguation.rb +17 -0
  35. data/lib/rouge/lexers/ada.rb +162 -0
  36. data/lib/rouge/lexers/apex.rb +126 -0
  37. data/lib/rouge/lexers/armasm.rb +145 -0
  38. data/lib/rouge/lexers/batchfile.rb +164 -0
  39. data/lib/rouge/lexers/bbcbasic.rb +112 -0
  40. data/lib/rouge/lexers/clean.rb +156 -0
  41. data/lib/rouge/lexers/cmhg.rb +34 -0
  42. data/lib/rouge/lexers/common_lisp.rb +1 -1
  43. data/lib/rouge/lexers/console.rb +1 -1
  44. data/lib/rouge/lexers/coq.rb +12 -9
  45. data/lib/rouge/lexers/cpp.rb +4 -1
  46. data/lib/rouge/lexers/csvs.rb +44 -0
  47. data/lib/rouge/lexers/cuda.rb +35 -0
  48. data/lib/rouge/lexers/cython.rb +151 -0
  49. data/lib/rouge/lexers/eex.rb +51 -0
  50. data/lib/rouge/lexers/elixir.rb +20 -9
  51. data/lib/rouge/lexers/epp.rb +51 -0
  52. data/lib/rouge/lexers/escape.rb +3 -0
  53. data/lib/rouge/lexers/gdscript.rb +171 -0
  54. data/lib/rouge/lexers/gherkin.rb +4 -2
  55. data/lib/rouge/lexers/graphql.rb +10 -3
  56. data/lib/rouge/lexers/handlebars.rb +14 -3
  57. data/lib/rouge/lexers/haxe.rb +246 -0
  58. data/lib/rouge/lexers/hocon.rb +86 -0
  59. data/lib/rouge/lexers/hql.rb +139 -0
  60. data/lib/rouge/lexers/html.rb +2 -2
  61. data/lib/rouge/lexers/http.rb +5 -5
  62. data/lib/rouge/lexers/igorpro.rb +1 -1
  63. data/lib/rouge/lexers/javascript.rb +1 -1
  64. data/lib/rouge/lexers/jsl.rb +55 -0
  65. data/lib/rouge/lexers/json.rb +43 -5
  66. data/lib/rouge/lexers/julia.rb +1 -1
  67. data/lib/rouge/lexers/kotlin.rb +21 -28
  68. data/lib/rouge/lexers/liquid.rb +82 -108
  69. data/lib/rouge/lexers/lustre.rb +79 -0
  70. data/lib/rouge/lexers/lutin.rb +33 -0
  71. data/lib/rouge/lexers/make.rb +39 -12
  72. data/lib/rouge/lexers/mason.rb +115 -0
  73. data/lib/rouge/lexers/matlab.rb +4 -2
  74. data/lib/rouge/lexers/matlab/builtins.yml +3515 -0
  75. data/lib/rouge/lexers/msgtrans.rb +26 -0
  76. data/lib/rouge/lexers/ocaml.rb +12 -48
  77. data/lib/rouge/lexers/ocaml/common.rb +53 -0
  78. data/lib/rouge/lexers/opentype_feature_file.rb +113 -0
  79. data/lib/rouge/lexers/php.rb +31 -9
  80. data/lib/rouge/lexers/php/builtins.rb +181 -174
  81. data/lib/rouge/lexers/plain_text.rb +1 -1
  82. data/lib/rouge/lexers/puppet.rb +2 -2
  83. data/lib/rouge/lexers/q.rb +1 -1
  84. data/lib/rouge/lexers/r.rb +2 -3
  85. data/lib/rouge/lexers/reasonml.rb +65 -0
  86. data/lib/rouge/lexers/robot_framework.rb +249 -0
  87. data/lib/rouge/lexers/rust.rb +12 -9
  88. data/lib/rouge/lexers/sas.rb +563 -0
  89. data/lib/rouge/lexers/sed.rb +1 -1
  90. data/lib/rouge/lexers/shell.rb +5 -3
  91. data/lib/rouge/lexers/smarty.rb +10 -10
  92. data/lib/rouge/lexers/sparql.rb +129 -0
  93. data/lib/rouge/lexers/sql.rb +26 -6
  94. data/lib/rouge/lexers/swift.rb +1 -1
  95. data/lib/rouge/lexers/terraform.rb +8 -0
  96. data/lib/rouge/tex_theme_renderer.rb +5 -1
  97. data/lib/rouge/themes/magritte.rb +3 -3
  98. data/lib/rouge/themes/thankful_eyes.rb +1 -1
  99. data/lib/rouge/themes/tulip.rb +1 -1
  100. data/lib/rouge/version.rb +1 -1
  101. data/rouge.gemspec +4 -3
  102. metadata +61 -6
  103. data/lib/rouge/lexers/matlab/builtins.rb +0 -13
@@ -0,0 +1,86 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ load_lexer 'json.rb'
7
+
8
+ class HOCON < JSON
9
+ title 'HOCON'
10
+ desc "Human-Optimized Config Object Notation (https://github.com/lightbend/config)"
11
+ tag 'hocon'
12
+ filenames '*.hocon'
13
+
14
+ state :comments do
15
+ # Comments
16
+ rule %r(//.*?$), Comment::Single
17
+ rule %r(#.*?$), Comment::Single
18
+ end
19
+
20
+ prepend :root do
21
+ mixin :comments
22
+ end
23
+
24
+ prepend :object do
25
+ # Keywords
26
+ rule %r/\b(?:include|url|file|classpath)\b/, Keyword
27
+ end
28
+
29
+ state :name do
30
+ rule %r/("(?:\"|[^"\n])*?")(\s*)([:=]|(?={))/ do
31
+ groups Name::Label, Text::Whitespace, Punctuation
32
+ end
33
+
34
+ rule %r/([-\w.]+)(\s*)([:=]|(?={))/ do
35
+ groups Name::Label, Text::Whitespace, Punctuation
36
+ end
37
+ end
38
+
39
+ state :value do
40
+ mixin :comments
41
+
42
+ rule %r/\n/, Text::Whitespace
43
+ rule %r/\s+/, Text::Whitespace
44
+
45
+ mixin :constants
46
+
47
+ # Interpolation
48
+ rule %r/[$][{][?]?/, Literal::String::Interpol, :interpolation
49
+
50
+ # Strings
51
+ rule %r/"""/, Literal::String::Double, :multiline_string
52
+ rule %r/"/, Str::Double, :string
53
+
54
+ rule %r/\[/, Punctuation, :array
55
+ rule %r/{/, Punctuation, :object
56
+
57
+ # Symbols (only those not handled by JSON)
58
+ rule %r/[()=]/, Punctuation
59
+
60
+ # Values
61
+ rule %r/[^$"{}\[\]:=,\+#`^?!@*&]+?/, Literal
62
+ end
63
+
64
+ state :interpolation do
65
+ rule %r/[\w\-\.]+?/, Name::Variable
66
+ rule %r/}/, Literal::String::Interpol, :pop!
67
+ end
68
+
69
+ prepend :string do
70
+ rule %r/[$][{][?]?/, Literal::String::Interpol, :interpolation
71
+ rule %r/[^\\"\${]+/, Literal::String::Double
72
+ end
73
+
74
+ state :multiline_string do
75
+ rule %r/"[^"]{1,2}/, Literal::String::Double
76
+ mixin :string
77
+ rule %r/"""/, Literal::String::Double, :pop!
78
+ end
79
+
80
+ prepend :constants do
81
+ # Numbers (handle the case where we have multiple periods, ie. IP addresses)
82
+ rule %r/\d+\.(\d+\.?){3,}/, Literal
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,139 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ load_lexer 'sql.rb'
6
+
7
+ class HQL < SQL
8
+ title "HQL"
9
+ desc "Hive Query Language SQL dialect"
10
+ tag 'hql'
11
+ filenames '*.hql'
12
+
13
+ def self.keywords
14
+ # sources:
15
+ # https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL
16
+ # https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF
17
+ @keywords ||= Set.new(%w(
18
+ ADD ADMIN AFTER ANALYZE ARCHIVE ASC BEFORE BUCKET BUCKETS CASCADE
19
+ CHANGE CLUSTER CLUSTERED CLUSTERSTATUS COLLECTION COLUMNS COMMENT
20
+ COMPACT COMPACTIONS COMPUTE CONCATENATE CONTINUE DATA DATABASES
21
+ DATETIME DAY DBPROPERTIES DEFERRED DEFINED DELIMITED DEPENDENCY DESC
22
+ DIRECTORIES DIRECTORY DISABLE DISTRIBUTE ELEM_TYPE ENABLE ESCAPED
23
+ EXCLUSIVE EXPLAIN EXPORT FIELDS FILE FILEFORMAT FIRST FORMAT FORMATTED
24
+ FUNCTIONS HOLD_DDLTIME HOUR IDXPROPERTIES IGNORE INDEX INDEXES INPATH
25
+ INPUTDRIVER INPUTFORMAT ITEMS JAR KEYS KEY_TYPE LIMIT LINES LOAD
26
+ LOCATION LOCK LOCKS LOGICAL LONG MAPJOIN MATERIALIZED METADATA MINUS
27
+ MINUTE MONTH MSCK NOSCAN NO_DROP OFFLINE OPTION OUTPUTDRIVER
28
+ OUTPUTFORMAT OVERWRITE OWNER PARTITIONED PARTITIONS PLUS PRETTY
29
+ PRINCIPALS PROTECTION PURGE READ READONLY REBUILD RECORDREADER
30
+ RECORDWRITER REGEXP RELOAD RENAME REPAIR REPLACE REPLICATION RESTRICT
31
+ REWRITE RLIKE ROLE ROLES SCHEMA SCHEMAS SECOND SEMI SERDE
32
+ SERDEPROPERTIES SERVER SETS SHARED SHOW SHOW_DATABASE SKEWED SORT
33
+ SORTED SSL STATISTICS STORED STREAMTABLE STRING STRUCT TABLES
34
+ TBLPROPERTIES TEMPORARY TERMINATED TINYINT TOUCH TRANSACTIONS UNARCHIVE
35
+ UNDO UNIONTYPE UNLOCK UNSET UNSIGNED URI USE UTC UTCTIMESTAMP
36
+ VALUE_TYPE VIEW WHILE YEAR IF
37
+
38
+ ALL ALTER AND ARRAY AS AUTHORIZATION BETWEEN BIGINT BINARY BOOLEAN
39
+ BOTH BY CASE CAST CHAR COLUMN CONF CREATE CROSS CUBE CURRENT
40
+ CURRENT_DATE CURRENT_TIMESTAMP CURSOR DATABASE DATE DECIMAL DELETE
41
+ DESCRIBE DISTINCT DOUBLE DROP ELSE END EXCHANGE EXISTS EXTENDED
42
+ EXTERNAL FALSE FETCH FLOAT FOLLOWING FOR FROM FULL FUNCTION GRANT
43
+ GROUP GROUPING HAVING IF IMPORT IN INNER INSERT INT INTERSECT
44
+ INTERVAL INTO IS JOIN LATERAL LEFT LESS LIKE LOCAL MACRO MAP MORE
45
+ NONE NOT NULL OF ON OR ORDER OUT OUTER OVER PARTIALSCAN PARTITION
46
+ PERCENT PRECEDING PRESERVE PROCEDURE RANGE READS REDUCE REVOKE RIGHT
47
+ ROLLUP ROW ROWS SELECT SET SMALLINT TABLE TABLESAMPLE THEN TIMESTAMP
48
+ TO TRANSFORM TRIGGER TRUE TRUNCATE UNBOUNDED UNION UNIQUEJOIN UPDATE
49
+ USER USING UTC_TMESTAMP VALUES VARCHAR WHEN WHERE WINDOW WITH
50
+
51
+ AUTOCOMMIT ISOLATION LEVEL OFFSET SNAPSHOT TRANSACTION WORK WRITE
52
+
53
+ COMMIT ONLY REGEXP RLIKE ROLLBACK START
54
+
55
+ ABORT KEY LAST NORELY NOVALIDATE NULLS RELY VALIDATE
56
+
57
+ CACHE CONSTRAINT FOREIGN PRIMARY REFERENCES
58
+
59
+ DETAIL DOW EXPRESSION OPERATOR QUARTER SUMMARY VECTORIZATION WEEK YEARS MONTHS WEEKS DAYS HOURS MINUTES SECONDS
60
+
61
+ DAYOFWEEK EXTRACT FLOOR INTEGER PRECISION VIEWS
62
+
63
+ TIMESTAMPTZ ZONE
64
+
65
+ TIME NUMERIC
66
+
67
+ NAMED_STRUCT CREATE_UNION
68
+
69
+ ROUND BROUND FLOOR CEIL CEILING RAND EXP LN LOG10 LOG2 LOG POW POWER SQRT BIN
70
+ HEX UNHEX CONV ABS PMOD SIN ASIN COS ACOS TAN ATAN DEGREES RADIANS POSITIVE
71
+ NEGATIVE SIGN E PI FACTORIAL CBRT SHIFTLEFT SHIFTRIGHT SHIFTRIGHTUNSIGNED
72
+ GREATEST LEAST WIDTH_BUCKET SIZE SIZE MAP_KEYS MAP_VALUES ARRAY_CONTAINS
73
+ SORT_ARRAY BINARY CAST FROM_UNIXTIME UNIX_TIMESTAMP UNIX_TIMESTAMP
74
+ UNIX_TIMESTAMP TO_DATE YEAR QUARTER MONTH DAY DAYOFMONTH HOUR MINUTE SECOND
75
+ WEEKOFYEAR EXTRACT DATEDIFF DATE_ADD DATE_SUB FROM_UTC_TIMESTAMP
76
+ TO_UTC_TIMESTAMP CURRENT_DATE CURRENT_TIMESTAMP ADD_MONTHS LAST_DAY NEXT_DAY
77
+ TRUNC MONTHS_BETWEEN DATE_FORMAT IF ISNULL ISNOTNULL NVL COALESCE CASE WHEN
78
+ then else end NULLIF ASSERT_TRUE ASCII BASE64 CHARACTER_LENGTH CHR CONCAT
79
+ CONTEXT_NGRAMS CONCAT_WS CONCAT_WS DECODE ELT ENCODE FIELD FIND_IN_SET
80
+ FORMAT_NUMBER GET_JSON_OBJECT IN_FILE INSTR LENGTH LOCATE LOWER LCASE LPAD LTRIM
81
+ NGRAMS OCTET_LENGTH PARSE_URL PRINTF REGEXP_EXTRACT REGEXP_REPLACE REPEAT
82
+ REPLACE REVERSE RPAD RTRIM SENTENCES SPACE SPLIT STR_TO_MAP SUBSTR SUBSTRING
83
+ SUBSTRING_INDEX TRANSLATE TRIM UNBASE64 UPPER UCASE INITCAP LEVENSHTEIN SOUNDEX
84
+ MASK MASK_FIRST_N MASK_LAST_N MASK_SHOW_FIRST_N MASK_SHOW_LAST_N MASK_HASH
85
+ JAVA_METHOD REFLECT HASH CURRENT_USER LOGGED_IN_USER CURRENT_DATABASE MD5 SHA1
86
+ SHA CRC32 SHA2 AES_ENCRYPT AES_DECRYPT VERSION COUNT SUM AVG MIN MAX VARIANCE
87
+ VAR_POP VAR_SAMP STDDEV_POP STDDEV_SAMP COVAR_POP COVAR_SAMP CORR PERCENTILE
88
+ PERCENTILE_APPROX PERCENTILE_APPROX REGR_AVGX REGR_AVGY REGR_COUNT
89
+ REGR_INTERCEPT REGR_R2 REGR_SLOPE REGR_SXX REGR_SXY REGR_SYY HISTOGRAM_NUMERIC
90
+ COLLECT_SET COLLECT_LIST NTILE EXPLODE EXPLODE POSEXPLODE INLINE STACK
91
+
92
+ JSON_TUPLE PARSE_URL_TUPLE
93
+
94
+ XPATH XPATH_SHORT XPATH_INT XPATH_LONG XPATH_FLOAT XPATH_DOUBLE
95
+ XPATH_NUMBER XPATH_STRING GET_JSON_OBJECT JSON_TUPLE
96
+
97
+ PARSE_URL_TUPLE
98
+ ))
99
+ end
100
+
101
+ def self.keywords_type
102
+ # source: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Types
103
+ @keywords_type ||= Set.new(%w(
104
+ TINYINT SMALLINT INT INTEGER BIGINT FLOAT DOUBLE PRECISION DECIMAL NUMERIC
105
+ TIMESTAMP DATE INTERVAL
106
+ STRING VARCHAR CHAR
107
+ BOOLEAN BINARY
108
+ ARRAY MAP STRUCT UNIONTYPE
109
+ ))
110
+ end
111
+
112
+ prepend :root do
113
+ # a double-quoted string is a string literal in Hive QL.
114
+ rule %r/"/, Str::Double, :double_string
115
+
116
+ # interpolation of variables through ${...}
117
+ rule %r/\$\{/, Name::Variable, :hive_variable
118
+ end
119
+
120
+ prepend :single_string do
121
+ rule %r/\$\{/, Name::Variable, :hive_variable
122
+ rule %r/[^\\'\$]+/, Str::Single
123
+ end
124
+
125
+ prepend :double_string do
126
+ rule %r/\$\{/, Name::Variable, :hive_variable
127
+ # double-quoted strings are string literals so need to change token
128
+ rule %r/"/, Str::Double, :pop!
129
+ rule %r/[^\\"\$]+/, Str::Double
130
+ end
131
+
132
+ state :hive_variable do
133
+ rule %r/\}/, Name::Variable, :pop!
134
+ rule %r/[^\}]+/, Name::Variable
135
+ end
136
+
137
+ end
138
+ end
139
+ end
@@ -83,8 +83,8 @@ module Rouge
83
83
 
84
84
  state :tag do
85
85
  rule %r/\s+/m, Text
86
- rule %r/[a-zA-Z0-9_:-]+\s*=\s*/m, Name::Attribute, :attr
87
- rule %r/[a-zA-Z0-9_:-]+/, Name::Attribute
86
+ rule %r/[a-zA-Z0-9_:\[\]()*.-]+\s*=\s*/m, Name::Attribute, :attr
87
+ rule %r/[a-zA-Z0-9_:#*-]+/, Name::Attribute
88
88
  rule %r(/?\s*>)m, Name::Tag, :pop!
89
89
  end
90
90
 
@@ -26,8 +26,8 @@ module Rouge
26
26
  # request
27
27
  rule %r(
28
28
  (#{HTTP.http_methods.join('|')})([ ]+) # method
29
- ([^ ]+)([ ]+) # path
30
- (HTTPS?)(/)(1[.][01])(\r?\n|$) # http version
29
+ ([^ ]+)([ ]+) # path
30
+ (HTTPS?)(/)(\d(?:\.\d)?)(\r?\n|$) # http version
31
31
  )ox do
32
32
  groups(
33
33
  Name::Function, Text,
@@ -40,9 +40,9 @@ module Rouge
40
40
 
41
41
  # response
42
42
  rule %r(
43
- (HTTPS?)(/)(1[.][01])([ ]+) # http version
44
- (\d{3})([ ]+) # status
45
- ([^\r\n]+)(\r?\n|$) # status message
43
+ (HTTPS?)(/)(\d(?:\.\d))([ ]+) # http version
44
+ (\d{3})([ ]+)? # status
45
+ ([^\r\n]*)?(\r?\n|$) # status message
46
46
  )x do
47
47
  groups(
48
48
  Keyword, Operator, Num, Text,
@@ -20,7 +20,7 @@ module Rouge
20
20
  break return continue
21
21
  for endfor do while
22
22
  case default
23
- try catch endtry
23
+ try catch endtry
24
24
  abortonrte
25
25
  )
26
26
  end
@@ -73,7 +73,7 @@ module Rouge
73
73
  end
74
74
 
75
75
  state :regex_end do
76
- rule %r/[gim]+/, Str::Regex, :pop!
76
+ rule %r/[gimuy]+/, Str::Regex, :pop!
77
77
  rule(//) { pop! }
78
78
  end
79
79
 
@@ -0,0 +1,55 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class JSL < RegexLexer
7
+ title "JSL"
8
+ desc "The JMP Scripting Language (JSL) (jmp.com)"
9
+
10
+ tag 'jsl'
11
+ filenames '*.jsl'
12
+
13
+ state :root do
14
+ rule %r/\s+/m, Text::Whitespace
15
+
16
+ rule %r(//.*?$), Comment::Single
17
+ rule %r(/\*.*?\*/)m, Comment::Multiline
18
+
19
+ # messages
20
+ rule %r/(<<)(.*?)(\(|;)/ do |m|
21
+ groups Operator, Name::Function, Punctuation
22
+ end
23
+
24
+ # covers built-in and custom functions
25
+ rule %r/([a-z_][\w\s'%.\\]*)(\()/i do |m|
26
+ groups Keyword, Punctuation
27
+ end
28
+
29
+ rule %r/\b[+-]?(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+|\.)(?:e[+-]?[0-9]+)?i?\b/i, Num
30
+
31
+ rule %r/\d{2}(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\d{2}(\d{2})?(:\d{2}:\d{2}(:\d{2}(\.\d*)?)?)?/i, Literal::Date
32
+
33
+ rule %r/::[a-z_][\w\s'%.\\]*/i, Name::Variable
34
+ rule %r/:\w+/, Name
35
+ rule %r/[a-z_][\w\s'%.\\]*/i, Name::Variable
36
+ rule %r/"(?:\\!"|[^"])*?"n/m, Name::Variable
37
+
38
+ rule %r/(")(\\\[)(.*?)(\]\\)(")/m do
39
+ groups Str::Double, Str::Escape, Str::Double, Str::Escape, Str::Double # escaped string
40
+ end
41
+ rule %r/"/, Str::Double, :dq
42
+
43
+ rule %r/[-+*\/!%&<>\|=:]/, Operator
44
+ rule %r/[\[\](){},;]/, Punctuation
45
+ end
46
+
47
+ state :dq do
48
+ rule %r/\\![btrnNf0\\"]/, Str::Escape
49
+ rule %r/\\/, Str::Double
50
+ rule %r/"/, Str::Double, :pop!
51
+ rule %r/[^\\"]*/m, Str::Double
52
+ end
53
+ end
54
+ end
55
+ end
@@ -12,13 +12,39 @@ module Rouge
12
12
  'application/hal+json', 'application/problem+json',
13
13
  'application/schema+json'
14
14
 
15
+ state :whitespace do
16
+ rule %r/\s+/, Text::Whitespace
17
+ end
18
+
15
19
  state :root do
16
- rule %r/\s+/m, Text::Whitespace
20
+ mixin :whitespace
21
+ rule %r/{/, Punctuation, :object
22
+ rule %r/\[/, Punctuation, :array
23
+
24
+ mixin :name
25
+ mixin :value
26
+ end
27
+
28
+ state :object do
29
+ mixin :whitespace
30
+ mixin :name
31
+ mixin :value
32
+ rule %r/}/, Punctuation, :pop!
33
+ rule %r/,/, Punctuation
34
+ end
35
+
36
+ state :name do
37
+ rule %r/("(?:\\.|[^"\\\n])*?")(\s*)(:)/ do
38
+ groups Name::Label, Text::Whitespace, Punctuation
39
+ end
40
+ end
41
+
42
+ state :value do
43
+ mixin :whitespace
44
+ mixin :constants
17
45
  rule %r/"/, Str::Double, :string
18
- rule %r/(?:true|false|null)\b/, Keyword::Constant
19
- rule %r/[{},:\[\]]/, Punctuation
20
- rule %r/-?(?:0|[1-9]\d*)\.\d+(?:e[+-]?\d+)?/i, Num::Float
21
- rule %r/-?(?:0|[1-9]\d*)(?:e[+-]?\d+)?/i, Num::Integer
46
+ rule %r/\[/, Punctuation, :array
47
+ rule %r/{/, Punctuation, :object
22
48
  end
23
49
 
24
50
  state :string do
@@ -26,6 +52,18 @@ module Rouge
26
52
  rule %r/\\./, Str::Escape
27
53
  rule %r/"/, Str::Double, :pop!
28
54
  end
55
+
56
+ state :array do
57
+ mixin :value
58
+ rule %r/\]/, Punctuation, :pop!
59
+ rule %r/,/, Punctuation
60
+ end
61
+
62
+ state :constants do
63
+ rule %r/(?:true|false|null)/, Keyword::Constant
64
+ rule %r/-?(?:0|[1-9]\d*)\.\d+(?:e[+-]?\d+)?/i, Num::Float
65
+ rule %r/-?(?:0|[1-9]\d*)(?:e[+-]?\d+)?/i, Num::Integer
66
+ end
29
67
  end
30
68
  end
31
69
  end
@@ -199,7 +199,7 @@ module Rouge
199
199
  end
200
200
 
201
201
  # types
202
- rule %r/((mutable )?struct|(abstract|primitive) type)((?:\s|\\\s)+)/ do
202
+ rule %r/((?:mutable )?struct|(?:abstract|primitive) type)((?:\s|\\\s)+)/ do
203
203
  groups Keyword, Name::Class
204
204
  push :typename
205
205
  end
@@ -24,19 +24,12 @@ module Rouge
24
24
  while yield
25
25
  )
26
26
 
27
- name = %r'@?[_\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Nl}][\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Nl}\p{Nd}\p{Pc}\p{Cf}\p{Mn}\p{Mc}]*'
28
- name_backtick = %r'#{name}|`#{name}`'
27
+ name_chars = %r'[-_\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Nl}\p{Nd}\p{Pc}\p{Cf}\p{Mn}\p{Mc}]*'
29
28
 
30
- id = %r'(#{name_backtick})'
29
+ class_name = %r'`?[\p{Lu}]#{name_chars}`?'
30
+ name = %r'`?[_\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Nl}]#{name_chars}`?'
31
31
 
32
32
  state :root do
33
- rule %r'(\))(\s*)(:)(\s+)(#{name_backtick})(<)' do
34
- groups Punctuation, Text, Punctuation, Text, Name::Class, Punctuation
35
- push :generic_parameters
36
- end
37
- rule %r'(\))(\s*)(:)(\s+)(#{name_backtick})' do
38
- groups Punctuation, Text, Punctuation, Text, Name::Class
39
- end
40
33
  rule %r'\b(companion)(\s+)(object)\b' do
41
34
  groups Keyword, Text, Keyword
42
35
  end
@@ -48,13 +41,6 @@ module Rouge
48
41
  groups Keyword, Text
49
42
  push :function
50
43
  end
51
- rule %r'(#{name_backtick})(:)(\s+)(#{name_backtick})(<)' do
52
- groups Name::Variable, Punctuation, Text, Name::Class, Punctuation
53
- push :generic_parameters
54
- end
55
- rule %r'(#{name_backtick})(:)(\s+)(#{name_backtick})' do
56
- groups Name::Variable, Punctuation, Text, Name::Class
57
- end
58
44
  rule %r'\b(package|import)(\s+)' do
59
45
  groups Keyword, Text
60
46
  push :package
@@ -67,8 +53,8 @@ module Rouge
67
53
  groups Keyword::Declaration, Text
68
54
  push :property
69
55
  end
70
- rule %r/\bfun\b/, Keyword
71
- rule %r/\b(?:#{keywords.join('|')})\b/, Keyword
56
+ rule %r'\bfun\b', Keyword
57
+ rule %r'\b(?:#{keywords.join('|')})\b', Keyword
72
58
  rule %r'^\s*\[.*?\]', Name::Attribute
73
59
  rule %r'[^\S\n]+', Text
74
60
  rule %r'\\\n', Text # line continuation
@@ -85,43 +71,50 @@ module Rouge
85
71
  rule %r'"(\\\\|\\"|[^"\n])*["\n]'m, Str
86
72
  rule %r"'\\.'|'[^\\]'", Str::Char
87
73
  rule %r"[0-9](\.[0-9]+)?([eE][+-][0-9]+)?[flFL]?|0[xX][0-9a-fA-F]+[Ll]?", Num
88
- rule %r/@#{id}/, Name::Decorator
89
- rule id, Name
74
+ rule %r'(@#{class_name})', Name::Decorator
75
+ rule %r'(#{class_name})(<)' do
76
+ groups Name::Class, Punctuation
77
+ push :generic_parameters
78
+ end
79
+ rule class_name, Name::Class
80
+ rule %r'(#{name})(?=\s*[({])', Name::Function
81
+ rule name, Name
90
82
  end
91
83
 
92
84
  state :package do
93
- rule %r/\S+/, Name::Namespace, :pop!
85
+ rule %r'\S+', Name::Namespace, :pop!
94
86
  end
95
87
 
96
88
  state :class do
97
- rule id, Name::Class, :pop!
89
+ rule class_name, Name::Class, :pop!
98
90
  end
99
91
 
100
92
  state :function do
101
93
  rule %r'(<)', Punctuation, :generic_parameters
102
94
  rule %r'(\s+)', Text
103
- rule %r'(#{name_backtick})(\.)' do
95
+ rule %r'(#{class_name})(\.)' do
104
96
  groups Name::Class, Punctuation
105
97
  end
106
- rule id, Name::Function, :pop!
98
+ rule name, Name::Function, :pop!
107
99
  end
108
100
 
109
101
  state :generic_parameters do
110
- rule id, Name::Class
102
+ rule class_name, Name::Class
103
+ rule %r'(<)', Punctuation, :generic_parameters
111
104
  rule %r'(,)', Punctuation
112
105
  rule %r'(\s+)', Text
113
106
  rule %r'(>)', Punctuation, :pop!
114
107
  end
115
108
 
116
109
  state :property do
117
- rule id, Name::Property, :pop!
110
+ rule name, Name::Property, :pop!
118
111
  end
119
112
 
120
113
  state :destructure do
121
114
  rule %r'(,)', Punctuation
122
115
  rule %r'(\))', Punctuation, :pop!
123
116
  rule %r'(\s+)', Text
124
- rule id, Name::Property
117
+ rule name, Name::Property
125
118
  end
126
119
 
127
120
  state :comment do