rouge 4.1.3 → 4.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +10 -7
  3. data/LICENSE +2 -1
  4. data/lib/rouge/cli.rb +4 -5
  5. data/lib/rouge/demos/bicep +10 -0
  6. data/lib/rouge/demos/cobol +103 -0
  7. data/lib/rouge/demos/codeowners +6 -0
  8. data/lib/rouge/demos/gjs +23 -0
  9. data/lib/rouge/demos/gts +36 -0
  10. data/lib/rouge/demos/iecst +21 -0
  11. data/lib/rouge/demos/json5 +12 -0
  12. data/lib/rouge/demos/mojo +10 -0
  13. data/lib/rouge/demos/p4 +99 -0
  14. data/lib/rouge/demos/svelte +29 -0
  15. data/lib/rouge/formatters/html_legacy.rb +0 -3
  16. data/lib/rouge/guessers/disambiguation.rb +24 -3
  17. data/lib/rouge/lexer.rb +8 -6
  18. data/lib/rouge/lexers/ada.rb +5 -5
  19. data/lib/rouge/lexers/bicep.rb +111 -0
  20. data/lib/rouge/lexers/bpf.rb +10 -10
  21. data/lib/rouge/lexers/brainfuck.rb +1 -0
  22. data/lib/rouge/lexers/clean.rb +4 -4
  23. data/lib/rouge/lexers/cobol.rb +137 -0
  24. data/lib/rouge/lexers/codeowners.rb +30 -0
  25. data/lib/rouge/lexers/cpp.rb +5 -4
  26. data/lib/rouge/lexers/crystal.rb +17 -17
  27. data/lib/rouge/lexers/csharp.rb +37 -34
  28. data/lib/rouge/lexers/css.rb +192 -150
  29. data/lib/rouge/lexers/dart.rb +1 -1
  30. data/lib/rouge/lexers/docker.rb +2 -2
  31. data/lib/rouge/lexers/ecl.rb +2 -2
  32. data/lib/rouge/lexers/eiffel.rb +1 -1
  33. data/lib/rouge/lexers/elixir.rb +5 -1
  34. data/lib/rouge/lexers/gdscript.rb +4 -4
  35. data/lib/rouge/lexers/ghc_cmm.rb +3 -3
  36. data/lib/rouge/lexers/gjs.rb +39 -0
  37. data/lib/rouge/lexers/go.rb +7 -5
  38. data/lib/rouge/lexers/groovy.rb +6 -4
  39. data/lib/rouge/lexers/gts.rb +39 -0
  40. data/lib/rouge/lexers/hcl.rb +1 -0
  41. data/lib/rouge/lexers/html.rb +1 -1
  42. data/lib/rouge/lexers/iecst.rb +92 -0
  43. data/lib/rouge/lexers/ini.rb +7 -5
  44. data/lib/rouge/lexers/java.rb +1 -1
  45. data/lib/rouge/lexers/javascript.rb +4 -4
  46. data/lib/rouge/lexers/json5.rb +74 -0
  47. data/lib/rouge/lexers/julia.rb +3 -2
  48. data/lib/rouge/lexers/kotlin.rb +1 -1
  49. data/lib/rouge/lexers/lua.rb +24 -3
  50. data/lib/rouge/lexers/make.rb +5 -1
  51. data/lib/rouge/lexers/markdown.rb +2 -1
  52. data/lib/rouge/lexers/mathematica.rb +1 -1
  53. data/lib/rouge/lexers/meson.rb +0 -1
  54. data/lib/rouge/lexers/mojo.rb +35 -0
  55. data/lib/rouge/lexers/nasm.rb +5 -4
  56. data/lib/rouge/lexers/nginx.rb +1 -0
  57. data/lib/rouge/lexers/objective_c/common.rb +0 -2
  58. data/lib/rouge/lexers/objective_c.rb +1 -1
  59. data/lib/rouge/lexers/ocl.rb +2 -2
  60. data/lib/rouge/lexers/openedge.rb +0 -2
  61. data/lib/rouge/lexers/p4.rb +81 -0
  62. data/lib/rouge/lexers/php/keywords.rb +86 -136
  63. data/lib/rouge/lexers/php.rb +42 -2
  64. data/lib/rouge/lexers/plsql.rb +5 -5
  65. data/lib/rouge/lexers/python.rb +59 -32
  66. data/lib/rouge/lexers/robot_framework.rb +1 -1
  67. data/lib/rouge/lexers/ruby.rb +21 -21
  68. data/lib/rouge/lexers/sass/common.rb +1 -1
  69. data/lib/rouge/lexers/scala.rb +5 -2
  70. data/lib/rouge/lexers/sql.rb +1 -1
  71. data/lib/rouge/lexers/svelte.rb +91 -0
  72. data/lib/rouge/lexers/syzlang.rb +0 -1
  73. data/lib/rouge/lexers/tcl.rb +7 -2
  74. data/lib/rouge/lexers/terraform.rb +4 -3
  75. data/lib/rouge/lexers/toml.rb +56 -45
  76. data/lib/rouge/lexers/ttcn3.rb +0 -2
  77. data/lib/rouge/lexers/typescript/common.rb +9 -0
  78. data/lib/rouge/lexers/xojo.rb +6 -6
  79. data/lib/rouge/lexers/yang.rb +1 -1
  80. data/lib/rouge/regex_lexer.rb +13 -0
  81. data/lib/rouge/tex_theme_renderer.rb +1 -1
  82. data/lib/rouge/themes/base16.rb +23 -18
  83. data/lib/rouge/themes/bw.rb +1 -0
  84. data/lib/rouge/themes/colorful.rb +1 -0
  85. data/lib/rouge/themes/github.rb +1 -0
  86. data/lib/rouge/themes/gruvbox.rb +4 -1
  87. data/lib/rouge/themes/igor_pro.rb +3 -0
  88. data/lib/rouge/themes/magritte.rb +1 -0
  89. data/lib/rouge/themes/molokai.rb +2 -1
  90. data/lib/rouge/themes/monokai.rb +2 -1
  91. data/lib/rouge/themes/monokai_sublime.rb +4 -3
  92. data/lib/rouge/themes/pastie.rb +1 -0
  93. data/lib/rouge/themes/thankful_eyes.rb +1 -0
  94. data/lib/rouge/themes/tulip.rb +1 -0
  95. data/lib/rouge/token.rb +2 -1
  96. data/lib/rouge/version.rb +1 -1
  97. metadata +23 -6
@@ -0,0 +1,111 @@
1
+ module Rouge
2
+ module Lexers
3
+ class Bicep < Rouge::RegexLexer
4
+ tag 'bicep'
5
+ filenames '*.bicep'
6
+
7
+ title "Bicep"
8
+ desc 'Bicep is a domain-specific language (DSL) that uses declarative syntax to deploy Azure resources.'
9
+
10
+ def self.keywords
11
+ @keywords ||= Set.new %w(
12
+ as assert existing extends extension false for from func if import in metadata module
13
+ none null output param provider resource targetScope test true type using var void with
14
+ )
15
+ end
16
+
17
+ def self.datatypes
18
+ @datatypes ||= Set.new %w(array bool int object string)
19
+ end
20
+
21
+ def self.functions
22
+ @functions ||= Set.new %w(
23
+ array base64 base64ToJson base64ToString bool cidrHost cidrSubnet concat contains dataUri
24
+ dataUriToString dateTimeAdd dateTimeFromEpoch dateTimeToEpoch deployer deployment empty endsWith
25
+ environment extensionResourceId fail filter first flatten format getSecret groupBy guid indexOf int
26
+ intersection items join json last lastIndexOf length list* listAccountSas listKeys listSecrets loadFileAsBase64
27
+ loadJsonContent loadTextContent loadYamlContent managementGroup managementGroupResourceId map mapValue max min
28
+ newGuid objectKeys padLeft parseCidr pickZones range readEnvironmentVariable reduce reference replace resourceGroup
29
+ resourceId shallowMerge skip sort split startsWith string subscription subscriptionResourceId substring take tenant
30
+ tenantResourceId toLogicalZone toLower toObject toPhysicalZone toUpper trim union uniqueString uri uriComponent
31
+ uriComponentToString utcNow
32
+ )
33
+ end
34
+
35
+ operators = %w(+ - * / % < <= > >= == != =~ !~ && || ! ?? ... .?)
36
+
37
+ punctuations = %w(( ) { } [ ] , : ; = .)
38
+
39
+ state :root do
40
+ mixin :comments
41
+
42
+ # Match strings
43
+ rule %r/'/, Str::Single, :string
44
+
45
+ # Match numbers
46
+ rule %r/\b\d+\b/, Num
47
+
48
+ # Rules for sets of reserved keywords
49
+ rule %r/\b\w+\b/ do |m|
50
+ if self.class.keywords.include? m[0]
51
+ token Keyword
52
+ elsif self.class.datatypes.include? m[0]
53
+ token Keyword::Type
54
+ elsif self.class.functions.include? m[0]
55
+ token Name::Function
56
+ else
57
+ token Name
58
+ end
59
+ end
60
+
61
+ # Match operators
62
+ rule %r/#{operators.map { |o| Regexp.escape(o) }.join('|')}/, Operator
63
+
64
+ # Enter a state when encountering an opening curly bracket
65
+ rule %r/{/, Punctuation::Indicator, :block
66
+
67
+ # Match punctuation
68
+ rule %r/#{punctuations.map { |p| Regexp.escape(p) }.join('|')}/, Punctuation
69
+
70
+ # Match identifiers
71
+ rule %r/[a-zA-Z_]\w*/, Name
72
+
73
+ # Match decorators
74
+ rule %r/@[a-zA-Z_]\w*/, Name::Decorator
75
+
76
+ # Ignore whitespace
77
+ rule %r/\s+/, Text
78
+ end
79
+
80
+ state :comments do
81
+ rule %r(//[^\n\r]+), Comment::Single
82
+ rule %r(/\*.*?\*/)m, Comment::Multiline
83
+ end
84
+
85
+ state :string do
86
+ rule %r/[^'$}]+/, Str::Single
87
+ rule %r/\$(?!\{)/, Str::Single
88
+ rule %r/\$[\{]/, Str::Interpol, :interp
89
+ rule %r/\'/, Str::Single, :pop!
90
+ rule %r/\$+/, Str::Single
91
+ end
92
+
93
+ state :interp do
94
+ rule %r/\}/, Str::Interpol, :pop!
95
+ mixin :root
96
+ end
97
+
98
+ # State for matching code blocks between curly brackets
99
+ state :block do
100
+ # Match property names
101
+ rule %r/\b([a-zA-Z_]\w*)\b(?=\s*:)/, Name::Property
102
+
103
+ # Match closing curly brackets
104
+ rule %r/}/, Punctuation::Indicator, :pop!
105
+
106
+ # Include the root state for nested tokens
107
+ mixin :root
108
+ end
109
+ end
110
+ end
111
+ end
@@ -9,11 +9,11 @@ module Rouge
9
9
  tag 'bpf'
10
10
 
11
11
  TYPE_KEYWORDS = %w(
12
- u8 u16 u32 u64 ll
12
+ u8 u16 u32 u64 s8 s16 s32 s64 ll
13
13
  ).join('|')
14
14
 
15
15
  MISC_KEYWORDS = %w(
16
- be16 be32 be64 exit lock map
16
+ be16 be32 be64 le16 le32 le64 bswap16 bswap32 bswap64 exit lock map
17
17
  ).join('|')
18
18
 
19
19
  state :root do
@@ -32,21 +32,21 @@ module Rouge
32
32
  rule %r/(call)(\s+)(\d+)/i do
33
33
  groups Keyword, Text::Whitespace, Literal::Number::Integer
34
34
  end
35
- rule %r/(call)(\s+)(\w+)(#)(\d+)/i do
35
+ rule %r/(call)(\s+)(\w+)(?:(#)(\d+))?/i do
36
36
  groups Keyword, Text::Whitespace, Name::Builtin, Punctuation, Literal::Number::Integer
37
37
  end
38
38
 
39
39
  # Unconditional jumps
40
- rule %r/(goto)(\s*)(\+\d+)?(\s*)(<?\w+>?)/i do
41
- groups Keyword, Text::Whitespace, Literal::Number::Integer, Text::Whitespace, Name::Label
40
+ rule %r/(gotol?)(\s*)([-+]0x\w+)?([-+]\d+)?(\s*)(<?\w+>?)/i do
41
+ groups Keyword, Text::Whitespace, Literal::Number::Hex, Literal::Number::Integer, Text::Whitespace, Name::Label
42
42
  end
43
43
 
44
44
  # Conditional jumps
45
- rule %r/(if)(\s+)([rw]\d+)(\s*)([s!=<>]+)(\s*)(0x\h+|[-]?\d+)(\s*)(goto)(\s*)(\+\d+)?(\s*)(<?\w+>?)/i do
46
- groups Keyword, Text::Whitespace, Name, Text::Whitespace, Operator, Text::Whitespace, Literal::Number, Text::Whitespace, Keyword, Text::Whitespace, Literal::Number::Integer, Text::Whitespace, Name::Label
45
+ rule %r/(if)(\s+)([rw]\d+)(\s*)([s!=<>]+)(\s*)(0x\h+|[-]?\d+)(\s*)(gotol?)(\s*)([-+]0x\w+)?([-+]\d+)?(\s*)(<?\w+>?)/i do
46
+ groups Keyword, Text::Whitespace, Name, Text::Whitespace, Operator, Text::Whitespace, Literal::Number, Text::Whitespace, Keyword, Text::Whitespace, Literal::Number::Hex, Literal::Number::Integer, Text::Whitespace, Name::Label
47
47
  end
48
- rule %r/(if)(\s+)([rw]\d+)(\s*)([s!=<>]+)(\s*)([rw]\d+)(\s*)(goto)(\s*)(\+\d+)?(\s*)(<?\w+>?)/i do
49
- groups Keyword, Text::Whitespace, Name, Text::Whitespace, Operator, Text::Whitespace, Name, Text::Whitespace, Keyword, Text::Whitespace, Literal::Number::Integer, Text::Whitespace, Name::Label
48
+ rule %r/(if)(\s+)([rw]\d+)(\s*)([s!=<>]+)(\s*)([rw]\d+)(\s*)(gotol?)(\s*)([-+]0x\w+)?([-+]\d+)?(\s*)(<?\w+>?)/i do
49
+ groups Keyword, Text::Whitespace, Name, Text::Whitespace, Operator, Text::Whitespace, Name, Text::Whitespace, Keyword, Text::Whitespace, Literal::Number::Hex, Literal::Number::Integer, Text::Whitespace, Name::Label
50
50
  end
51
51
 
52
52
  # Dereferences
@@ -70,7 +70,7 @@ module Rouge
70
70
  rule %r/#{MISC_KEYWORDS}/i, Keyword
71
71
 
72
72
  # Literals and global objects (maps) refered by name
73
- rule %r/(0x\h+|[-]?\d+)(\s*)(ll)?/i do
73
+ rule %r/([-]?0x\h+|[-]?\d+)(\s*)(ll)?/i do
74
74
  groups Literal::Number, Text::Whitespace, Keyword::Type
75
75
  end
76
76
  rule %r/(\w+)(\s*)(ll)/i do
@@ -9,6 +9,7 @@ module Rouge
9
9
  mimetypes 'text/x-brainfuck'
10
10
 
11
11
  title "Brainfuck"
12
+ aliases "bf"
12
13
  desc "The Brainfuck programming language"
13
14
 
14
15
  start { push :bol }
@@ -79,7 +79,7 @@ module Rouge
79
79
 
80
80
  rule %r/code(\s+inline)?\s*{/, Comment::Preproc, :abc
81
81
 
82
- rule %r/_*[a-z][\w_`]*/ do |m|
82
+ rule %r/_*[a-z][\w`]*/ do |m|
83
83
  if self.class.keywords.include?(m[0])
84
84
  token Keyword
85
85
  else
@@ -87,7 +87,7 @@ module Rouge
87
87
  end
88
88
  end
89
89
 
90
- rule %r/_*[A-Z][\w_`]*/ do |m|
90
+ rule %r/_*[A-Z][\w`]*/ do |m|
91
91
  if m[0]=='True' || m[0]=='False'
92
92
  token Keyword::Constant
93
93
  else
@@ -95,7 +95,7 @@ module Rouge
95
95
  end
96
96
  end
97
97
 
98
- rule %r/[^\w_\s`]/, Punctuation
98
+ rule %r/[^\w\s`]/, Punctuation
99
99
  rule %r/_\b/, Punctuation
100
100
  end
101
101
 
@@ -136,7 +136,7 @@ module Rouge
136
136
 
137
137
  rule %r/}/, Comment::Preproc, :pop!
138
138
  rule %r/\.\w*/, Keyword, :abc_rest_of_line
139
- rule %r/[\w_]+/, Name::Builtin, :abc_rest_of_line
139
+ rule %r/[\w]+/, Name::Builtin, :abc_rest_of_line
140
140
  end
141
141
 
142
142
  state :abc_rest_of_line do
@@ -0,0 +1,137 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class COBOL < RegexLexer
7
+ title 'COBOL'
8
+ desc 'COBOL (Common Business-Oriented Language) programming language'
9
+ tag 'cobol'
10
+ filenames '*.cob', '*.cbl', '*.cpy', '*.cpb'
11
+ mimetypes 'text/x-cobol'
12
+
13
+ identifier = /\p{Alpha}[\p{Alnum}-]*/
14
+
15
+ def self.divisions
16
+ @divisions ||= %w(
17
+ IDENTIFICATION ENVIRONMENT DATA PROCEDURE DIVISION
18
+ )
19
+ end
20
+
21
+ def self.sections
22
+ @sections ||= %w(
23
+ CONFIGURATION INPUT-OUTPUT FILE WORKING-STORAGE LOCAL-STORAGE LINKAGE SECTION
24
+ )
25
+ end
26
+
27
+ # List of COBOL keywords
28
+ # sourced from https://www.ibm.com/docs/en/cobol-zos/6.4?topic=appendixes-reserved-words
29
+ def self.keywords
30
+ @keywords ||= Set.new(%w(
31
+ ACCEPT ACCESS ACTIVE-CLASS ADD ADDRESS ADVANCING AFTER ALIGNED ALL ALLOCATE ALPHABET ALPHABETIC ALPHABETIC-LOWER
32
+ ALPHABETIC-UPPER ALPHANUMERIC ALPHANUMERIC-EDITED ALSO ALTER ALTERNATE AND ANYCASE ANY APPLY ARE AREA AREAS
33
+ ASCENDING ASSIGN AT AUTHOR B-AND B-NOT B-OR B-XOR BASED BASIS BEFORE BEGINNING BINARY BINARY-CHAR BINARY-DOUBLE
34
+ BINARY-LONG BINARY-SHORT BIT BLANK BLOCK BOOLEAN BOTTOM BY BYTE-LENGTH CALL CANCEL CBL CD CF CH CHARACTER
35
+ CHARACTERS CLASS CLASS-ID CLOCK-UNITS CLOSE COBOL CODE CODE-SET COL COLLATING COLS COLUMN COLUMNS COM-REG COMMA
36
+ COMMON COMMUNICATION COMP-1 COMP-2 COMP-3 COMP-4 COMP-5 COMP COMPUTATIONAL-1 COMPUTATIONAL-2
37
+ COMPUTATIONAL-3 COMPUTATIONAL-4 COMPUTATIONAL-5 COMPUTATIONAL COMPUTE CONDITION CONSTANT CONTAINS CONTENT
38
+ CONTINUE CONTROL CONTROLS CONVERTING COPY CORR CORRESPONDING COUNT CRT CURRENCY CURSOR DATA-POINTER DATE
39
+ DATE-COMPILED DATE-WRITTEN DAY DAY-OF-WEEK DBCS DE DEBUG-CONTENTS DEBUG-ITEM DEBUG-LINE DEBUG-NAME DEBUG-SUB-1
40
+ DEBUG-SUB-2 DEBUG-SUB-3 DEBUGGING DECIMAL-POINT DECLARATIVES DEFAULT DELETE DELIMITED DELIMITER DEPENDING
41
+ DESCENDING DESTINATION DETAIL DISABLE DISPLAY-1 DISPLAY DIVIDE DOWN DUPLICATES DYNAMIC EC EGCS EGI
42
+ EJECT ELSE EMI ENABLE END-ACCEPT END-ADD END-CALL END-COMPUTE END-DELETE END-DISPLAY END-DIVIDE END-EVALUATE
43
+ END-EXEC END-IF END-INVOKE END-JSON END-MULTIPLY END-OF-PAGE END-PERFORM END-READ END-RECEIVE END-RETURN
44
+ END-REWRITE END-SEARCH END-START END-STRING END-SUBTRACT END-UNSTRING END-WRITE END-XML ENDING END ENTER ENTRY
45
+ EO EOP EQUAL ERROR ESI EVALUATE EVERY EXCEPTION EXCEPTION-OBJECT EXEC EXECUTE EXIT EXTEND EXTERNAL
46
+ FACTORY FALSE FD FILE-CONTROL FILLER FINAL FIRST FLOAT-EXTENDED FLOAT-LONG FLOAT-SHORT FOOTING FOR FORMAT
47
+ FREE FROM FUNCTION FUNCTION-ID FUNCTION-POINTER GENERATE GET GIVING GLOBAL GO GOBACK GREATER GROUP GROUP-USAGE
48
+ HEADING HIGH-VALUE HIGH-VALUES I-O-CONTROL I-O ID IF IN INDEX INDEXED INDICATE INHERITS INITIAL
49
+ INITIALIZE INITIATE INPUT INSERT INSPECT INSTALLATION INTERFACE INTERFACE-ID INTO INVALID INVOKE
50
+ IS JAVA JNIENVPTR JSON JSON-CODE JSON-STATUS JUST JUSTIFIED KANJI KEY LABEL LAST LEADING LEFT LENGTH LESS LIMIT
51
+ LIMITS LINAGE-COUNTER LINAGE LINE-COUNTER LINES LINE LOCALE LOCK LOW-VALUE LOW-VALUES
52
+ MEMORY MERGE MESSAGE METHOD METHOD-ID MINUS MODE MODULES MORE-LABELS MOVE MULTIPLE MULTIPLY NATIONAL
53
+ NATIONAL-EDITED NATIVE NEGATIVE NESTED NEXT NO NOT NULL NULLS NUMBER NUMERIC NUMERIC-EDITED OBJECT
54
+ OBJECT-COMPUTER OBJECT-REFERENCE OCCURS OF OFF OMITTED ON OPEN OPTIONAL OPTIONS OR ORDER ORGANIZATION
55
+ OTHER OUTPUT OVERFLOW OVERRIDE PACKED-DECIMAL PADDING PAGE PAGE-COUNTER PASSWORD PERFORM PF PH PIC PICTURE
56
+ PLUS POINTER- POINTER-31 POINTER-32 POINTER-64 POINTER POSITION POSITIVE PRESENT PRINTING
57
+ PROCEDURE-POINTER PROCEDURES PROCEED PROCESSING PROGRAM-ID PROGRAM-POINTER PROGRAM PROPERTY PROTOTYPE
58
+ PURGE QUEUE QUOTE QUOTES RAISE RAISING RANDOM RD READ READY RECEIVE RECORD RECORDING RECORDS RECURSIVE REDEFINES
59
+ REEL REFERENCE REFERENCES RELATIVE RELEASE RELOAD REMAINDER REMOVAL RENAMES REPLACE REPLACING REPORT REPORTING
60
+ REPORTS REPOSITORY RERUN RESERVE RESET RESUME RETRY RETURN RETURN-CODE RETURNING REVERSED REWIND REWRITE RF RH
61
+ RIGHT ROUNDED RUN SAME SCREEN SD SEARCH SECTION SECURITY SEGMENT SEGMENT-LIMIT SELECT SELF SEND SENTENCE
62
+ SEPARATE SEQUENCE SEQUENTIAL SERVICE SET SHARING SHIFT-IN SHIFT-OUT SIGN SIZE SKIP1 SKIP2 SKIP3
63
+ SORT-CONTROL SORT-CORE-SIZE SORT-FILE-SIZE SORT-MERGE SORT-MESSAGE SORT-MODE-SIZE SORT-RETURN SORT
64
+ SOURCE-COMPUTER SOURCES SOURCE SPACE SPACES SPECIAL-NAMES SQL SQLIMS STANDARD-1 STANDARD-2 STANDARD START STATUS STOP
65
+ STRING SUB-QUEUE-1 SUB-QUEUE-2 SUB-QUEUE-3 SUBTRACT SUM SUPER SUPPRESS SYMBOLIC SYNC SYNCHRONIZED SYSTEM-DEFAULT
66
+ TABLE TALLY TALLYING TAPE TERMINAL TERMINATE TEST TEXT THAN THEN THROUGH THRU TIME TIMES TITLE TO TOP TRACE
67
+ TRAILING TRUE TYPE TYPEDEF UNIT UNIVERSAL UNLOCK UNSTRING UNTIL UP UPON USAGE USE USER-DEFAULT USING UTF-8
68
+ VAL-STATUS VALID VALIDATE VALIDATE-STATUS VALUE VALUES VARYING VOLATILE WHEN WHEN-COMPILED WITH WORDS
69
+ WRITE WRITE-ONLY XML-CODE XML-EVENT XML-INFORMATION XML-NAMESPACE XML-NAMESPACE-PREFIX
70
+ XML-NNAMESPACE XML-NNAMESPACE-PREFIX XML-NTEXT XML-SCHEMA XML-TEXT XML ZERO ZEROES ZEROS
71
+ ))
72
+ end
73
+
74
+ state :root do
75
+ # First detect the comments
76
+ rule %r/^( \*).*|^(^Debug \*).*/, Comment::Special
77
+
78
+ # Strings
79
+ rule %r/"/, Str::Double, :string_double
80
+ rule %r/'/, Str::Single, :string_single
81
+
82
+ # Keywords and divisions
83
+ rule %r/(?<![\w-])#{identifier}(?![\w-])/i do |m|
84
+ if self.class.divisions.include?(m[0].upcase)
85
+ token Keyword::Declaration
86
+ elsif self.class.sections.include?(m[0].upcase)
87
+ token Keyword::Namespace
88
+ elsif self.class.keywords.include?(m[0].upcase)
89
+ token Keyword
90
+ else
91
+ token Name
92
+ end
93
+ end
94
+
95
+ # Numbers
96
+ rule %r/[-+]?\b\d+(\.\d+)?\b/, Num
97
+
98
+ # Punctuation
99
+ rule %r/[.,;:()]/, Punctuation
100
+
101
+ # Comments
102
+ rule %r/\*>.*/, Comment::Single
103
+
104
+ # Operators
105
+ rule %r/[+\-*\/><=]/, Operator
106
+
107
+ # Whitespace remaining
108
+ rule %r/\s/, Text::Whitespace
109
+
110
+ # Anything else remaining
111
+ rule %r/.+/, Text
112
+ end
113
+
114
+ # TODO double check string escaping in COBOL
115
+ # TODO Fix that a string opened by " can't be closed by '
116
+ # TODO Fix that strings can't be multi-line
117
+
118
+ # Handle strings where " opens a string and must be closed by "
119
+ state :string_double do
120
+ # Ensure strings can't span multiple lines
121
+ rule %r/[^"\\\n]+/, Str
122
+ rule %r/\\./, Str::Escape
123
+ rule %r/"/, Str::Double, :pop!
124
+ rule %r/\n/, Error # Flag an error if a string goes to the next line
125
+ end
126
+
127
+ # Handle strings where ' opens a string and must be closed by '
128
+ state :string_single do
129
+ # Ensure strings can't span multiple lines
130
+ rule %r/[^'\\\n]+/, Str
131
+ rule %r/\\./, Str::Escape
132
+ rule %r/'/, Str::Single, :pop!
133
+ rule %r/\n/, Error # Flag an error if a string goes to the next line
134
+ end
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,30 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class Codeowners < RegexLexer
7
+ title 'CODEOWNERS'
8
+ desc 'Code Owners syntax (https://docs.gitlab.com/ee/user/project/codeowners/reference.html)'
9
+ tag 'codeowners'
10
+ filenames 'CODEOWNERS'
11
+
12
+ state :root do
13
+ rule %r/[ \t\r\n]+/, Text::Whitespace
14
+ rule %r/^\s*#.*$/, Comment::Single
15
+
16
+ rule %r(
17
+ (\^?\[(?!\d+\])[^\]]+\])
18
+ (\[\d+\])?
19
+ )x do
20
+ groups Name::Namespace, Literal::Number
21
+ end
22
+
23
+ rule %r/\S*@\S+/, Name::Function
24
+
25
+ rule %r/[\p{Word}\.\/\-\*]+/, Name
26
+ rule %r/.*\\[\#\s]/, Name
27
+ end
28
+ end
29
+ end
30
+ end
@@ -27,7 +27,7 @@ module Rouge
27
27
  delete dynamic_cast explicit export friend
28
28
  mutable namespace new operator private protected public
29
29
  reinterpret_cast requires restrict size_of static_cast this throw throws
30
- typeid typename using virtual final override
30
+ typeid typename using virtual final override import module
31
31
 
32
32
  alignas alignof decltype noexcept static_assert
33
33
  thread_local try
@@ -62,9 +62,10 @@ module Rouge
62
62
  rule %r/(class|struct)\b/, Keyword, :classname
63
63
  rule %r/template\b/, Keyword, :template
64
64
  rule %r/#{dq}(\.#{dq})?(?:y|d|h|(?:min)|s|(?:ms)|(?:us)|(?:ns)|i|(?:if)|(?:il))\b/, Num::Other
65
- rule %r((#{dq}[.]#{dq}?|[.]#{dq})(e[+-]?#{dq}[lu]*)?)i, Num::Float
66
- rule %r(#{dq}e[+-]?#{dq}[lu]*)i, Num::Float
67
- rule %r/0x\h('?\h)*[lu]*/i, Num::Hex
65
+ rule %r((#{dq}[.]#{dq}?|[.]#{dq})([ep][+-]?#{dq})?[luf]*)i, Num::Float
66
+ rule %r(#{dq}[ep][+-]?#{dq}[luf]*)i, Num::Float
67
+ rule %r/0x\h('?\h)*([ep][+-]?#{dq})?[lu]*/i, Num::Hex
68
+ rule %r/0x\h('?\h)*[.]\h+([ep][+-]?#{dq})[luf]*/i, Num::Hex
68
69
  rule %r/0b[01]+('[01]+)*/, Num::Bin
69
70
  rule %r/0[0-7]('?[0-7])*[lu]*/i, Num::Oct
70
71
  rule %r/#{dq}[lu]*/i, Num::Integer
@@ -21,7 +21,7 @@ module Rouge
21
21
  rule %r(
22
22
  : # initial :
23
23
  @{0,2} # optional ivar, for :@foo and :@@foo
24
- [a-z_]\w*[!?]? # the symbol
24
+ [\p{Ll}_]\p{Word}*[!?]? # the symbol
25
25
  )xi, Str::Symbol
26
26
 
27
27
  # special symbols
@@ -35,7 +35,7 @@ module Rouge
35
35
  # %-sigiled strings
36
36
  # %(abc), %[abc], %<abc>, %.abc., %r.abc., etc
37
37
  delimiter_map = { '{' => '}', '[' => ']', '(' => ')', '<' => '>' }
38
- rule %r/%([rqswQWxiI])?([^\w\s}])/ do |m|
38
+ rule %r/%([rqswQWxiI])?([^\p{Word}\s}])/ do |m|
39
39
  open = Regexp.escape(m[2])
40
40
  close = Regexp.escape(delimiter_map[m[2]] || m[2])
41
41
  interp = /[rQWxI]/ === m[1]
@@ -77,7 +77,7 @@ module Rouge
77
77
 
78
78
  state :strings do
79
79
  mixin :symbols
80
- rule %r/\b[a-z_]\w*?[?!]?:\s+/, Str::Symbol, :expr_start
80
+ rule %r/\b[\p{Ll}_]\p{Word}*?[?!]?:\s+/, Str::Symbol, :expr_start
81
81
  rule %r/"/, Str::Double, :simple_string
82
82
  rule %r/(?<!\.)`/, Str::Backtick, :simple_backtick
83
83
  rule %r/(')(\\u[a-fA-F0-9]{4}|\\u\{[a-fA-F0-9]{1,6}\}|\\[abefnrtv])?(\\\\|\\'|[^'])*(')/ do
@@ -166,9 +166,9 @@ module Rouge
166
166
  rule %r/@\[([^\]]+)\]/, Name::Decorator
167
167
 
168
168
  # names
169
- rule %r/@@[a-z_]\w*/i, Name::Variable::Class
170
- rule %r/@[a-z_]\w*/i, Name::Variable::Instance
171
- rule %r/\$\w+/, Name::Variable::Global
169
+ rule %r/@@[\p{Ll}_]\p{Word}*/i, Name::Variable::Class
170
+ rule %r/@[\p{Ll}_]\p{Word}*/i, Name::Variable::Instance
171
+ rule %r/\$\p{Word}+/, Name::Variable::Global
172
172
  rule %r(\$[!@&`'+~=/\\,;.<>_*\$?:"]), Name::Variable::Global
173
173
  rule %r/\$-[0adFiIlpvw]/, Name::Variable::Global
174
174
  rule %r/::/, Operator
@@ -181,7 +181,7 @@ module Rouge
181
181
  rule %r(
182
182
  (module)
183
183
  (\s+)
184
- ([a-zA-Z_][a-zA-Z0-9_]*(::[a-zA-Z_][a-zA-Z0-9_]*)*)
184
+ ([\p{L}_][\p{L}0-9_]*(::[\p{L}_][\p{L}0-9_]*)*)
185
185
  )x do
186
186
  groups Keyword, Text, Name::Namespace
187
187
  end
@@ -207,14 +207,14 @@ module Rouge
207
207
  # Otherwise, they will be parsed as :method_call
208
208
  rule %r/\.{2,3}/, Operator, :expr_start
209
209
 
210
- rule %r/[A-Z][a-zA-Z0-9_]*/, Name::Constant, :method_call
211
- rule %r/(\.|::)(\s*)([a-z_]\w*[!?]?|[*%&^`~+-\/\[<>=])/ do
210
+ rule %r/[\p{Lu}][\p{L}0-9_]*/, Name::Constant, :method_call
211
+ rule %r/(\.|::)(\s*)([\p{Ll}_]\p{Word}*[!?]?|[*%&^`~+-\/\[<>=])/ do
212
212
  groups Punctuation, Text, Name::Function
213
213
  push :method_call
214
214
  end
215
215
 
216
- rule %r/[a-zA-Z_]\w*[?!]/, Name, :expr_start
217
- rule %r/[a-zA-Z_]\w*/, Name, :method_call
216
+ rule %r/[\p{L}_]\p{Word}*[?!]/, Name, :expr_start
217
+ rule %r/[\p{L}_]\p{Word}*/, Name, :method_call
218
218
  rule %r/\*\*|\/\/|>=|<=|<=>|<<?|>>?|=~|={3}|!~|&&?|\|\||\./,
219
219
  Operator, :expr_start
220
220
  rule %r/{%|%}/, Punctuation
@@ -225,7 +225,7 @@ module Rouge
225
225
  end
226
226
 
227
227
  state :has_heredocs do
228
- rule %r/(?<!\w)(<<[-~]?)(["`']?)([a-zA-Z_]\w*)(\2)/ do |m|
228
+ rule %r/(?<!\p{Word})(<<[-~]?)(["`']?)([\p{L}_]\p{Word}*)(\2)/ do |m|
229
229
  token Operator, m[1]
230
230
  token Name::Constant, "#{m[2]}#{m[3]}#{m[4]}"
231
231
  @heredoc_queue << [['<<-', '<<~'].include?(m[1]), m[3]]
@@ -282,9 +282,9 @@ module Rouge
282
282
  rule %r/\s+/, Text
283
283
  rule %r/\(/, Punctuation, :defexpr
284
284
  rule %r(
285
- (?:([a-zA-Z_]\w*)(\.))?
285
+ (?:([\p{L}_]\p{Word}*)(\.))?
286
286
  (
287
- [a-zA-Z_]\w*[!?]? |
287
+ [\p{L}_]\p{Word}*[!?]? |
288
288
  \*\*? | [-+]@? | [/%&\|^`~] | \[\]=? |
289
289
  <<? | >>? | <=>? | >= | ===?
290
290
  )
@@ -311,7 +311,7 @@ module Rouge
311
311
  goto :expr_start
312
312
  end
313
313
 
314
- rule %r/[A-Z_]\w*/, Name::Class, :pop!
314
+ rule %r/[\p{Lu}_]\p{Word}*/, Name::Class, :pop!
315
315
 
316
316
  rule(//) { pop! }
317
317
  end
@@ -343,7 +343,7 @@ module Rouge
343
343
 
344
344
  state :string_intp do
345
345
  rule %r/[#][{]/, Str::Interpol, :in_interp
346
- rule %r/#(@@?|\$)[a-z_]\w*/i, Str::Interpol
346
+ rule %r/#(@@?|\$)[\p{Ll}_]\p{Word}*/i, Str::Interpol
347
347
  end
348
348
 
349
349
  state :string_intp_escaped do
@@ -399,7 +399,7 @@ module Rouge
399
399
  rule %r(
400
400
  [?](\\[MC]-)* # modifiers
401
401
  (\\([\\abefnrstv\#"']|x[a-fA-F0-9]{1,2}|[0-7]{1,3})|\S)
402
- (?!\w)
402
+ (?!\p{Word})
403
403
  )x, Str::Char, :pop!
404
404
 
405
405
  # special case for using a single space. Ruby demands that
@@ -12,35 +12,40 @@ module Rouge
12
12
  title "C#"
13
13
  desc 'a multi-paradigm language targeting .NET'
14
14
 
15
- # TODO: support more of unicode
16
- id = /@?[_a-z]\w*/i
17
-
18
- #Reserved Identifiers
19
- #Contextual Keywords
20
- #LINQ Query Expressions
21
- keywords = %w(
22
- abstract as base break case catch checked const continue
23
- default delegate do else enum event explicit extern false
24
- finally fixed for foreach goto if implicit in interface
25
- internal is lock new null operator out override params private
26
- protected public readonly ref return sealed sizeof stackalloc
27
- static switch this throw true try typeof unchecked unsafe
28
- virtual void volatile while
29
- add alias async await get global partial remove set value where
30
- yield nameof notnull
31
- ascending by descending equals from group in init into join let
32
- on orderby select unmanaged when and not or with
33
- )
34
-
35
- keywords_type = %w(
36
- bool byte char decimal double dynamic float int long nint nuint
37
- object sbyte short string uint ulong ushort var
38
- )
39
-
40
- cpp_keywords = %w(
41
- if endif else elif define undef line error warning region
42
- endregion pragma nullable
43
- )
15
+ id = /@?[_\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}]*/
16
+
17
+ # Reserved Identifiers
18
+ # Contextual Keywords
19
+ # LINQ Query Expressions
20
+ def self.keywords
21
+ @keywords ||= %w(
22
+ abstract add alias and as ascending async await base
23
+ break by case catch checked const continue default delegate
24
+ descending do else enum equals event explicit extern false
25
+ finally fixed for foreach from get global goto group
26
+ if implicit in init interface internal into is join
27
+ let lock nameof new notnull null on operator orderby
28
+ out override params partial private protected public readonly
29
+ ref remove return sealed set sizeof stackalloc static
30
+ switch this throw true try typeof unchecked unsafe
31
+ unmanaged value virtual void volatile when where while
32
+ with yield
33
+ )
34
+ end
35
+
36
+ def self.keywords_type
37
+ @keywords_type ||= %w(
38
+ bool byte char decimal double dynamic float int long nint nuint
39
+ object sbyte short string uint ulong ushort var
40
+ )
41
+ end
42
+
43
+ def self.cpp_keywords
44
+ @cpp_keywords ||= %w(
45
+ if endif else elif define undef line error warning region
46
+ endregion pragma nullable
47
+ )
48
+ end
44
49
 
45
50
  state :whitespace do
46
51
  rule %r/\s+/m, Text
@@ -91,10 +96,9 @@ module Rouge
91
96
  )ix, Num
92
97
  rule %r/\b(?:class|record|struct|interface)\b/, Keyword, :class
93
98
  rule %r/\b(?:namespace|using)\b/, Keyword, :namespace
94
- rule %r/^#[ \t]*(#{cpp_keywords.join('|')})\b.*?\n/,
95
- Comment::Preproc
96
- rule %r/\b(#{keywords.join('|')})\b/, Keyword
97
- rule %r/\b(#{keywords_type.join('|')})\b/, Keyword::Type
99
+ rule %r/^#[ \t]*(#{CSharp.cpp_keywords.join('|')})\b.*?\n/, Comment::Preproc
100
+ rule %r/\b(#{CSharp.keywords.join('|')})\b/, Keyword
101
+ rule %r/\b(#{CSharp.keywords_type.join('|')})\b/, Keyword::Type
98
102
  rule %r/#{id}(?=\s*[(])/, Name::Function
99
103
  rule id, Name
100
104
  end
@@ -109,7 +113,6 @@ module Rouge
109
113
  rule %r/(?=[(])/, Text, :pop!
110
114
  rule %r/(#{id}|[.])+/, Name::Namespace, :pop!
111
115
  end
112
-
113
116
  end
114
117
  end
115
118
  end