rouge 3.7.0 → 3.8.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.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/lib/rouge/demos/armasm +12 -0
- data/lib/rouge/demos/batchfile +3 -0
- data/lib/rouge/demos/bbcbasic +6 -0
- data/lib/rouge/demos/cmhg +8 -0
- data/lib/rouge/demos/cython +6 -0
- data/lib/rouge/demos/epp +4 -0
- data/lib/rouge/demos/msgtrans +4 -0
- data/lib/rouge/demos/plist +1 -132
- data/lib/rouge/formatters/html_line_table.rb +3 -1
- data/lib/rouge/formatters/tex.rb +11 -12
- data/lib/rouge/guessers/disambiguation.rb +8 -0
- data/lib/rouge/lexers/armasm.rb +145 -0
- data/lib/rouge/lexers/batchfile.rb +164 -0
- data/lib/rouge/lexers/bbcbasic.rb +112 -0
- data/lib/rouge/lexers/cmhg.rb +34 -0
- data/lib/rouge/lexers/console.rb +1 -1
- data/lib/rouge/lexers/cpp.rb +4 -1
- data/lib/rouge/lexers/cython.rb +151 -0
- data/lib/rouge/lexers/epp.rb +51 -0
- data/lib/rouge/lexers/json.rb +1 -1
- data/lib/rouge/lexers/julia.rb +1 -1
- data/lib/rouge/lexers/make.rb +39 -12
- data/lib/rouge/lexers/msgtrans.rb +26 -0
- data/lib/rouge/lexers/plain_text.rb +1 -1
- data/lib/rouge/lexers/puppet.rb +2 -2
- data/lib/rouge/lexers/r.rb +2 -3
- data/lib/rouge/lexers/sed.rb +1 -1
- data/lib/rouge/tex_theme_renderer.rb +2 -1
- data/lib/rouge/themes/magritte.rb +2 -2
- data/lib/rouge/version.rb +1 -1
- data/rouge.gemspec +4 -2
- metadata +21 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4041f8ac950b427b35d8d3147b6d9aed3743655daaaf09f57d303932b11259a6
|
4
|
+
data.tar.gz: cddd94af18b0f7ba578fa4c57f75415233d5518095b29202a7c12afd2662b804
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68b649f1f965e5cd21fd722263bdff8720ba04119b8fff2245bb9c4178648d255362c3a18129c6724dd56893f777a518d1ff74ade223697530f5a6595d20f2aa
|
7
|
+
data.tar.gz: 182df2ef3e868eb95132022309db218e34f2cd19e9e874a7d119f6250db0971e7ba6fd28ddea2ebfa8fdb759504dfe8a8401e085e95386748c7a00de347fc5d9
|
data/Gemfile
CHANGED
data/lib/rouge/demos/epp
ADDED
data/lib/rouge/demos/plist
CHANGED
@@ -5,138 +5,7 @@
|
|
5
5
|
};
|
6
6
|
objectVersion = 46;
|
7
7
|
objects = {
|
8
|
-
|
9
|
-
/* Begin PBXGroup section */
|
10
|
-
1D67B9537FE4C81097096F85 /* Frameworks */ = {
|
11
|
-
isa = PBXGroup;
|
12
|
-
children = (
|
13
|
-
);
|
14
|
-
name = Frameworks;
|
15
|
-
sourceTree = "<group>";
|
16
|
-
};
|
17
|
-
74946460D3EE9E1FA4792785 = {
|
18
|
-
isa = PBXGroup;
|
19
|
-
children = (
|
20
|
-
E3060171E73473A889949AB5 /* Products */,
|
21
|
-
1D67B9537FE4C81097096F85 /* Frameworks */,
|
22
|
-
);
|
23
|
-
sourceTree = "<group>";
|
24
|
-
};
|
25
|
-
E3060171E73473A889949AB5 /* Products */ = {
|
26
|
-
isa = PBXGroup;
|
27
|
-
children = (
|
28
|
-
);
|
29
|
-
name = Products;
|
30
|
-
sourceTree = "<group>";
|
31
|
-
};
|
32
|
-
/* End PBXGroup section */
|
33
|
-
|
34
|
-
/* Begin PBXProject section */
|
35
|
-
B3A67937542EC2041CBF1CA2 /* Project object */ = {
|
36
|
-
isa = PBXProject;
|
37
|
-
attributes = {
|
38
|
-
LastSwiftUpdateCheck = 0730;
|
39
|
-
LastUpgradeCheck = 0700;
|
40
|
-
};
|
41
|
-
buildConfigurationList = 442CE273DD7DF2DFDC620C8B /* Build configuration list for PBXProject "foo" */;
|
42
|
-
compatibilityVersion = "Xcode 3.2";
|
43
|
-
developmentRegion = English;
|
44
|
-
hasScannedForEncodings = 0;
|
45
|
-
knownRegions = (
|
46
|
-
en,
|
47
|
-
);
|
48
|
-
mainGroup = 74946460D3EE9E1FA4792785;
|
49
|
-
productRefGroup = E3060171E73473A889949AB5 /* Products */;
|
50
|
-
projectDirPath = "";
|
51
|
-
projectRoot = "";
|
52
|
-
targets = (
|
53
|
-
);
|
54
|
-
};
|
55
|
-
/* End PBXProject section */
|
56
|
-
|
57
|
-
/* Begin XCBuildConfiguration section */
|
58
|
-
09AC0D63F19B6944E1045E60 /* Release */ = {
|
59
|
-
isa = XCBuildConfiguration;
|
60
|
-
buildSettings = {
|
61
|
-
ALWAYS_SEARCH_USER_PATHS = NO;
|
62
|
-
CLANG_ANALYZER_NONNULL = YES;
|
63
|
-
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
64
|
-
CLANG_CXX_LIBRARY = "libc++";
|
65
|
-
CLANG_ENABLE_MODULES = YES;
|
66
|
-
CLANG_ENABLE_OBJC_ARC = YES;
|
67
|
-
CLANG_WARN_BOOL_CONVERSION = YES;
|
68
|
-
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
69
|
-
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES;
|
70
|
-
CLANG_WARN_EMPTY_BODY = YES;
|
71
|
-
CLANG_WARN_ENUM_CONVERSION = YES;
|
72
|
-
CLANG_WARN_INT_CONVERSION = YES;
|
73
|
-
CLANG_WARN_OBJC_ROOT_CLASS = YES;
|
74
|
-
CLANG_WARN_UNREACHABLE_CODE = YES;
|
75
|
-
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
76
|
-
COPY_PHASE_STRIP = YES;
|
77
|
-
ENABLE_NS_ASSERTIONS = NO;
|
78
|
-
GCC_C_LANGUAGE_STANDARD = gnu99;
|
79
|
-
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
80
|
-
GCC_WARN_ABOUT_RETURN_TYPE = YES;
|
81
|
-
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
82
|
-
GCC_WARN_UNINITIALIZED_AUTOS = YES;
|
83
|
-
GCC_WARN_UNUSED_FUNCTION = YES;
|
84
|
-
GCC_WARN_UNUSED_VARIABLE = YES;
|
85
|
-
VALIDATE_PRODUCT = YES;
|
86
|
-
};
|
87
|
-
name = Release;
|
88
|
-
};
|
89
|
-
4D494CA5F82DCCAB3194BA09 /* Debug */ = {
|
90
|
-
isa = XCBuildConfiguration;
|
91
|
-
buildSettings = {
|
92
|
-
ALWAYS_SEARCH_USER_PATHS = NO;
|
93
|
-
CLANG_ANALYZER_NONNULL = YES;
|
94
|
-
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
95
|
-
CLANG_CXX_LIBRARY = "libc++";
|
96
|
-
CLANG_ENABLE_MODULES = YES;
|
97
|
-
CLANG_ENABLE_OBJC_ARC = YES;
|
98
|
-
CLANG_WARN_BOOL_CONVERSION = YES;
|
99
|
-
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
100
|
-
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES;
|
101
|
-
CLANG_WARN_EMPTY_BODY = YES;
|
102
|
-
CLANG_WARN_ENUM_CONVERSION = YES;
|
103
|
-
CLANG_WARN_INT_CONVERSION = YES;
|
104
|
-
CLANG_WARN_OBJC_ROOT_CLASS = YES;
|
105
|
-
CLANG_WARN_UNREACHABLE_CODE = YES;
|
106
|
-
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
107
|
-
COPY_PHASE_STRIP = NO;
|
108
|
-
ENABLE_TESTABILITY = YES;
|
109
|
-
GCC_C_LANGUAGE_STANDARD = gnu99;
|
110
|
-
GCC_DYNAMIC_NO_PIC = NO;
|
111
|
-
GCC_OPTIMIZATION_LEVEL = 0;
|
112
|
-
GCC_PREPROCESSOR_DEFINITIONS = (
|
113
|
-
"DEBUG=1",
|
114
|
-
"$(inherited)",
|
115
|
-
);
|
116
|
-
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
|
117
|
-
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
118
|
-
GCC_WARN_ABOUT_RETURN_TYPE = YES;
|
119
|
-
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
120
|
-
GCC_WARN_UNINITIALIZED_AUTOS = YES;
|
121
|
-
GCC_WARN_UNUSED_FUNCTION = YES;
|
122
|
-
GCC_WARN_UNUSED_VARIABLE = YES;
|
123
|
-
ONLY_ACTIVE_ARCH = YES;
|
124
|
-
};
|
125
|
-
name = Debug;
|
126
|
-
};
|
127
|
-
/* End XCBuildConfiguration section */
|
128
|
-
|
129
|
-
/* Begin XCConfigurationList section */
|
130
|
-
442CE273DD7DF2DFDC620C8B /* Build configuration list for PBXProject "foo" */ = {
|
131
|
-
isa = XCConfigurationList;
|
132
|
-
buildConfigurations = (
|
133
|
-
4D494CA5F82DCCAB3194BA09 /* Debug */,
|
134
|
-
09AC0D63F19B6944E1045E60 /* Release */,
|
135
|
-
);
|
136
|
-
defaultConfigurationIsVisible = 0;
|
137
|
-
defaultConfigurationName = Release;
|
138
|
-
};
|
139
|
-
/* End XCConfigurationList section */
|
8
|
+
/* ... */
|
140
9
|
};
|
141
10
|
rootObject = B3A67937542EC2041CBF1CA2 /* Project object */;
|
142
11
|
}
|
@@ -37,7 +37,9 @@ module Rouge
|
|
37
37
|
token_lines(tokens) do |line_tokens|
|
38
38
|
lineno += 1
|
39
39
|
buffer << %(<tr id="#{sprintf @line_id, lineno}" class="#@line_class">)
|
40
|
-
buffer << %(<td class="#@gutter_class gl"
|
40
|
+
buffer << %(<td class="#@gutter_class gl" )
|
41
|
+
buffer << %(style="-moz-user-select: none;-ms-user-select: none;)
|
42
|
+
buffer << %(-webkit-user-select: none;user-select: none;">)
|
41
43
|
buffer << %(<pre>#{lineno}</pre></td>)
|
42
44
|
buffer << %(<td class="#@code_class"><pre>)
|
43
45
|
@formatter.stream(line_tokens) { |formatted| buffer << formatted }
|
data/lib/rouge/formatters/tex.rb
CHANGED
@@ -22,6 +22,9 @@ module Rouge
|
|
22
22
|
'^' => '{\textasciicircum}',
|
23
23
|
'|' => '{\textbar}',
|
24
24
|
'\\' => '{\textbackslash}',
|
25
|
+
'`' => '{\textasciigrave}',
|
26
|
+
"'" => "'{}",
|
27
|
+
'"' => '"{}',
|
25
28
|
"\t" => '{\tab}',
|
26
29
|
}
|
27
30
|
|
@@ -59,24 +62,20 @@ module Rouge
|
|
59
62
|
end
|
60
63
|
|
61
64
|
def render_line(line, &b)
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
tag_first(*head, &b)
|
66
|
-
rest.each do |(tok, val)|
|
67
|
-
yield tag(tok, val)
|
65
|
+
line.each do |(tok, val)|
|
66
|
+
hphantom_tag(tok, val, &b)
|
68
67
|
end
|
69
68
|
end
|
70
69
|
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
74
|
-
#
|
75
|
-
def
|
70
|
+
# Special handling for leading spaces, since they may be gobbled
|
71
|
+
# by a previous command. We replace all initial spaces with
|
72
|
+
# \hphantom{xxxx}, which renders an empty space equal to the size
|
73
|
+
# of the x's.
|
74
|
+
def hphantom_tag(tok, val)
|
76
75
|
leading = nil
|
77
76
|
val.sub!(/^[ ]+/) { leading = $&.size; '' }
|
78
77
|
yield "\\hphantom{#{'x' * leading}}" if leading
|
79
|
-
yield tag(tok, val)
|
78
|
+
yield tag(tok, val) unless val.empty?
|
80
79
|
end
|
81
80
|
|
82
81
|
def tag(tok, val)
|
@@ -75,6 +75,8 @@ module Rouge
|
|
75
75
|
disambiguate '*.h' do
|
76
76
|
next ObjectiveC if matches?(/@(end|implementation|protocol|property)\b/)
|
77
77
|
next ObjectiveC if contains?('@"')
|
78
|
+
next Cpp if matches?(/^\s*(?:catch|class|constexpr|namespace|private|
|
79
|
+
protected|public|template|throw|try|using)\b/x)
|
78
80
|
|
79
81
|
C
|
80
82
|
end
|
@@ -118,6 +120,12 @@ module Rouge
|
|
118
120
|
|
119
121
|
next Python
|
120
122
|
end
|
123
|
+
|
124
|
+
disambiguate 'Messages' do
|
125
|
+
next MsgTrans if matches?(/^[^\s:]+:[^\s:]+/)
|
126
|
+
|
127
|
+
next PlainText
|
128
|
+
end
|
121
129
|
end
|
122
130
|
end
|
123
131
|
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
# -*- coding: utf-8 -*- #
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Rouge
|
5
|
+
module Lexers
|
6
|
+
class ArmAsm < RegexLexer
|
7
|
+
title "ArmAsm"
|
8
|
+
desc "Arm assembly syntax"
|
9
|
+
tag 'armasm'
|
10
|
+
filenames '*.s'
|
11
|
+
|
12
|
+
def self.preproc_keyword
|
13
|
+
@preproc_keyword ||= %w(
|
14
|
+
define elif else endif error if ifdef ifndef include line pragma undef warning
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.file_directive
|
19
|
+
@file_directive ||= %w(
|
20
|
+
BIN GET INCBIN INCLUDE LNK
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.general_directive
|
25
|
+
@general_directive ||= %w(
|
26
|
+
ALIAS ALIGN AOF AOUT AREA ARM ASSERT ATTR CN CODE16 CODE32 COMMON CP
|
27
|
+
DATA DCB DCD DCDO DCDU DCFD DCFDU DCFH DCFHU DCFS DCFSU DCI DCI.N DCI.W
|
28
|
+
DCQ DCQU DCW DCWU DN ELIF ELSE END ENDFUNC ENDIF ENDP ENTRY EQU EXPORT
|
29
|
+
EXPORTAS EXTERN FIELD FILL FN FRAME FUNCTION GBLA GBLL GBLS GLOBAL IF
|
30
|
+
IMPORT INFO KEEP LCLA LCLL LCLS LEADR LEAF LTORG MACRO MAP MEND MEXIT
|
31
|
+
NOFP OPT ORG PRESERVE8 PROC QN RELOC REQUIRE REQUIRE8 RLIST RN ROUT
|
32
|
+
SETA SETL SETS SN SPACE STRONG SUBT THUMB THUMBX TTL WEND WHILE
|
33
|
+
\[ \] [|!#*=%&^]
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.shift_or_condition
|
38
|
+
@shift_or_condition ||= %w(
|
39
|
+
ASR LSL LSR ROR RRX AL CC CS EQ GE GT HI HS LE LO LS LT MI NE PL VC VS
|
40
|
+
asr lsl lsr ror rrx al cc cs eq ge gt hi hs le lo ls lt mi ne pl vc vs
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.builtin
|
45
|
+
@builtin ||= %w(
|
46
|
+
ARCHITECTURE AREANAME ARMASM_VERSION CODESIZE COMMANDLINE CONFIG CPU
|
47
|
+
ENDIAN FALSE FPIC FPU INPUTFILE INTER LINENUM LINENUMUP LINENUMUPPER
|
48
|
+
OBJASM_VERSION OPT PC PCSTOREOFFSET REENTRANT ROPI RWPI TRUE VAR
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.operator
|
53
|
+
@operator ||= %w(
|
54
|
+
AND BASE CC CC_ENCODING CHR DEF EOR FATTR FEXEC FLOAD FSIZE INDEX LAND
|
55
|
+
LEFT LEN LEOR LNOT LOR LOWERCASE MOD NOT OR RCONST REVERSE_CC RIGHT ROL
|
56
|
+
ROR SHL SHR STR TARGET_ARCH_[0-9A-Z_]+ TARGET_FEATURE_[0-9A-Z_]+
|
57
|
+
TARGET_FPU_[A-Z_] TARGET_PROFILE_[ARM] UAL UPPERCASE
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
state :root do
|
62
|
+
rule %r/\n/, Text
|
63
|
+
rule %r/^([ \t]*)(#[ \t]*(?:(?:#{ArmAsm.preproc_keyword.join('|')})(?:[ \t].*)?)?)(\n)/ do
|
64
|
+
groups Text, Comment::Preproc, Text
|
65
|
+
end
|
66
|
+
rule %r/[ \t]+/, Text, :command
|
67
|
+
rule %r/;.*/, Comment
|
68
|
+
rule %r/\$[a-z_]\w*\.?/i, Name::Namespace # variable substitution or macro argument
|
69
|
+
rule %r/\w+|\|[^|\n]+\|/, Name::Label
|
70
|
+
end
|
71
|
+
|
72
|
+
state :command do
|
73
|
+
rule %r/\n/, Text, :pop!
|
74
|
+
rule %r/[ \t]+/ do |m|
|
75
|
+
token Text
|
76
|
+
goto :args
|
77
|
+
end
|
78
|
+
rule %r/;.*/, Comment, :pop!
|
79
|
+
rule %r/(?:#{ArmAsm.file_directive.join('|')})\b/ do |m|
|
80
|
+
token Keyword
|
81
|
+
goto :filespec
|
82
|
+
end
|
83
|
+
rule %r/(?:#{ArmAsm.general_directive.join('|')})(?=[; \t\n])/, Keyword
|
84
|
+
rule %r/(?:[A-Z][\dA-Z]*|[a-z][\da-z]*)(?:\.[NWnw])?(?:\.[DFIPSUdfipsu]?(?:8|16|32|64)?){,3}\b/, Name::Builtin # rather than attempt to list all opcodes, rely on all-uppercase or all-lowercase rule
|
85
|
+
rule %r/[a-z_]\w*|\|[^|\n]+\|/i, Name::Function # probably a macro name
|
86
|
+
rule %r/\$[a-z]\w*\.?/i, Name::Namespace
|
87
|
+
end
|
88
|
+
|
89
|
+
state :args do
|
90
|
+
rule %r/\n/, Text, :pop!
|
91
|
+
rule %r/[ \t]+/, Text
|
92
|
+
rule %r/;.*/, Comment, :pop!
|
93
|
+
rule %r/(?:#{ArmAsm.shift_or_condition.join('|')})\b/, Name::Builtin
|
94
|
+
rule %r/[a-z_]\w*|\|[^|\n]+\|/i, Name::Variable # various types of symbol
|
95
|
+
rule %r/%[bf]?[at]?\d+(?:[a-z_]\w*)?/i, Name::Label
|
96
|
+
rule %r/(?:&|0x)\h+(?!p)/i, Literal::Number::Hex
|
97
|
+
rule %r/(?:&|0x)[.\h]+(?:p[-+]?\d+)?/i, Literal::Number::Float
|
98
|
+
rule %r/0f_\h{8}|0d_\h{16}/i, Literal::Number::Float
|
99
|
+
rule %r/(?:2_[01]+|3_[0-2]+|4_[0-3]+|5_[0-4]+|6_[0-5]+|7_[0-6]+|8_[0-7]+|9_[0-8]+|\d+)(?!e)/i, Literal::Number::Integer
|
100
|
+
rule %r/(?:2_[.01]+|3_[.0-2]+|4_[.0-3]+|5_[.0-4]+|6_[.0-5]+|7_[.0-6]+|8_[.0-7]+|9_[.0-8]+|[.\d]+)(?:e[-+]?\d+)?/i, Literal::Number::Float
|
101
|
+
rule %r/[@:](?=[ \t]*(?:8|16|32|64|128|256)[^\d])/, Operator
|
102
|
+
rule %r/[.@]|\{(?:#{ArmAsm.builtin.join('|')})\}/, Name::Constant
|
103
|
+
rule %r/[-!#%&()*+,\/<=>?^{|}]|\[|\]|!=|&&|\/=|<<|<=|<>|==|><|>=|>>|\|\||:(?:#{ArmAsm.operator.join('|')}):/, Operator
|
104
|
+
rule %r/\$[a-z]\w*\.?/i, Name::Namespace
|
105
|
+
rule %r/'/ do |m|
|
106
|
+
token Literal::String::Char
|
107
|
+
goto :singlequoted
|
108
|
+
end
|
109
|
+
rule %r/"/ do |m|
|
110
|
+
token Literal::String::Double
|
111
|
+
goto :doublequoted
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
state :singlequoted do
|
116
|
+
rule %r/\n/, Text, :pop!
|
117
|
+
rule %r/\$\$/, Literal::String::Char
|
118
|
+
rule %r/\$[a-z]\w*\.?/i, Name::Namespace
|
119
|
+
rule %r/'/ do |m|
|
120
|
+
token Literal::String::Char
|
121
|
+
goto :args
|
122
|
+
end
|
123
|
+
rule %r/[^$'\n]+/, Literal::String::Char
|
124
|
+
end
|
125
|
+
|
126
|
+
state :doublequoted do
|
127
|
+
rule %r/\n/, Text, :pop!
|
128
|
+
rule %r/\$\$/, Literal::String::Double
|
129
|
+
rule %r/\$[a-z]\w*\.?/i, Name::Namespace
|
130
|
+
rule %r/"/ do |m|
|
131
|
+
token Literal::String::Double
|
132
|
+
goto :args
|
133
|
+
end
|
134
|
+
rule %r/[^$"\n]+/, Literal::String::Double
|
135
|
+
end
|
136
|
+
|
137
|
+
state :filespec do
|
138
|
+
rule %r/\n/, Text, :pop!
|
139
|
+
rule %r/\$\$/, Literal::String::Other
|
140
|
+
rule %r/\$[a-z]\w*\.?/i, Name::Namespace
|
141
|
+
rule %r/[^$\n]+/, Literal::String::Other
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
# -*- coding: utf-8 -*- #
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Rouge
|
5
|
+
module Lexers
|
6
|
+
class Batchfile < RegexLexer
|
7
|
+
title "Batchfile"
|
8
|
+
desc "Windows Batch File"
|
9
|
+
|
10
|
+
tag 'batchfile'
|
11
|
+
aliases 'bat', 'batch', 'dosbatch', 'winbatch'
|
12
|
+
filenames '*.bat', '*.cmd'
|
13
|
+
|
14
|
+
mimetypes 'application/bat', 'application/x-bat', 'application/x-msdos-program'
|
15
|
+
|
16
|
+
def self.keywords
|
17
|
+
@keywords ||= %w(
|
18
|
+
if else for in do goto call exit
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.operator_words
|
23
|
+
@operator_words ||= %w(
|
24
|
+
exist defined errorlevel cmdextversion not equ neq lss leq gtr geq
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.devices
|
29
|
+
@devices ||= %w(
|
30
|
+
con prn aux nul com1 com2 com3 com4 com5 com6 com7 com8 com9 lpt1 lpt2
|
31
|
+
lpt3 lpt4 lpt5 lpt6 lpt7 lpt8 lpt9
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.builtin_commands
|
36
|
+
@builtin_commands ||= %w(
|
37
|
+
assoc attrib break bcdedit cacls cd chcp chdir chkdsk chkntfs choice
|
38
|
+
cls cmd color comp compact convert copy date del dir diskpart doskey
|
39
|
+
dpath driverquery echo endlocal erase fc find findstr format fsutil
|
40
|
+
ftype gpresult graftabl help icacls label md mkdir mklink mode more
|
41
|
+
move openfiles path pause popd print prompt pushd rd recover ren
|
42
|
+
rename replace rmdir robocopy setlocal sc schtasks shift shutdown sort
|
43
|
+
start subst systeminfo takeown tasklist taskkill time timeout title
|
44
|
+
tree type ver verify vol xcopy waitfor wmic
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.other_commands
|
49
|
+
@other_commands ||= %w(
|
50
|
+
addusers admodcmd ansicon arp at bcdboot bitsadmin browstat certreq
|
51
|
+
certutil change cidiag cipher cleanmgr clip cmdkey compress convertcp
|
52
|
+
coreinfo csccmd csvde cscript curl debug defrag delprof deltree devcon
|
53
|
+
diamond dirquota diruse diskshadow diskuse dism dnscmd dsacls dsadd
|
54
|
+
dsget dsquery dsmod dsmove dsrm dsmgmt dsregcmd edlin eventcreate
|
55
|
+
expand extract fdisk fltmc forfiles freedisk ftp getmac gpupdate
|
56
|
+
hostname ifmember inuse ipconfig kill lgpo lodctr logman logoff
|
57
|
+
logtime makecab mapisend mbsacli mem mountvol moveuser msg mshta
|
58
|
+
msiexec msinfo32 mstsc nbtstat net net1 netdom netsh netstat nlsinfo
|
59
|
+
nltest now nslookup ntbackup ntdsutil ntoskrnl ntrights nvspbind
|
60
|
+
pathping perms ping portqry powercfg pngout pnputil printbrm prncnfg
|
61
|
+
prnmngr procdump psexec psfile psgetsid psinfo pskill pslist
|
62
|
+
psloggedon psloglist pspasswd psping psservice psshutdown pssuspend
|
63
|
+
qbasic qgrep qprocess query quser qwinsta rasdial reg reg1 regdump
|
64
|
+
regedt32 regsvr32 regini reset restore rundll32 rmtshare route rpcping
|
65
|
+
run runas scandisk setspn setx sfc share shellrunas shortcut sigcheck
|
66
|
+
sleep slmgr strings subinacl sysmon telnet tftp tlist touch tracerpt
|
67
|
+
tracert tscon tsdiscon tskill tttracer typeperf tzutil undelete
|
68
|
+
unformat verifier vmconnect vssadmin w32tm wbadmin wecutil wevtutil
|
69
|
+
wget where whoami windiff winrm winrs wpeutil wpr wusa wuauclt wscript
|
70
|
+
)
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.attributes
|
74
|
+
@attributes ||= %w(
|
75
|
+
on off disable enableextensions enabledelayedexpansion
|
76
|
+
)
|
77
|
+
end
|
78
|
+
|
79
|
+
state :basic do
|
80
|
+
# Comments
|
81
|
+
rule %r/\brem\b.*$/i, Comment
|
82
|
+
# Empty Labels
|
83
|
+
rule %r/^::.*$/, Comment
|
84
|
+
|
85
|
+
# Labels
|
86
|
+
rule %r/:[a-z]+/i, Name::Label
|
87
|
+
|
88
|
+
rule %r/([a-z]\w*)(\.exe|com|bat|cmd|msi)?/i do |m|
|
89
|
+
if self.class.devices.include? m[1]
|
90
|
+
groups Keyword::Reserved, Error
|
91
|
+
elsif self.class.keywords.include? m[1]
|
92
|
+
groups Keyword, Error
|
93
|
+
elsif self.class.operator_words.include? m[1]
|
94
|
+
groups Operator::Word, Error
|
95
|
+
elsif self.class.builtin_commands.include? m[1]
|
96
|
+
token Name::Builtin
|
97
|
+
elsif self.class.other_commands.include? m[1]
|
98
|
+
token Name::Builtin
|
99
|
+
elsif self.class.attributes.include? m[1]
|
100
|
+
groups Name::Attribute, Error
|
101
|
+
elsif "set".casecmp m[1]
|
102
|
+
groups Keyword::Declaration, Error
|
103
|
+
else
|
104
|
+
token Text
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
rule %r/([\/\-+][a-z]+)\s*/i, Name::Attribute
|
109
|
+
|
110
|
+
mixin :expansions
|
111
|
+
|
112
|
+
rule %r/[<>&|(){}\[\]\-+=;,~?*]/, Operator
|
113
|
+
end
|
114
|
+
|
115
|
+
state :escape do
|
116
|
+
rule %r/\^./m, Str::Escape
|
117
|
+
end
|
118
|
+
|
119
|
+
state :expansions do
|
120
|
+
# Normal and Delayed expansion
|
121
|
+
rule %r/[%!]+([a-z_$@#]+)[%!]+/i, Name::Variable
|
122
|
+
# For Variables
|
123
|
+
rule %r/(\%+~?[a-z]+\d?)/i, Name::Variable::Magic
|
124
|
+
end
|
125
|
+
|
126
|
+
state :double_quotes do
|
127
|
+
mixin :escape
|
128
|
+
rule %r/["]/, Str::Double, :pop!
|
129
|
+
mixin :expansions
|
130
|
+
rule %r/[^\^"%!]+/, Str::Double
|
131
|
+
end
|
132
|
+
|
133
|
+
state :single_quotes do
|
134
|
+
mixin :escape
|
135
|
+
rule %r/[']/, Str::Single, :pop!
|
136
|
+
mixin :expansions
|
137
|
+
rule %r/[^\^'%!]+/, Str::Single
|
138
|
+
end
|
139
|
+
|
140
|
+
state :backtick do
|
141
|
+
mixin :escape
|
142
|
+
rule %r/[`]/, Str::Backtick, :pop!
|
143
|
+
mixin :expansions
|
144
|
+
rule %r/[^\^`%!]+/, Str::Backtick
|
145
|
+
end
|
146
|
+
|
147
|
+
state :data do
|
148
|
+
rule %r/\s+/, Text
|
149
|
+
rule %r/0x[0-9a-f]+/i, Literal::Number::Hex
|
150
|
+
rule %r/[0-9]/, Literal::Number
|
151
|
+
rule %r/["]/, Str::Double, :double_quotes
|
152
|
+
rule %r/[']/, Str::Single, :single_quotes
|
153
|
+
rule %r/[`]/, Str::Backtick, :backtick
|
154
|
+
rule %r/[^\s&|()\[\]{}\^=;!%+\-,"'`~?*]+/, Text
|
155
|
+
mixin :escape
|
156
|
+
end
|
157
|
+
|
158
|
+
state :root do
|
159
|
+
mixin :basic
|
160
|
+
mixin :data
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|