rouge 4.3.0 → 4.5.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de3a38233be791cfb87fbcee4e092afc1731ed4c2ac0bd9f4e8eb8d889a262c4
4
- data.tar.gz: 81d1cf226f514155b861b1f127e55ffdf7cf9d40e2a8c8fa1ee5cd211052aeb0
3
+ metadata.gz: 4c49b8e02cddb54e0f39aecaad73d5b52d4fb5ff4161b32a80344f5df1a61afa
4
+ data.tar.gz: e9c17a30cd177dab2413546b32c83fbe4b436a0c055d8aa7dbaa48e7b877f579
5
5
  SHA512:
6
- metadata.gz: 3ba279624b6990706218bced834a373cd4d5a15a487c862b07cc7042a924b429cad7518bea407f8ca85bda087395f1fa15abb231f0dd9ff0faa3b2b5e7cb108a
7
- data.tar.gz: 93021b4af8761ddc54e22038b6926b7522f67c70c1ba0e7ebdb76ccb21375760f23efe4ebc9c4000bf3bba73499476fb9832596ac3f8eeca5f6f6f626e15069d
6
+ metadata.gz: e0ff902fc5912f3dc69b9526cc5eea412ac417d88ea73fcd65f864280195e8fc8b0d74f5810d661ff3233e8efeecc96ff9fb02235407d78c43d268b1f3907e03
7
+ data.tar.gz: 1a74aa3d80aff64dc748125728b7016fb03886c6be323d76f24ecd1658b04154df5e49d04eeb7d6feafab0ccd416690e402cf1d931e2f621cfa8637d3b9f9c5f
@@ -0,0 +1,103 @@
1
+ *-----------------------
2
+ * This file was sourced from https://github.com/openmainframeproject/cobol-programming-course
3
+ * Credits:
4
+ * The course materials were made available through a joint collaboration between IBM, its clients, and
5
+ * American River College and proposed as a new project by IBM.
6
+ *-----------------------
7
+ * Copyright Contributors to the COBOL Programming Course
8
+ * SPDX-License-Identifier: CC-BY-4.0
9
+ *-----------------------
10
+ IDENTIFICATION DIVISION.
11
+ *-----------------------
12
+ PROGRAM-ID. CBL0001
13
+ AUTHOR. Otto B. Fun.
14
+ *--------------------
15
+ ENVIRONMENT DIVISION.
16
+ *--------------------
17
+ INPUT-OUTPUT SECTION.
18
+ FILE-CONTROL.
19
+ SELECT PRINT-LINE ASSIGN TO PRTLINE.
20
+ SELECT ACCT-REC ASSIGN TO ACCTREC.
21
+ *SELECT clause creates an internal file name
22
+ *ASSIGN clause creates a name for an external data source,
23
+ *which is associated with the JCL DDNAME used by the z/OS
24
+ *e.g. ACCTREC is linked in JCL file CBL0001J to &SYSUID..DATA
25
+ *where &SYSUID. stands for Your z/OS user id
26
+ *e.g. if Your user id is Z54321,
27
+ *the data set used for ACCTREC is Z54321.DATA
28
+ *-------------
29
+ DATA DIVISION.
30
+ *-------------
31
+ FILE SECTION.
32
+ FD PRINT-LINE RECORDING MODE F.
33
+ 01 PRINT-REC.
34
+ 05 ACCT-NO-O PIC X(8).
35
+ 05 ACCT-LIMIT-O PIC $$,$$$,$$9.99.
36
+ 05 ACCT-BALANCE-O PIC $$,$$$,$$9.99.
37
+ * PIC $$,$$$,$$9.99 -- Alternative for PIC on chapter 7.2.3,
38
+ * using $ to allow values of different amounts of digits
39
+ * and .99 instead of v99 to allow period display on output
40
+ 05 LAST-NAME-O PIC X(20).
41
+ 05 FIRST-NAME-O PIC X(15).
42
+ 05 COMMENTS-O PIC X(50).
43
+ * since the level 05 is higher than level 01,
44
+ * all variables belong to PRINT-REC (see chapter 7.3.3)
45
+ *
46
+ FD ACCT-REC RECORDING MODE F.
47
+ 01 ACCT-FIELDS.
48
+ 05 ACCT-NO PIC X(8).
49
+ 05 ACCT-LIMIT PIC S9(7)V99 COMP-3.
50
+ 05 ACCT-BALANCE PIC S9(7)V99 COMP-3.
51
+ * PIC S9(7)v99 -- seven-digit plus a sign digit value
52
+ * COMP-3 -- packed BCD (binary coded decimal) representation
53
+ 05 LAST-NAME PIC X(20).
54
+ 05 FIRST-NAME PIC X(15).
55
+ 05 CLIENT-ADDR.
56
+ 10 STREET-ADDR PIC X(25).
57
+ 10 CITY-COUNTY PIC X(20).
58
+ 10 USA-STATE PIC X(15).
59
+ 05 RESERVED PIC X(7).
60
+ 05 COMMENTS PIC X(50).
61
+ *
62
+ WORKING-STORAGE SECTION.
63
+ 01 FLAGS.
64
+ 05 LASTREC PIC X VALUE SPACE.
65
+ *------------------
66
+ PROCEDURE DIVISION.
67
+ *------------------
68
+ OPEN-FILES.
69
+ OPEN INPUT ACCT-REC.
70
+ OPEN OUTPUT PRINT-LINE.
71
+ *
72
+ READ-NEXT-RECORD.
73
+ PERFORM READ-RECORD
74
+ * The previous statement is needed before entering the loop.
75
+ * Both the loop condition LASTREC = 'Y'
76
+ * and the call to WRITE-RECORD depend on READ-RECORD having
77
+ * been executed before.
78
+ * The loop starts at the next line with PERFORM UNTIL
79
+ PERFORM UNTIL LASTREC = 'Y'
80
+ PERFORM WRITE-RECORD
81
+ PERFORM READ-RECORD
82
+ END-PERFORM
83
+ .
84
+ *
85
+ CLOSE-STOP.
86
+ CLOSE ACCT-REC.
87
+ CLOSE PRINT-LINE.
88
+ GOBACK.
89
+ *
90
+ READ-RECORD.
91
+ READ ACCT-REC
92
+ AT END MOVE 'Y' TO LASTREC
93
+ END-READ.
94
+ *
95
+ WRITE-RECORD.
96
+ MOVE ACCT-NO TO ACCT-NO-O.
97
+ MOVE ACCT-LIMIT TO ACCT-LIMIT-O.
98
+ MOVE ACCT-BALANCE TO ACCT-BALANCE-O.
99
+ MOVE LAST-NAME TO LAST-NAME-O.
100
+ MOVE FIRST-NAME TO FIRST-NAME-O.
101
+ MOVE COMMENTS TO COMMENTS-O.
102
+ WRITE PRINT-REC.
103
+ *
@@ -0,0 +1,12 @@
1
+ {
2
+ // comments
3
+ unquoted: 'and you can quote me on that',
4
+ singleQuotes: 'I can use "double quotes" here',
5
+ lineBreaks: "Look, Mom! \
6
+ No \\n's!",
7
+ hexadecimal: 0xdecaf,
8
+ leadingDecimalPoint: .8675309, andTrailing: 8675309.,
9
+ positiveSign: +1,
10
+ trailingComma: 'in objects', andIn: ['arrays',],
11
+ "backwardsCompatible": "with JSON",
12
+ }
@@ -0,0 +1,10 @@
1
+ fn fib(n: Int): # write Fibonacci series up to n
2
+ """Print a Fibonacci series up to n."""
3
+ var a = 0
4
+ var b = 1
5
+ while a < n:
6
+ print(a)
7
+ a, b = b, a+b
8
+
9
+ fn main():
10
+ fib(10)
@@ -0,0 +1,99 @@
1
+ #include <core.p4>
2
+ #include <v1model.p4>
3
+
4
+ const bit<16> TYPE_IPV4 = 0x800;
5
+ typedef bit<9> egressSpec_t;
6
+ typedef bit<48> macAddr_t;
7
+ typedef bit<32> ip4Addr_t;
8
+
9
+ header ethernet_t {
10
+ macAddr_t dstAddr;
11
+ macAddr_t srcAddr;
12
+ bit<16> etherType;
13
+ }
14
+
15
+ header ipv4_t {
16
+ bit<4> version;
17
+ bit<4> ihl;
18
+ bit<8> diffserv;
19
+ bit<16> totalLen;
20
+ bit<16> identification;
21
+ bit<3> flags;
22
+ bit<13> fragOffset;
23
+ bit<8> ttl;
24
+ bit<8> protocol;
25
+ bit<16> hdrChecksum;
26
+ ip4Addr_t srcAddr;
27
+ ip4Addr_t dstAddr;
28
+ }
29
+
30
+ struct metadata { /* empty */ }
31
+
32
+ struct headers {
33
+ ethernet_t ethernet;
34
+ ipv4_t ipv4;
35
+ }
36
+
37
+ parser MyParser(packet_in packet,
38
+ out headers hdr,
39
+ inout metadata meta,
40
+ inout standard_metadata_t standard_metadata) {
41
+
42
+ state start { transition parse_ethernet; }
43
+
44
+ state parse_ethernet {
45
+ packet.extract(hdr.ethernet);
46
+ transition select(hdr.ethernet.etherType) {
47
+ TYPE_IPV4: parse_ipv4;
48
+ default: accept;
49
+ }
50
+ }
51
+
52
+ state parse_ipv4 {
53
+ packet.extract(hdr.ipv4);
54
+ transition accept;
55
+ }
56
+
57
+ }
58
+
59
+ control MyIngress(inout headers hdr,
60
+ inout metadata meta,
61
+ inout standard_metadata_t standard_metadata) {
62
+ action drop() {
63
+ mark_to_drop(standard_metadata);
64
+ }
65
+
66
+ action ipv4_forward(macAddr_t dstAddr, egressSpec_t port) {
67
+ standard_metadata.egress_spec = port;
68
+ hdr.ethernet.srcAddr = hdr.ethernet.dstAddr;
69
+ hdr.ethernet.dstAddr = dstAddr;
70
+ hdr.ipv4.ttl = hdr.ipv4.ttl - 1;
71
+ }
72
+
73
+ table ipv4_lpm {
74
+ key = { hdr.ipv4.dstAddr: lpm; }
75
+ actions = { ipv4_forward; drop; NoAction; }
76
+ size = 1024;
77
+ default_action = drop();
78
+ }
79
+
80
+ apply {
81
+ if (hdr.ipv4.isValid()) {
82
+ ipv4_lpm.apply();
83
+ }
84
+ }
85
+ }
86
+
87
+
88
+ control MyDeparser(packet_out packet, in headers hdr) {
89
+ apply {
90
+ packet.emit(hdr.ethernet);
91
+ packet.emit(hdr.ipv4);
92
+ }
93
+ }
94
+
95
+ V1Switch(
96
+ MyParser(),
97
+ MyIngress(),
98
+ MyDeparser()
99
+ ) main;
@@ -66,6 +66,12 @@ module Rouge
66
66
  end
67
67
  end
68
68
 
69
+ disambiguate '*.cfg' do
70
+ next CiscoIos if matches?(/\A\s*(version|banner|interface)\b/)
71
+
72
+ INI
73
+ end
74
+
69
75
  disambiguate '*.pl' do
70
76
  next Perl if contains?('my $')
71
77
  next Prolog if contains?(':-')
@@ -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'
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
@@ -7,8 +7,8 @@ module Rouge
7
7
  title "Docker"
8
8
  desc "Dockerfile syntax"
9
9
  tag 'docker'
10
- aliases 'dockerfile', 'Dockerfile'
11
- filenames 'Dockerfile', '*.Dockerfile', '*.docker'
10
+ aliases 'dockerfile', 'Dockerfile', 'containerfile', 'Containerfile'
11
+ filenames 'Dockerfile', '*.Dockerfile', '*.docker', 'Containerfile', '*.Containerfile'
12
12
  mimetypes 'text/x-dockerfile-config'
13
13
 
14
14
  KEYWORDS = %w(
@@ -7,11 +7,13 @@ module Rouge
7
7
  title "Groovy"
8
8
  desc 'The Groovy programming language (http://www.groovy-lang.org/)'
9
9
  tag 'groovy'
10
- filenames '*.groovy', 'Jenkinsfile', '*.Jenkinsfile'
10
+ aliases 'nextflow', 'nf'
11
+ filenames '*.groovy', 'Jenkinsfile', '*.Jenkinsfile', '*.nf'
11
12
  mimetypes 'text/x-groovy'
12
13
 
13
14
  def self.detect?(text)
14
15
  return true if text.shebang?(/groovy/)
16
+ return true if text.shebang?(/nextflow/)
15
17
  end
16
18
 
17
19
  def self.keywords
@@ -8,9 +8,8 @@ module Rouge
8
8
  desc 'the INI configuration format'
9
9
  tag 'ini'
10
10
 
11
- # TODO add more here
12
- filenames '*.ini', '*.INI', '*.gitconfig'
13
- mimetypes 'text/x-ini'
11
+ filenames '*.ini', '*.INI', '*.gitconfig', '*.cfg', '.editorconfig', '*.inf'
12
+ mimetypes 'text/x-ini', 'text/inf'
14
13
 
15
14
  identifier = /[\w\-.]+/
16
15
 
@@ -190,8 +190,8 @@ module Rouge
190
190
 
191
191
  rule %r/function(?=(\(.*\)))/, Keyword::Declaration # For anonymous functions
192
192
 
193
- rule %r/(#{id})[ \t]*(?=(\(.*\)))/m do |m|
194
- if self.class.keywords.include? m[1]
193
+ rule %r/(#?#{id})[ \t]*(?=(\(.*\)))/m do |m|
194
+ if self.class.keywords.include?(m[1])
195
195
  # "if" in "if (...)" or "switch" in "switch (...)" are recognized as keywords.
196
196
  token Keyword
197
197
  else
@@ -201,7 +201,7 @@ module Rouge
201
201
 
202
202
  rule %r/[{}]/, Punctuation, :statement
203
203
 
204
- rule id do |m|
204
+ rule %r/#?#{id}/ do |m|
205
205
  if self.class.keywords.include? m[0]
206
206
  token Keyword
207
207
  push :expr_start
@@ -0,0 +1,74 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ load_lexer 'json.rb'
7
+
8
+ class JSON5 < JSON
9
+ title 'JSON 5'
10
+ tag 'json5'
11
+ filenames '*.json5'
12
+ mimetypes 'application/json5', 'application/x-json5'
13
+
14
+ desc 'JSON 5 extension for JSON (json5.org)'
15
+
16
+ append :whitespace do
17
+ rule %r://.*$:, Comment
18
+
19
+ # comments are non-nesting, so a single regex will do
20
+ rule %r:/[*].*?[*]/:m, Comment
21
+ end
22
+
23
+ prepend :name do
24
+ rule Javascript.id_regex, Name::Label
25
+ rule %r/".*?"/, Name::Label
26
+ end
27
+
28
+ # comments can appear between keys and :, so we have to
29
+ # manage our states a little more carefully
30
+ append :object do
31
+ rule %r/:/ do
32
+ token Punctuation
33
+ goto :object_value
34
+ end
35
+ end
36
+
37
+ state :object_value do
38
+ mixin :value
39
+ rule %r/,/ do
40
+ token Punctuation
41
+ goto :object
42
+ end
43
+
44
+ rule %r/}/, Punctuation, :pop!
45
+ end
46
+
47
+ append :value do
48
+ rule %r/'/, Str::Single, :sstring
49
+ end
50
+
51
+ state :sstring do
52
+ rule %r/[^\\']+/, Str::Single
53
+ rule %r/\\./m, Str::Escape
54
+ rule %r/'/, Str::Single, :pop!
55
+ end
56
+
57
+ # can escape newlines
58
+ append :string do
59
+ rule %r/\\./m, Str::Escape
60
+ end
61
+
62
+ # override: numbers are very different in json5
63
+ state :constants do
64
+ rule %r/\b(?:true|false|null)\b/, Keyword::Constant
65
+ rule %r/[+-]?\b(?:Infinity|NaN)\b/, Keyword::Constant
66
+ rule %r/[+-]?0x\h+/i, Num::Hex
67
+
68
+ rule %r/[+-.]?[0-9]+[.]?[0-9]?([eE][-]?[0-9]+)?/i, Num::Float
69
+ rule %r/[+-]?\d+e[+-]?\d+/, Num::Integer
70
+ rule %r/[+-]?(?:0|[1-9]\d*)(?:e[+-]?\d+)?/i, Num::Integer
71
+ end
72
+ end
73
+ end
74
+ end
@@ -40,6 +40,10 @@ module Rouge
40
40
  groups Keyword, Text, Name::Variable
41
41
  end
42
42
 
43
+ rule %r/(else\b)([\t ]+)((?:ifn?def|ifn?eq)\b)([\t ]+)([^#\n]+)/ do
44
+ groups Keyword, Text, Keyword, Text, Name::Variable
45
+ end
46
+
43
47
  rule %r/(?:else|endif|endef|endfor)[\t ]*(?=[#\n])/, Keyword
44
48
 
45
49
  rule %r/(export)([\t ]+)(?=[\w\${}()\t -]+\n)/ do
@@ -0,0 +1,35 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ load_lexer 'python.rb'
7
+
8
+ class Mojo < Python
9
+ title "Mojo"
10
+ desc "The Mojo programming language (modular.com)"
11
+ tag 'mojo'
12
+ aliases 'mojo'
13
+ filenames '*.mojo', '*.🔥'
14
+ mimetypes 'text/x-mojo', 'application/x-mojo'
15
+
16
+ def self.detect?(text)
17
+ return true if text.shebang?(/mojow?(?:[23](?:\.\d+)?)?/)
18
+ end
19
+
20
+ def self.keywords
21
+ @keywords ||= super + %w(
22
+ fn self alias inout borrowed owned ref var
23
+ struct trait raises with in match case
24
+ )
25
+ end
26
+
27
+ def self.builtins
28
+ @builtins ||= super + %w(
29
+ __mlir_attr __mlir_type __mlir_op parameter alwaysinline
30
+ register_passable
31
+ )
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,81 @@
1
+ # -*- coding: utf-8 -*- #
2
+ # frozen_string_literal: true
3
+
4
+ module Rouge
5
+ module Lexers
6
+ class P4 < RegexLexer
7
+ tag 'p4'
8
+ title 'P4'
9
+ desc 'The P4 programming language'
10
+ filenames '*.p4'
11
+ mimetypes 'text/x-p4'
12
+
13
+ def self.keywords
14
+ @keywords ||= %w(
15
+ abstract action actions apply const default default_action else enum
16
+ entries extern exit if in inout key list out package packet_in
17
+ packet_out return size select switch this transition tuple type
18
+ typedef
19
+ )
20
+ end
21
+
22
+ def self.operators
23
+ @operators ||= %w(
24
+ \|\+\| \|-\| \? \& \&\&\& < > << >> \* \| ~ \^ - \+ /
25
+ \# \. = != <= >= \+\+
26
+ )
27
+ end
28
+
29
+ def self.decls
30
+ @decls ||= %w(
31
+ control header header_union parser state struct table
32
+ value_set
33
+ )
34
+ end
35
+
36
+ def self.builtins
37
+ @builtins ||= %w(
38
+ bit bool error extract int isValid setValid setInvalid match_kind
39
+ string varbit verify void
40
+ )
41
+ end
42
+
43
+ state :whitespace do
44
+ rule %r/\s+/m, Text
45
+ end
46
+
47
+ state :comment do
48
+ rule %r((//).*$\n?), Comment::Single
49
+ rule %r/\/\*(?:(?!\*\/).)*\*\//m, Comment::Multiline
50
+ end
51
+
52
+ state :number do
53
+ rule %r/([0-9]+[sw])?0[oO][0-7_]+/, Num
54
+ rule %r/([0-9]+[sw])?0[xX][0-9a-fA-F_]+/, Num
55
+ rule %r/([0-9]+[sw])?0[bB][01_]+/, Num
56
+ rule %r/([0-9]+[sw])?0[dD][0-9_]+/, Num
57
+ rule %r/([0-9]+[sw])?[0-9_]+/, Num
58
+ end
59
+
60
+ id = /[\p{XID_Start}_]\p{XID_Continue}*/
61
+ string_element = /\\"|[^"]/x
62
+
63
+ state :root do
64
+ mixin :whitespace
65
+ mixin :comment
66
+
67
+ rule %r/#\s*#{id}/, Comment::Preproc
68
+ rule %r/\b(?:#{P4.keywords.join('|')})\b/, Keyword
69
+ rule %r/\b(?:#{P4.decls.join('|')})\b/, Keyword::Declaration
70
+ rule %r/\b(?:#{P4.builtins.join('|')})\b/, Name::Builtin
71
+ rule %r/\b#{id}_[th]\b/x, Name::Class
72
+ rule %r/(?:#{P4.operators.join('|')})/x, Operator
73
+ rule %r/[(){}\[\]<>,:;\.]/, Punctuation
74
+ mixin :number
75
+ rule %r/@#{id}/x, Name::Label
76
+ rule %r/#{id}/x, Text
77
+ rule %r/"(?: #{string_element} )*"/x, Str::String
78
+ end
79
+ end
80
+ end
81
+ end
@@ -11,7 +11,7 @@ module Rouge
11
11
  filenames '*.rb', '*.ruby', '*.rbw', '*.rake', '*.gemspec', '*.podspec',
12
12
  'Rakefile', 'Guardfile', 'Gemfile', 'Capfile', 'Podfile',
13
13
  'Vagrantfile', '*.ru', '*.prawn', 'Berksfile', '*.arb',
14
- 'Dangerfile', 'Fastfile', 'Deliverfile', 'Appfile'
14
+ 'Dangerfile', 'Fastfile', 'Deliverfile', 'Appfile', '*.thor', 'Thorfile'
15
15
 
16
16
  mimetypes 'text/x-ruby', 'application/x-ruby'
17
17
 
@@ -39,8 +39,9 @@ module Rouge
39
39
 
40
40
  state :strings do
41
41
  rule %r/\\./, Str::Escape
42
+ rule %r/(\$[\$]+|%[%]+)(\{)/, Str
42
43
  rule %r/\$\{/ do
43
- token Keyword
44
+ token Punctuation
44
45
  push :interpolation
45
46
  end
46
47
  end
@@ -66,7 +67,7 @@ module Rouge
66
67
 
67
68
  state :interpolation do
68
69
  rule %r/\}/ do
69
- token Keyword
70
+ token Punctuation
70
71
  pop!
71
72
  end
72
73
 
@@ -166,6 +166,19 @@ module Rouge
166
166
  puts " yielding: #{tok.qualname}, #{stream[0].inspect}" if @debug
167
167
  @output_stream.call(tok, stream[0])
168
168
  end
169
+ when Array
170
+ proc do |stream|
171
+ puts " yielding: #{tok.qualname}, #{stream[0].inspect}" if @debug
172
+ @output_stream.call(tok, stream[0])
173
+ for i_next_state in next_state do
174
+ next @stack.pop if i_next_state == :pop!
175
+ next @stack.push(@stack.last) if i_next_state == :push
176
+
177
+ state = @states[i_next_state] || self.class.get_state(i_next_state)
178
+ puts " pushing :#{state.name}" if @debug
179
+ @stack.push(state)
180
+ end
181
+ end
169
182
  else
170
183
  raise "invalid next state: #{next_state.inspect}"
171
184
  end
data/lib/rouge/version.rb CHANGED
@@ -3,6 +3,6 @@
3
3
 
4
4
  module Rouge
5
5
  def self.version
6
- "4.3.0"
6
+ "4.5.1"
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rouge
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.0
4
+ version: 4.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeanine Adkisson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-14 00:00:00.000000000 Z
11
+ date: 2024-11-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Rouge aims to a be a simple, easy-to-extend drop-in replacement for pygments.
14
14
  email:
@@ -49,6 +49,7 @@ files:
49
49
  - lib/rouge/demos/clojure
50
50
  - lib/rouge/demos/cmake
51
51
  - lib/rouge/demos/cmhg
52
+ - lib/rouge/demos/cobol
52
53
  - lib/rouge/demos/codeowners
53
54
  - lib/rouge/demos/coffeescript
54
55
  - lib/rouge/demos/common_lisp
@@ -125,6 +126,7 @@ files:
125
126
  - lib/rouge/demos/jsl
126
127
  - lib/rouge/demos/json
127
128
  - lib/rouge/demos/json-doc
129
+ - lib/rouge/demos/json5
128
130
  - lib/rouge/demos/jsonnet
129
131
  - lib/rouge/demos/jsp
130
132
  - lib/rouge/demos/jsx
@@ -149,6 +151,7 @@ files:
149
151
  - lib/rouge/demos/matlab
150
152
  - lib/rouge/demos/meson
151
153
  - lib/rouge/demos/minizinc
154
+ - lib/rouge/demos/mojo
152
155
  - lib/rouge/demos/moonscript
153
156
  - lib/rouge/demos/mosel
154
157
  - lib/rouge/demos/msgtrans
@@ -165,6 +168,7 @@ files:
165
168
  - lib/rouge/demos/ocl
166
169
  - lib/rouge/demos/openedge
167
170
  - lib/rouge/demos/opentype_feature_file
171
+ - lib/rouge/demos/p4
168
172
  - lib/rouge/demos/pascal
169
173
  - lib/rouge/demos/perl
170
174
  - lib/rouge/demos/php
@@ -293,6 +297,7 @@ files:
293
297
  - lib/rouge/lexers/clojure.rb
294
298
  - lib/rouge/lexers/cmake.rb
295
299
  - lib/rouge/lexers/cmhg.rb
300
+ - lib/rouge/lexers/cobol.rb
296
301
  - lib/rouge/lexers/codeowners.rb
297
302
  - lib/rouge/lexers/coffeescript.rb
298
303
  - lib/rouge/lexers/common_lisp.rb
@@ -369,6 +374,7 @@ files:
369
374
  - lib/rouge/lexers/jinja.rb
370
375
  - lib/rouge/lexers/jsl.rb
371
376
  - lib/rouge/lexers/json.rb
377
+ - lib/rouge/lexers/json5.rb
372
378
  - lib/rouge/lexers/json_doc.rb
373
379
  - lib/rouge/lexers/jsonnet.rb
374
380
  - lib/rouge/lexers/jsp.rb
@@ -400,6 +406,7 @@ files:
400
406
  - lib/rouge/lexers/matlab/keywords.rb
401
407
  - lib/rouge/lexers/meson.rb
402
408
  - lib/rouge/lexers/minizinc.rb
409
+ - lib/rouge/lexers/mojo.rb
403
410
  - lib/rouge/lexers/moonscript.rb
404
411
  - lib/rouge/lexers/mosel.rb
405
412
  - lib/rouge/lexers/msgtrans.rb
@@ -418,6 +425,7 @@ files:
418
425
  - lib/rouge/lexers/ocl.rb
419
426
  - lib/rouge/lexers/openedge.rb
420
427
  - lib/rouge/lexers/opentype_feature_file.rb
428
+ - lib/rouge/lexers/p4.rb
421
429
  - lib/rouge/lexers/pascal.rb
422
430
  - lib/rouge/lexers/perl.rb
423
431
  - lib/rouge/lexers/php.rb
@@ -549,7 +557,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
549
557
  - !ruby/object:Gem::Version
550
558
  version: '0'
551
559
  requirements: []
552
- rubygems_version: 3.5.3
560
+ rubygems_version: 3.5.19
553
561
  signing_key:
554
562
  specification_version: 4
555
563
  summary: A pure-ruby colorizer based on pygments