rouge 3.17.0 → 3.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rouge.rb +65 -51
- data/lib/rouge/demos/cypher +5 -0
- data/lib/rouge/demos/datastudio +21 -0
- data/lib/rouge/demos/ghc-cmm +23 -0
- data/lib/rouge/demos/isbl +4 -0
- data/lib/rouge/demos/rego +8 -0
- data/lib/rouge/demos/solidity +13 -0
- data/lib/rouge/demos/yang +17 -0
- data/lib/rouge/lexer.rb +2 -1
- data/lib/rouge/lexers/apache.rb +4 -8
- data/lib/rouge/lexers/apache/keywords.rb +15 -0
- data/lib/rouge/lexers/cmake.rb +1 -0
- data/lib/rouge/lexers/console.rb +53 -37
- data/lib/rouge/lexers/cpp.rb +12 -5
- data/lib/rouge/lexers/cypher.rb +108 -0
- data/lib/rouge/lexers/datastudio.rb +138 -0
- data/lib/rouge/lexers/fsharp.rb +1 -0
- data/lib/rouge/lexers/ghc_cmm.rb +340 -0
- data/lib/rouge/lexers/gherkin.rb +1 -1
- data/lib/rouge/lexers/isbl.rb +97 -0
- data/lib/rouge/lexers/isbl/builtins.rb +17 -0
- data/lib/rouge/lexers/json.rb +3 -0
- data/lib/rouge/lexers/json_doc.rb +1 -0
- data/lib/rouge/lexers/kotlin.rb +4 -0
- data/lib/rouge/lexers/lasso.rb +4 -9
- data/lib/rouge/lexers/lasso/keywords.rb +14 -0
- data/lib/rouge/lexers/lua.rb +1 -1
- data/lib/rouge/lexers/markdown.rb +1 -1
- data/lib/rouge/lexers/mathematica.rb +1 -1
- data/lib/rouge/lexers/matlab.rb +3 -4
- data/lib/rouge/lexers/matlab/builtins.rb +11 -0
- data/lib/rouge/lexers/pascal.rb +1 -1
- data/lib/rouge/lexers/php.rb +47 -32
- data/lib/rouge/lexers/python.rb +66 -57
- data/lib/rouge/lexers/racket.rb +24 -1
- data/lib/rouge/lexers/rego.rb +45 -0
- data/lib/rouge/lexers/ruby.rb +11 -1
- data/lib/rouge/lexers/solidity.rb +185 -0
- data/lib/rouge/lexers/sqf.rb +1 -1
- data/lib/rouge/lexers/terraform.rb +15 -0
- data/lib/rouge/lexers/typescript.rb +4 -0
- data/lib/rouge/lexers/viml.rb +1 -1
- data/lib/rouge/lexers/vue.rb +4 -1
- data/lib/rouge/lexers/yang.rb +147 -0
- data/lib/rouge/version.rb +1 -1
- metadata +20 -5
- data/lib/rouge/lexers/apache/keywords.yml +0 -764
- data/lib/rouge/lexers/lasso/keywords.yml +0 -446
- data/lib/rouge/lexers/matlab/builtins.yml +0 -3515
data/lib/rouge/lexers/cpp.rb
CHANGED
@@ -22,10 +22,10 @@ module Rouge
|
|
22
22
|
|
23
23
|
def self.keywords
|
24
24
|
@keywords ||= super + Set.new(%w(
|
25
|
-
asm auto catch const_cast delete dynamic_cast explicit export
|
26
|
-
|
27
|
-
reinterpret_cast restrict size_of static_cast
|
28
|
-
|
25
|
+
asm auto catch const_cast delete dynamic_cast explicit export friend
|
26
|
+
mutable namespace new operator private protected public
|
27
|
+
reinterpret_cast restrict size_of static_cast this throw throws
|
28
|
+
typeid typename using virtual final override
|
29
29
|
|
30
30
|
alignas alignof constexpr decltype noexcept static_assert
|
31
31
|
thread_local try
|
@@ -57,7 +57,8 @@ module Rouge
|
|
57
57
|
dq = /\d('?\d)*/
|
58
58
|
|
59
59
|
prepend :statements do
|
60
|
-
rule %r/class\b/, Keyword, :classname
|
60
|
+
rule %r/(class|struct)\b/, Keyword, :classname
|
61
|
+
rule %r/template\b/, Keyword, :template
|
61
62
|
rule %r/\d+(\.\d+)?(?:h|(?:min)|s|(?:ms)|(?:us)|(?:ns))/, Num::Other
|
62
63
|
rule %r((#{dq}[.]#{dq}?|[.]#{dq})(e[+-]?#{dq}[lu]*)?)i, Num::Float
|
63
64
|
rule %r(#{dq}e[+-]?#{dq}[lu]*)i, Num::Float
|
@@ -77,6 +78,12 @@ module Rouge
|
|
77
78
|
rule %r/[.]{3}/, Operator
|
78
79
|
mixin :whitespace
|
79
80
|
end
|
81
|
+
|
82
|
+
state :template do
|
83
|
+
rule %r/>/, Punctuation, :pop!
|
84
|
+
rule %r/typename\b/, Keyword, :classname
|
85
|
+
mixin :root
|
86
|
+
end
|
80
87
|
end
|
81
88
|
end
|
82
89
|
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# -*- coding: utf-8 -*- #
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Rouge
|
5
|
+
module Lexers
|
6
|
+
class Cypher < RegexLexer
|
7
|
+
tag 'cypher'
|
8
|
+
aliases 'cypher'
|
9
|
+
filenames '*.cypher'
|
10
|
+
mimetypes 'application/x-cypher-query'
|
11
|
+
|
12
|
+
title "Cypher"
|
13
|
+
desc 'The Cypher query language (neo4j.com/docs/cypher-manual)'
|
14
|
+
|
15
|
+
def self.functions
|
16
|
+
@functions ||= Set.new %w(
|
17
|
+
ABS ACOS ALLSHORTESTPATHS ASIN ATAN ATAN2 AVG CEIL COALESCE COLLECT
|
18
|
+
COS COT COUNT DATE DEGREES E ENDNODE EXP EXTRACT FILTER FLOOR
|
19
|
+
HAVERSIN HEAD ID KEYS LABELS LAST LEFT LENGTH LOG LOG10 LOWER LTRIM
|
20
|
+
MAX MIN NODE NODES PERCENTILECONT PERCENTILEDISC PI RADIANS RAND
|
21
|
+
RANGE REDUCE REL RELATIONSHIP RELATIONSHIPS REPLACE REVERSE RIGHT
|
22
|
+
ROUND RTRIM SHORTESTPATH SIGN SIN SIZE SPLIT SQRT STARTNODE STDEV
|
23
|
+
STDEVP STR SUBSTRING SUM TAIL TAN TIMESTAMP TOFLOAT TOINT TOINTEGER
|
24
|
+
TOSTRING TRIM TYPE UPPER
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.predicates
|
29
|
+
@predicates ||= Set.new %w(
|
30
|
+
ALL AND ANY CONTAINS EXISTS HAS IN NONE NOT OR SINGLE XOR
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.keywords
|
35
|
+
@keywords ||= Set.new %w(
|
36
|
+
AS ASC ASCENDING ASSERT BY CASE COMMIT CONSTRAINT CREATE CSV CYPHER
|
37
|
+
DELETE DESC DESCENDING DETACH DISTINCT DROP ELSE END ENDS EXPLAIN
|
38
|
+
FALSE FIELDTERMINATOR FOREACH FROM HEADERS IN INDEX IS JOIN LIMIT
|
39
|
+
LOAD MATCH MERGE NULL ON OPTIONAL ORDER PERIODIC PROFILE REMOVE
|
40
|
+
RETURN SCAN SET SKIP START STARTS THEN TRUE UNION UNIQUE UNWIND USING
|
41
|
+
WHEN WHERE WITH CALL YIELD
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
state :root do
|
46
|
+
rule %r/[\s]+/, Text
|
47
|
+
rule %r(//.*?$), Comment::Single
|
48
|
+
|
49
|
+
rule %r([*+\-<>=&|~%^]), Operator
|
50
|
+
rule %r/[{}),;\[\]]/, Str::Symbol
|
51
|
+
|
52
|
+
# literal number
|
53
|
+
rule %r/(\w+)(:)(\s*)(-?[._\d]+)/ do
|
54
|
+
groups Name::Label, Str::Delimiter, Text::Whitespace, Num
|
55
|
+
end
|
56
|
+
|
57
|
+
# function-like
|
58
|
+
# - "name("
|
59
|
+
# - "name ("
|
60
|
+
# - "name ("
|
61
|
+
rule %r/(\w+)(\s*)(\()/ do |m|
|
62
|
+
name = m[1].upcase
|
63
|
+
if self.class.functions.include? name
|
64
|
+
groups Name::Function, Text::Whitespace, Str::Symbol
|
65
|
+
elsif self.class.keywords.include? name
|
66
|
+
groups Keyword, Text::Whitespace, Str::Symbol
|
67
|
+
else
|
68
|
+
groups Name, Text::Whitespace, Str::Symbol
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
rule %r/:\w+/, Name::Class
|
73
|
+
|
74
|
+
# number range
|
75
|
+
rule %r/(-?\d+)(\.\.)(-?\d+)/ do
|
76
|
+
groups Num, Operator, Num
|
77
|
+
end
|
78
|
+
|
79
|
+
# numbers
|
80
|
+
rule %r/(\d+\.\d*|\d*\.\d+)(e[+-]?\d+)?/i, Num::Float
|
81
|
+
rule %r/\d+e[+-]?\d+/i, Num::Float
|
82
|
+
rule %r/0[0-7]+/, Num::Oct
|
83
|
+
rule %r/0x[a-f0-9]+/i, Num::Hex
|
84
|
+
rule %r/\d+/, Num::Integer
|
85
|
+
|
86
|
+
rule %r([.\w]+:), Name::Property
|
87
|
+
|
88
|
+
# remaining "("
|
89
|
+
rule %r/\(/, Str::Symbol
|
90
|
+
|
91
|
+
rule %r/[.\w$]+/ do |m|
|
92
|
+
match = m[0].upcase
|
93
|
+
if self.class.predicates.include? match
|
94
|
+
token Operator::Word
|
95
|
+
elsif self.class.keywords.include? match
|
96
|
+
token Keyword
|
97
|
+
else
|
98
|
+
token Name
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
rule %r/"(\\\\|\\"|[^"])*"/, Str::Double
|
103
|
+
rule %r/'(\\\\|\\'|[^'])*'/, Str::Single
|
104
|
+
rule %r/`(\\\\|\\`|[^`])*`/, Str::Backtick
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
# -*- coding: utf-8 -*- #
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Rouge
|
5
|
+
module Lexers
|
6
|
+
class Datastudio < RegexLexer
|
7
|
+
tag 'datastudio'
|
8
|
+
filenames '*.job'
|
9
|
+
mimetypes 'text/x-datastudio'
|
10
|
+
|
11
|
+
title "Datastudio"
|
12
|
+
desc 'Datastudio scripting language'
|
13
|
+
|
14
|
+
id = /@?[_a-z]\w*/i
|
15
|
+
|
16
|
+
def self.sql_keywords
|
17
|
+
@sql_keywords ||= %w(
|
18
|
+
ABORT ABS ABSOLUTE ACCESS ADA ADD ADMIN AFTER AGGREGATE ALIAS
|
19
|
+
ALL ALLOCATE ALTER ANALYSE ANALYZE AND ANY ARE AS ASC ASENSITIVE
|
20
|
+
ASSERTION ASSIGNMENT ASYMMETRIC AT ATOMIC AUTHORIZATION
|
21
|
+
AVG BACKWARD BEFORE BEGIN BETWEEN BITVAR BIT_LENGTH BOTH
|
22
|
+
BREADTH BY C CACHE CALL CALLED CARDINALITY CASCADE CASCADED
|
23
|
+
CASE CAST CATALOG CATALOG_NAME CHAIN CHARACTERISTICS
|
24
|
+
CHARACTER_LENGTH CHARACTER_SET_CATALOG CHARACTER_SET_NAME
|
25
|
+
CHARACTER_SET_SCHEMA CHAR_LENGTH CHECK CHECKED CHECKPOINT
|
26
|
+
CLASS CLASS_ORIGIN CLOB CLOSE CLUSTER COALSECE COBOL COLLATE
|
27
|
+
COLLATION COLLATION_CATALOG COLLATION_NAME COLLATION_SCHEMA
|
28
|
+
COLUMN COLUMN_NAME COMMAND_FUNCTION COMMAND_FUNCTION_CODE
|
29
|
+
COMMENT COMMIT COMMITTED COMPLETION CONDITION_NUMBER
|
30
|
+
CONNECT CONNECTION CONNECTION_NAME CONSTRAINT CONSTRAINTS
|
31
|
+
CONSTRAINT_CATALOG CONSTRAINT_NAME CONSTRAINT_SCHEMA
|
32
|
+
CONSTRUCTOR CONTAINS CONTINUE CONVERSION CONVERT COPY
|
33
|
+
CORRESPONTING COUNT CREATE CREATEDB CREATEUSER CROSS CUBE
|
34
|
+
CURRENT CURRENT_DATE CURRENT_PATH CURRENT_ROLE CURRENT_TIME
|
35
|
+
CURRENT_TIMESTAMP CURRENT_USER CURSOR CURSOR_NAME CYCLE DATA
|
36
|
+
DATABASE DATETIME_INTERVAL_CODE DATETIME_INTERVAL_PRECISION
|
37
|
+
DAY DEALLOCATE DECLARE DEFAULT DEFAULTS DEFERRABLE DEFERRED
|
38
|
+
DEFINED DEFINER DELETE DELIMITER DELIMITERS DEREF DESC DESCRIBE
|
39
|
+
DESCRIPTOR DESTROY DESTRUCTOR DETERMINISTIC DIAGNOSTICS
|
40
|
+
DICTIONARY DISCONNECT DISPATCH DISTINCT DO DOMAIN DROP
|
41
|
+
DYNAMIC DYNAMIC_FUNCTION DYNAMIC_FUNCTION_CODE EACH ELSE
|
42
|
+
ENCODING ENCRYPTED END END-EXEC EQUALS ESCAPE EVERY EXCEPT
|
43
|
+
ESCEPTION EXCLUDING EXCLUSIVE EXEC EXECUTE EXISTING EXISTS
|
44
|
+
EXPLAIN EXTERNAL EXTRACT FALSE FETCH FINAL FIRST FOR FORCE
|
45
|
+
FOREIGN FORTRAN FORWARD FOUND FREE FREEZE FROM FULL FUNCTION
|
46
|
+
G GENERAL GENERATED GET GLOBAL GO GOTO GRANT GRANTED GROUP
|
47
|
+
GROUPING HANDLER HAVING HIERARCHY HOLD HOST IDENTITY IGNORE
|
48
|
+
ILIKE IMMEDIATE IMMUTABLE IMPLEMENTATION IMPLICIT IN INCLUDING
|
49
|
+
INCREMENT INDEX INDITCATOR INFIX INHERITS INITIALIZE INITIALLY
|
50
|
+
INNER INOUT INPUT INSENSITIVE INSERT INSTANTIABLE INSTEAD
|
51
|
+
INTERSECT INTO INVOKER IS ISNULL ISOLATION ITERATE JOIN KEY
|
52
|
+
KEY_MEMBER KEY_TYPE LANCOMPILER LANGUAGE LARGE LAST LATERAL
|
53
|
+
LEADING LEFT LENGTH LESS LEVEL LIKE LIMIT LISTEN LOAD LOCAL
|
54
|
+
LOCALTIME LOCALTIMESTAMP LOCATION LOCATOR LOCK LOWER MAP MATCH
|
55
|
+
MAX MAXVALUE MESSAGE_LENGTH MESSAGE_OCTET_LENGTH MESSAGE_TEXT
|
56
|
+
METHOD MIN MINUTE MINVALUE MOD MODE MODIFIES MODIFY MONTH
|
57
|
+
MORE MOVE MUMPS NAMES NATURAL NCLOB NEW NEXT
|
58
|
+
NO NOCREATEDB NOCREATEUSER NONE NOT NOTHING NOTIFY NOTNULL
|
59
|
+
NULL NULLABLE NULLIF OBJECT OCTET_LENGTH OF OFF OFFSET OIDS
|
60
|
+
OLD ON ONLY OPEN OPERATION OPERATOR OPTION OPTIONS OR ORDER
|
61
|
+
ORDINALITY OUT OUTER OUTPUT OVERLAPS OVERLAY OVERRIDING
|
62
|
+
OWNER PAD PARAMETER PARAMETERS PARAMETER_MODE PARAMATER_NAME
|
63
|
+
PARAMATER_ORDINAL_POSITION PARAMETER_SPECIFIC_CATALOG
|
64
|
+
PARAMETER_SPECIFIC_NAME PARAMATER_SPECIFIC_SCHEMA PARTIAL PASCAL
|
65
|
+
PENDANT PLACING PLI POSITION POSTFIX PREFIX PREORDER
|
66
|
+
PREPARE PRESERVE PRIMARY PRIOR PRIVILEGES PROCEDURAL PROCEDURE
|
67
|
+
PUBLIC READ READS RECHECK RECURSIVE REF REFERENCES REFERENCING
|
68
|
+
REINDEX RELATIVE RENAME REPEATABLE REPLACE RESET RESTART
|
69
|
+
RESTRICT RESULT RETURN RETURNED_LENGTH RETURNED_OCTET_LENGTH
|
70
|
+
RETURNED_SQLSTATE RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP
|
71
|
+
ROUTINE ROUTINE_CATALOG ROUTINE_NAME ROUTINE_SCHEMA ROW ROWS
|
72
|
+
ROW_COUNT RULE SAVE_POINT SCALE SCHEMA SCHEMA_NAME SCOPE SCROLL
|
73
|
+
SEARCH SECOND SECURITY SELECT SELF SENSITIVE SERIALIZABLE
|
74
|
+
SERVER_NAME SESSION SESSION_USER SET SETOF SETS SHARE SHOW
|
75
|
+
SIMILAR SIMPLE SIZE SOME SOURCE SPACE SPECIFIC SPECIFICTYPE
|
76
|
+
SPECIFIC_NAME SQL SQLCODE SQLERROR SQLEXCEPTION SQLSTATE
|
77
|
+
SQLWARNINIG STABLE START STATE STATEMENT STATIC STATISTICS
|
78
|
+
STDIN STDOUT STORAGE STRICT STRUCTURE STYPE SUBCLASS_ORIGIN
|
79
|
+
SUBLIST SUBSTRING SUM SYMMETRIC SYSID SYSTEM SYSTEM_USER
|
80
|
+
TABLE TABLE_NAME TEMP TEMPLATE TEMPORARY TERMINATE THAN THEN
|
81
|
+
TIMEZONE_HOUR TIMEZONE_MINUTE TO TOAST TRAILING
|
82
|
+
TRANSATION TRANSACTIONS_COMMITTED TRANSACTIONS_ROLLED_BACK
|
83
|
+
TRANSATION_ACTIVE TRANSFORM TRANSFORMS TRANSLATE TRANSLATION
|
84
|
+
TREAT TRIGGER TRIGGER_CATALOG TRIGGER_NAME TRIGGER_SCHEMA TRIM
|
85
|
+
TRUE TRUNCATE TRUSTED TYPE UNCOMMITTED UNDER UNENCRYPTED UNION
|
86
|
+
UNIQUE UNKNOWN UNLISTEN UNNAMED UNNEST UNTIL UPDATE UPPER
|
87
|
+
USAGE USER USER_DEFINED_TYPE_CATALOG USER_DEFINED_TYPE_NAME
|
88
|
+
USER_DEFINED_TYPE_SCHEMA USING VACUUM VALID VALIDATOR VALUES
|
89
|
+
VARIABLE VERBOSE VERSION VIEW VOLATILE WHEN WHENEVER WHERE
|
90
|
+
WITH WITHOUT WORK WRITE ZONE
|
91
|
+
)
|
92
|
+
end
|
93
|
+
|
94
|
+
state :whitespace do
|
95
|
+
rule %r/\s+/m, Text
|
96
|
+
rule %r(//.*?$), Comment::Single
|
97
|
+
rule %r(/[*].*?[*]/)m, Comment::Multiline
|
98
|
+
end
|
99
|
+
|
100
|
+
state :string do
|
101
|
+
rule %r/%(\\.|.)+?%/, Str::Escape
|
102
|
+
rule %r/\\"/, Str::Double
|
103
|
+
rule %r/"/, Str::Double, :pop!
|
104
|
+
rule %r/./m, Str::Double
|
105
|
+
end
|
106
|
+
|
107
|
+
state :string_s do
|
108
|
+
rule %r/%(\\.|.)+?%/, Str::Escape
|
109
|
+
rule %r/\\'/, Str::Single
|
110
|
+
rule %r/'/, Str::Single, :pop!
|
111
|
+
rule %r/./m, Str::Single
|
112
|
+
end
|
113
|
+
|
114
|
+
state :root do
|
115
|
+
mixin :whitespace
|
116
|
+
|
117
|
+
rule %r/^:#{id}/, Name::Label
|
118
|
+
rule %r/@#{id}(\.#{id})?/m, Name::Entity
|
119
|
+
rule %r/%(\\.|.)+?%/, Name::Variable
|
120
|
+
rule %r/[~!%^&*()+=|\[\]{}:;,.<>\/?-]/, Punctuation
|
121
|
+
rule %r/"/, Str::Double, :string
|
122
|
+
rule %r/'/, Str::Single, :string_s
|
123
|
+
rule %r/\d(\.\d*)?/i, Num
|
124
|
+
rule %r/#{id}(?=\s*[(])/, Name::Function
|
125
|
+
rule id do |m|
|
126
|
+
name = m[0].upcase
|
127
|
+
|
128
|
+
if self.class.sql_keywords.include? name
|
129
|
+
token Keyword
|
130
|
+
else
|
131
|
+
token Name
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
data/lib/rouge/lexers/fsharp.rb
CHANGED
@@ -0,0 +1,340 @@
|
|
1
|
+
# -*- coding: utf-8 -*- #
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# C minus minus (Cmm) is a pun on the name C++. It's an intermediate language
|
5
|
+
# of the Glasgow Haskell Compiler (GHC) that is very similar to C, but with
|
6
|
+
# many features missing and some special constructs.
|
7
|
+
#
|
8
|
+
# Cmm is a dialect of C--. The goal of this lexer is to use what GHC produces
|
9
|
+
# and parses (Cmm); C-- itself is not supported.
|
10
|
+
#
|
11
|
+
# https://gitlab.haskell.org/ghc/ghc/wikis/commentary/compiler/cmm-syntax
|
12
|
+
#
|
13
|
+
module Rouge
|
14
|
+
module Lexers
|
15
|
+
class GHCCmm < RegexLexer
|
16
|
+
title "GHC Cmm (C--)"
|
17
|
+
desc "GHC Cmm is the intermediate representation of the GHC Haskell compiler"
|
18
|
+
tag 'ghc-cmm'
|
19
|
+
filenames '*.cmm', '*.dump-cmm', '*.dump-cmm-*'
|
20
|
+
aliases 'cmm'
|
21
|
+
|
22
|
+
ws = %r(\s|//.*?\n|/[*](?:[^*]|(?:[*][^/]))*[*]+/)mx
|
23
|
+
|
24
|
+
# Make sure that this is not a preprocessor macro, e.g. `#if` or `#define`.
|
25
|
+
id = %r((?!#[a-zA-Z])[\w#\$%_']+)
|
26
|
+
|
27
|
+
complex_id = %r(
|
28
|
+
(?:[\w#$%_']|\(\)|\(,\)|\[\]|[0-9])*
|
29
|
+
(?:[\w#$%_']+)
|
30
|
+
)mx
|
31
|
+
|
32
|
+
state :root do
|
33
|
+
rule %r/\s+/m, Text
|
34
|
+
|
35
|
+
# sections markers
|
36
|
+
rule %r/^=====.*=====$/, Generic::Heading
|
37
|
+
|
38
|
+
# timestamps
|
39
|
+
rule %r/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+ UTC$/, Comment::Single
|
40
|
+
|
41
|
+
mixin :detect_section
|
42
|
+
mixin :preprocessor_macros
|
43
|
+
|
44
|
+
mixin :info_tbls
|
45
|
+
mixin :comments
|
46
|
+
mixin :literals
|
47
|
+
mixin :keywords
|
48
|
+
mixin :types
|
49
|
+
mixin :infos
|
50
|
+
mixin :names
|
51
|
+
mixin :operators
|
52
|
+
|
53
|
+
# escaped newline
|
54
|
+
rule %r/\\\n/, Text
|
55
|
+
|
56
|
+
# rest is Text
|
57
|
+
rule %r/./, Text
|
58
|
+
end
|
59
|
+
|
60
|
+
state :detect_section do
|
61
|
+
rule %r/(section)(\s+)/ do |m|
|
62
|
+
token Keyword, m[1]
|
63
|
+
token Text, m[2]
|
64
|
+
push :section
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
state :section do
|
69
|
+
rule %r/"(data|cstring|text|rodata|relrodata|bss)"/, Name::Builtin
|
70
|
+
|
71
|
+
rule %r/{/, Punctuation, :pop!
|
72
|
+
|
73
|
+
mixin :names
|
74
|
+
mixin :operators
|
75
|
+
mixin :keywords
|
76
|
+
|
77
|
+
rule %r/\s+/, Text
|
78
|
+
end
|
79
|
+
|
80
|
+
state :preprocessor_macros do
|
81
|
+
rule %r/#(include|endif|else|if)/, Comment::Preproc
|
82
|
+
|
83
|
+
rule %r{
|
84
|
+
(\#define)
|
85
|
+
(#{ws}*)
|
86
|
+
(#{id})
|
87
|
+
}mx do |m|
|
88
|
+
token Comment::Preproc, m[1]
|
89
|
+
recurse m[2]
|
90
|
+
token Name::Label, m[3]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
state :info_tbls do
|
95
|
+
rule %r/({ )(info_tbls)(:)/ do |m|
|
96
|
+
token Punctuation, m[1]
|
97
|
+
token Name::Entity, m[2]
|
98
|
+
token Punctuation, m[3]
|
99
|
+
|
100
|
+
push :info_tbls_body
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
state :info_tbls_body do
|
105
|
+
rule %r/}/, Punctuation, :pop!
|
106
|
+
rule %r/{/, Punctuation, :info_tbls_body
|
107
|
+
|
108
|
+
rule %r/(?=label:)/ do
|
109
|
+
push :label
|
110
|
+
end
|
111
|
+
|
112
|
+
rule %r{(\()(#{complex_id})(,)}mx do |m|
|
113
|
+
token Punctuation, m[1]
|
114
|
+
token Name::Label, m[2]
|
115
|
+
token Punctuation, m[3]
|
116
|
+
end
|
117
|
+
|
118
|
+
mixin :literals
|
119
|
+
mixin :infos
|
120
|
+
mixin :keywords
|
121
|
+
mixin :operators
|
122
|
+
|
123
|
+
rule %r/#{id}/, Text
|
124
|
+
rule %r/\s+/, Text
|
125
|
+
end
|
126
|
+
|
127
|
+
state :label do
|
128
|
+
mixin :infos
|
129
|
+
mixin :names
|
130
|
+
mixin :keywords
|
131
|
+
mixin :operators
|
132
|
+
|
133
|
+
rule %r/[^\S\n]+/, Text # Tab, space, etc. but not newline!
|
134
|
+
rule %r/\n/, Text, :pop!
|
135
|
+
end
|
136
|
+
|
137
|
+
state :comments do
|
138
|
+
rule %r/\/{2}.*/, Comment::Single
|
139
|
+
rule %r/\(likely.*?\)/, Comment
|
140
|
+
rule %r/\/\*.*?\*\//m, Comment::Multiline
|
141
|
+
end
|
142
|
+
|
143
|
+
state :literals do
|
144
|
+
rule %r/-?[0-9]+\.[0-9]+/, Literal::Number::Float
|
145
|
+
rule %r/-?[0-9]+/, Literal::Number::Integer
|
146
|
+
rule %r/"/, Literal::String::Delimiter, :literal_string
|
147
|
+
end
|
148
|
+
|
149
|
+
state :literal_string do
|
150
|
+
# quotes
|
151
|
+
rule %r/\\./, Literal::String::Escape
|
152
|
+
rule %r/%./, Literal::String::Symbol
|
153
|
+
rule %r/"/, Literal::String::Delimiter, :pop!
|
154
|
+
rule %r/./, Literal::String
|
155
|
+
end
|
156
|
+
|
157
|
+
state :operators do
|
158
|
+
rule %r/\.\./, Operator
|
159
|
+
rule %r/[+\-*\/<>=!&|~]/, Operator
|
160
|
+
rule %r/[\[\].{}:;,()]/, Punctuation
|
161
|
+
end
|
162
|
+
|
163
|
+
state :keywords do
|
164
|
+
rule %r/(const)(\s+)/ do |m|
|
165
|
+
token Keyword::Constant, m[1]
|
166
|
+
token Text, m[2]
|
167
|
+
end
|
168
|
+
|
169
|
+
rule %r/"/, Literal::String::Double
|
170
|
+
|
171
|
+
rule %r/(switch)([^{]*)({)/ do |m|
|
172
|
+
token Keyword, m[1]
|
173
|
+
recurse m[2]
|
174
|
+
token Punctuation, m[3]
|
175
|
+
end
|
176
|
+
|
177
|
+
rule %r/(arg|result)(#{ws}+)(hints)(:)/ do |m|
|
178
|
+
token Name::Property, m[1]
|
179
|
+
recurse m[2]
|
180
|
+
token Name::Property, m[3]
|
181
|
+
token Punctuation, m[4]
|
182
|
+
end
|
183
|
+
|
184
|
+
rule %r/(returns)(#{ws}*)(to)/ do |m|
|
185
|
+
token Keyword, m[1]
|
186
|
+
recurse m[2]
|
187
|
+
token Keyword, m[3]
|
188
|
+
end
|
189
|
+
|
190
|
+
rule %r/(never)(#{ws}*)(returns)/ do |m|
|
191
|
+
token Keyword, m[1]
|
192
|
+
recurse m[2]
|
193
|
+
token Keyword, m[3]
|
194
|
+
end
|
195
|
+
|
196
|
+
rule %r{(return)(#{ws}*)(\()} do |m|
|
197
|
+
token Keyword, m[1]
|
198
|
+
recurse m[2]
|
199
|
+
token Punctuation, m[3]
|
200
|
+
end
|
201
|
+
|
202
|
+
rule %r{(if|else|goto|call|offset|import|jump|ccall|foreign|prim|case|unwind|export|reserve|push)(#{ws})} do |m|
|
203
|
+
token Keyword, m[1]
|
204
|
+
recurse m[2]
|
205
|
+
end
|
206
|
+
|
207
|
+
rule %r{(default)(#{ws}*)(:)} do |m|
|
208
|
+
token Keyword, m[1]
|
209
|
+
recurse m[2]
|
210
|
+
token Punctuation, m[3]
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
state :types do
|
215
|
+
# Memory access: `type[42]`
|
216
|
+
# Note: Only a token for type is produced.
|
217
|
+
rule %r/(#{id})(?=\[[^\]])/ do |m|
|
218
|
+
token Keyword::Type, m[1]
|
219
|
+
end
|
220
|
+
|
221
|
+
# Array type: `type[]`
|
222
|
+
rule %r/(#{id}\[\])/ do |m|
|
223
|
+
token Keyword::Type, m[1]
|
224
|
+
end
|
225
|
+
|
226
|
+
# Capture macro substitutions before lexing typed declarations
|
227
|
+
# I.e. there is no type in `PREPROCESSOR_MACRO_VARIABLE someFun()`
|
228
|
+
rule %r{
|
229
|
+
(^#{id})
|
230
|
+
(#{ws}+)
|
231
|
+
(#{id})
|
232
|
+
(#{ws}*)
|
233
|
+
(\()
|
234
|
+
}mx do |m|
|
235
|
+
token Name::Label, m[1]
|
236
|
+
recurse m[2]
|
237
|
+
token Name::Function, m[3]
|
238
|
+
recurse m[4]
|
239
|
+
token Punctuation, m[5]
|
240
|
+
end
|
241
|
+
|
242
|
+
# Type in variable or parameter declaration:
|
243
|
+
# `type /* optional whitespace */ var_name /* optional whitespace */;`
|
244
|
+
# `type /* optional whitespace */ var_name /* optional whitespace */, var_name2`
|
245
|
+
# `(type /* optional whitespace */ var_name /* optional whitespace */)`
|
246
|
+
# Note: Only the token for type is produced here.
|
247
|
+
rule %r{
|
248
|
+
(^#{id})
|
249
|
+
(#{ws}+)
|
250
|
+
(#{id})
|
251
|
+
}mx do |m|
|
252
|
+
token Keyword::Type, m[1]
|
253
|
+
recurse m[2]
|
254
|
+
token Name::Label, m[3]
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
state :infos do
|
259
|
+
rule %r/(args|res|upd|label|rep|srt|arity|fun_type|arg_space|updfr_space)(:)/ do |m|
|
260
|
+
token Name::Property, m[1]
|
261
|
+
token Punctuation, m[2]
|
262
|
+
end
|
263
|
+
|
264
|
+
rule %r/(stack_info)(:)/ do |m|
|
265
|
+
token Name::Entity, m[1]
|
266
|
+
token Punctuation, m[2]
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
state :names do
|
271
|
+
rule %r/(::)(#{ws}*)([A-Z]\w+)/ do |m|
|
272
|
+
token Operator, m[1]
|
273
|
+
recurse m[2]
|
274
|
+
token Keyword::Type, m[3]
|
275
|
+
end
|
276
|
+
|
277
|
+
rule %r/<(#{id})>/, Name::Builtin
|
278
|
+
|
279
|
+
rule %r/(Sp|SpLim|Hp|HpLim|HpAlloc|BaseReg|CurrentNursery|CurrentTSO|R\d{1,2}|gcptr)(?!#{id})/, Name::Variable::Global
|
280
|
+
rule %r/([A-Z]#{id})(\.)/ do |m|
|
281
|
+
token Name::Namespace, m[1]
|
282
|
+
token Punctuation, m[2]
|
283
|
+
push :namespace_name
|
284
|
+
end
|
285
|
+
|
286
|
+
# Inline function calls:
|
287
|
+
# ```
|
288
|
+
# arg1 `lt` arg2
|
289
|
+
# ```
|
290
|
+
rule %r/(`)(#{id})(`)/ do |m|
|
291
|
+
token Punctuation, m[1]
|
292
|
+
token Name::Function, m[2]
|
293
|
+
token Punctuation, m[3]
|
294
|
+
end
|
295
|
+
|
296
|
+
# Function: `name /* optional whitespace */ (`
|
297
|
+
# Function (arguments via explicit stack handling): `name /* optional whitespace */ {`
|
298
|
+
rule %r{(?=
|
299
|
+
#{complex_id}
|
300
|
+
#{ws}*
|
301
|
+
[\{\(]
|
302
|
+
)}mx do
|
303
|
+
push :function
|
304
|
+
end
|
305
|
+
|
306
|
+
rule %r/CLOSURE/, Keyword::Type
|
307
|
+
rule %r/#{complex_id}/, Name::Label
|
308
|
+
end
|
309
|
+
|
310
|
+
state :namespace_name do
|
311
|
+
rule %r/([A-Z]#{id})(\.)/ do |m|
|
312
|
+
token Name::Namespace, m[1]
|
313
|
+
token Punctuation, m[2]
|
314
|
+
end
|
315
|
+
|
316
|
+
rule %r{(#{complex_id})(#{ws}*)([\{\(])}mx do |m|
|
317
|
+
token Name::Function, m[1]
|
318
|
+
recurse m[2]
|
319
|
+
token Punctuation, m[3]
|
320
|
+
pop!
|
321
|
+
end
|
322
|
+
|
323
|
+
rule %r/#{complex_id}/, Name::Label, :pop!
|
324
|
+
|
325
|
+
rule %r/(?=.)/m do
|
326
|
+
pop!
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
state :function do
|
331
|
+
rule %r/INFO_TABLE_FUN|INFO_TABLE_CONSTR|INFO_TABLE_SELECTOR|INFO_TABLE_RET|INFO_TABLE/, Name::Builtin
|
332
|
+
rule %r/%#{id}/, Name::Builtin
|
333
|
+
rule %r/#{complex_id}/, Name::Function
|
334
|
+
rule %r/\s+/, Text
|
335
|
+
rule %r/[({]/, Punctuation, :pop!
|
336
|
+
mixin :comments
|
337
|
+
end
|
338
|
+
end
|
339
|
+
end
|
340
|
+
end
|