rouge 1.10.1 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rouge/cli.rb +1 -1
  3. data/lib/rouge/demos/actionscript +4 -0
  4. data/lib/rouge/demos/apiblueprint +33 -0
  5. data/lib/rouge/demos/biml +38 -0
  6. data/lib/rouge/demos/ceylon +7 -0
  7. data/lib/rouge/demos/cmake +7 -0
  8. data/lib/rouge/demos/coq +11 -0
  9. data/lib/rouge/demos/d +16 -0
  10. data/lib/rouge/demos/eiffel +30 -0
  11. data/lib/rouge/demos/fortran +22 -0
  12. data/lib/rouge/demos/gradle +10 -0
  13. data/lib/rouge/demos/jinja +9 -0
  14. data/lib/rouge/demos/jsonnet +28 -0
  15. data/lib/rouge/demos/julia +11 -0
  16. data/lib/rouge/demos/nasm +26 -0
  17. data/lib/rouge/demos/objective_c +4 -0
  18. data/lib/rouge/demos/protobuf +5 -0
  19. data/lib/rouge/demos/shell_session +10 -0
  20. data/lib/rouge/demos/smarty +12 -0
  21. data/lib/rouge/demos/tap +5 -0
  22. data/lib/rouge/demos/twig +9 -0
  23. data/lib/rouge/demos/typescript +1 -0
  24. data/lib/rouge/demos/verilog +27 -0
  25. data/lib/rouge/demos/viml +14 -5
  26. data/lib/rouge/formatters/html_wrapper.rb +11 -0
  27. data/lib/rouge/formatters/terminal256.rb +1 -1
  28. data/lib/rouge/lexer.rb +4 -2
  29. data/lib/rouge/lexers/actionscript.rb +195 -0
  30. data/lib/rouge/lexers/apache.rb +23 -20
  31. data/lib/rouge/lexers/apache/keywords.yml +721 -410
  32. data/lib/rouge/lexers/apiblueprint.rb +51 -0
  33. data/lib/rouge/lexers/biml.rb +41 -0
  34. data/lib/rouge/lexers/c.rb +7 -2
  35. data/lib/rouge/lexers/ceylon.rb +123 -0
  36. data/lib/rouge/lexers/clojure.rb +1 -1
  37. data/lib/rouge/lexers/cmake.rb +206 -0
  38. data/lib/rouge/lexers/coffeescript.rb +1 -1
  39. data/lib/rouge/lexers/coq.rb +187 -0
  40. data/lib/rouge/lexers/cpp.rb +12 -1
  41. data/lib/rouge/lexers/csharp.rb +12 -5
  42. data/lib/rouge/lexers/css.rb +2 -0
  43. data/lib/rouge/lexers/d.rb +176 -0
  44. data/lib/rouge/lexers/diff.rb +9 -9
  45. data/lib/rouge/lexers/eiffel.rb +65 -0
  46. data/lib/rouge/lexers/fortran.rb +142 -0
  47. data/lib/rouge/lexers/gradle.rb +37 -0
  48. data/lib/rouge/lexers/groovy.rb +2 -2
  49. data/lib/rouge/lexers/ini.rb +2 -2
  50. data/lib/rouge/lexers/java.rb +11 -8
  51. data/lib/rouge/lexers/javascript.rb +2 -1
  52. data/lib/rouge/lexers/jinja.rb +137 -0
  53. data/lib/rouge/lexers/jsonnet.rb +151 -0
  54. data/lib/rouge/lexers/julia.rb +172 -0
  55. data/lib/rouge/lexers/markdown.rb +1 -0
  56. data/lib/rouge/lexers/nasm.rb +203 -0
  57. data/lib/rouge/lexers/objective_c.rb +11 -0
  58. data/lib/rouge/lexers/php.rb +1 -1
  59. data/lib/rouge/lexers/powershell.rb +1 -1
  60. data/lib/rouge/lexers/protobuf.rb +70 -0
  61. data/lib/rouge/lexers/python.rb +23 -0
  62. data/lib/rouge/lexers/r.rb +53 -20
  63. data/lib/rouge/lexers/ruby.rb +4 -4
  64. data/lib/rouge/lexers/rust.rb +2 -2
  65. data/lib/rouge/lexers/shell_session.rb +29 -0
  66. data/lib/rouge/lexers/smarty.rb +91 -0
  67. data/lib/rouge/lexers/sql.rb +1 -1
  68. data/lib/rouge/lexers/swift.rb +20 -5
  69. data/lib/rouge/lexers/tap.rb +91 -0
  70. data/lib/rouge/lexers/twig.rb +37 -0
  71. data/lib/rouge/lexers/typescript.rb +46 -0
  72. data/lib/rouge/lexers/verilog.rb +164 -0
  73. data/lib/rouge/regex_lexer.rb +1 -1
  74. data/lib/rouge/version.rb +1 -1
  75. data/rouge.gemspec +1 -1
  76. metadata +47 -6
  77. data/lib/rouge/formatters/html_inline.rb +0 -20
  78. data/lib/rouge/formatters/html_linewise.rb +0 -31
@@ -0,0 +1,151 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class Jsonnet < RegexLexer
6
+ title 'Jsonnet'
7
+ desc 'An elegant, formally-specified config language for JSON'
8
+ tag 'jsonnet'
9
+ filenames '*.jsonnet'
10
+ mimetypes 'text/x-jsonnet'
11
+
12
+ def self.keywords
13
+ @keywords ||= Set.new %w(
14
+ self super local for in if then else import importstr error
15
+ tailstrict assert
16
+ )
17
+ end
18
+
19
+ def self.declarations
20
+ @declarations ||= Set.new %w(
21
+ function
22
+ )
23
+ end
24
+
25
+ def self.constants
26
+ @constants ||= Set.new %w(
27
+ null true false
28
+ )
29
+ end
30
+
31
+ def self.builtins
32
+ @builtins ||= Set.new %w(
33
+ acos
34
+ asin
35
+ atan
36
+ ceil
37
+ char
38
+ codepoint
39
+ cos
40
+ exp
41
+ exponent
42
+ filter
43
+ floor
44
+ force
45
+ length
46
+ log
47
+ makeArray
48
+ mantissa
49
+ objectFields
50
+ objectHas
51
+ pow
52
+ sin
53
+ sqrt
54
+ tan
55
+ thisFile
56
+ type
57
+ abs
58
+ assertEqual
59
+ escapeStringBash
60
+ escapeStringDollars
61
+ escapeStringJson
62
+ escapeStringPython
63
+ filterMap
64
+ flattenArrays
65
+ foldl
66
+ foldr
67
+ format
68
+ join
69
+ lines
70
+ manifestIni
71
+ manifestPython
72
+ manifestPythonVars
73
+ map
74
+ max
75
+ min
76
+ mod
77
+ range
78
+ set
79
+ setDiff
80
+ setInter
81
+ setMember
82
+ setUnion
83
+ sort
84
+ split
85
+ stringChars
86
+ substr
87
+ toString
88
+ uniq
89
+ )
90
+ end
91
+
92
+ identifier = /[a-zA-Z_][a-zA-Z0-9_]*/
93
+
94
+ state :root do
95
+ rule /\s+/, Text
96
+ rule %r(//.*?$), Comment::Single
97
+ rule %r(#.*?$), Comment::Single
98
+ rule %r(/\*.*?\*/)m, Comment::Multiline
99
+
100
+ rule /-?(?:0|[1-9]\d*)\.\d+(?:e[+-]\d+)?/i, Num::Float
101
+ rule /-?(?:0|[1-9]\d*)(?:e[+-]\d+)?/i, Num::Integer
102
+
103
+ rule /[{}:\.,;+\[\]=%\(\)]/, Punctuation
104
+
105
+ rule /"/, Str, :string_double
106
+ rule /'/, Str, :string_single
107
+ rule /\|\|\|/, Str, :string_block
108
+
109
+ rule /\$/, Keyword
110
+
111
+ rule identifier do |m|
112
+ if self.class.keywords.include? m[0]
113
+ token Keyword
114
+ elsif self.class.declarations.include? m[0]
115
+ token Keyword::Declaration
116
+ elsif self.class.constants.include? m[0]
117
+ token Keyword::Constant
118
+ elsif self.class.builtins.include? m[0]
119
+ token Name::Builtin
120
+ else
121
+ token Name::Other
122
+ end
123
+ end
124
+ end
125
+
126
+ state :string do
127
+ rule /\\([\\\/bfnrt]|(u[0-9a-fA-F]{4}))/, Str::Escape
128
+ end
129
+
130
+ state :string_double do
131
+ mixin :string
132
+ rule /\\"/, Str::Escape
133
+ rule /"/, Str, :pop!
134
+ rule /[^\\"]+/, Str
135
+ end
136
+
137
+ state :string_single do
138
+ mixin :string
139
+ rule /\\'/, Str::Escape
140
+ rule /'/, Str, :pop!
141
+ rule /[^\\']+/, Str
142
+ end
143
+
144
+ state :string_block do
145
+ mixin :string
146
+ rule /\|\|\|/, Str, :pop!
147
+ rule /.*/, Str
148
+ end
149
+ end
150
+ end
151
+ end
@@ -0,0 +1,172 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class Julia < RegexLexer
6
+ title "Julia"
7
+ desc "The Julia programming language"
8
+ tag 'julia'
9
+ aliases 'jl'
10
+ filenames '*.jl'
11
+ mimetypes 'text/x-julia', 'application/x-julia'
12
+
13
+ def self.analyze_text(text)
14
+ 1 if text.shebang? 'julia'
15
+ end
16
+
17
+ BUILTINS = /\b(?:
18
+ applicable | assert | convert
19
+ | dlopen | dlsym | edit
20
+ | eps | error | exit
21
+ | finalizer | hash | im
22
+ | Inf | invoke | is
23
+ | isa | isequal | load
24
+ | method_exists | Nan | new
25
+ | ntuple | pi | promote
26
+ | promote_type | realmax | realmin
27
+ | sizeof | subtype | system
28
+ | throw | tuple | typemax
29
+ | typemin | typeof | uid
30
+ | whos
31
+ )\b/x
32
+
33
+ KEYWORDS = /\b(?:
34
+ function | return | module | import | export
35
+ | if | else | elseif | end | for
36
+ | in | while | try | catch | super
37
+ | const
38
+ )\b/x
39
+
40
+ TYPES = /\b(?:
41
+ Int | UInt | Int8
42
+ | UInt8 | Int16 | UInt16
43
+ | Int32 | UInt32 | Int64
44
+ | UInt64 | Int128 | UInt128
45
+ | Float16 | Float32 | Float64
46
+ | Bool | Inf | Inf16
47
+ | Inf32 | NaN | NaN16
48
+ | NaN32 | BigInt | BigFloat
49
+ | Char | ASCIIString | UTF8String
50
+ | UTF16String | UTF32String | AbstractString
51
+ | WString | String | Regex
52
+ | RegexMatch | Complex64 | Complex128
53
+ | Any | Nothing | None
54
+ )\b/x
55
+
56
+ OPERATORS = / \+ | = | - | \* | \/
57
+ | \\ | & | \| | \$ | ~
58
+ | \^ | % | ! | >>> | >>
59
+ | << | && | \|\| | \+= | -=
60
+ | \*= | \/= | \\= | ÷= | %=
61
+ | \^= | &= | \|= | \$= | >>>=
62
+ | >>= | <<= | == | != | ≠
63
+ | <= | ≤ | >= | ≥ | \.
64
+ | :: | <: | -> | \? | \.\*
65
+ | \.\^ | \.\\ | \.\/ | \\ | <
66
+ | >
67
+ /x
68
+
69
+ PUNCTUATION = / [ \[ \] { } : \( \) , ; @ ] /x
70
+
71
+
72
+ state :root do
73
+ rule /\n/, Text
74
+ rule /[^\S\n]+/, Text
75
+ rule /#=/, Comment::Multiline, :blockcomment
76
+ rule /#.*$/, Comment
77
+ rule OPERATORS, Operator
78
+ rule /\\\n/, Text
79
+ rule /\\/, Text
80
+
81
+
82
+ # functions
83
+ rule /(function)((?:\s|\\\s)+)/ do
84
+ groups Keyword, Name::Function
85
+ push :funcname
86
+ end
87
+
88
+ # types
89
+ rule /(type|typealias|abstract)((?:\s|\\\s)+)/ do
90
+ groups Keyword, Name::Class
91
+ push :typename
92
+ end
93
+ rule TYPES, Keyword::Type
94
+
95
+ # keywords
96
+ rule /(local|global|const)\b/, Keyword::Declaration
97
+ rule KEYWORDS, Keyword
98
+
99
+ rule BUILTINS, Name::Builtin
100
+
101
+ # backticks
102
+ rule /`.*?`/, Literal::String::Backtick
103
+
104
+ # chars
105
+ rule /'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,3}|\\u[a-fA-F0-9]{1,4}|\\U[a-fA-F0-9]{1,6}|[^\\\'\n])'/, Literal::String::Char
106
+
107
+ # try to match trailing transpose
108
+ rule /(?<=[.\w)\]])\'+/, Operator
109
+
110
+ # strings
111
+ rule /(?:[IL])"/, Literal::String, :string
112
+ rule /[E]?"/, Literal::String, :string
113
+
114
+ # names
115
+ rule /@[\w.]+/, Name::Decorator
116
+ rule /(?:[a-zA-Z_\u00A1-\uffff]|[\u1000-\u10ff])(?:[a-zA-Z_0-9\u00A1-\uffff]|[\u1000-\u10ff])*!*/, Name
117
+
118
+ rule PUNCTUATION, Other
119
+
120
+ # numbers
121
+ rule /(\d+(_\d+)+\.\d*|\d*\.\d+(_\d+)+)([eEf][+-]?[0-9]+)?/, Literal::Number::Float
122
+ rule /(\d+\.\d*|\d*\.\d+)([eEf][+-]?[0-9]+)?/, Literal::Number::Float
123
+ rule /\d+(_\d+)+[eEf][+-]?[0-9]+/, Literal::Number::Float
124
+ rule /\d+[eEf][+-]?[0-9]+/, Literal::Number::Float
125
+ rule /0b[01]+(_[01]+)+/, Literal::Number::Bin
126
+ rule /0b[01]+/, Literal::Number::Bin
127
+ rule /0o[0-7]+(_[0-7]+)+/, Literal::Number::Oct
128
+ rule /0o[0-7]+/, Literal::Number::Oct
129
+ rule /0x[a-fA-F0-9]+(_[a-fA-F0-9]+)+/, Literal::Number::Hex
130
+ rule /0x[a-fA-F0-9]+/, Literal::Number::Hex
131
+ rule /\d+(_\d+)+/, Literal::Number::Integer
132
+ rule /\d+/, Literal::Number::Integer
133
+ end
134
+
135
+
136
+ state :funcname do
137
+ rule /[a-zA-Z_]\w*/, Name::Function, :pop!
138
+ rule /\([^\s\w{]{1,2}\)/, Operator, :pop!
139
+ rule /[^\s\w{]{1,2}/, Operator, :pop!
140
+ end
141
+
142
+ state :typename do
143
+ rule /[a-zA-Z_]\w*/, Name::Class, :pop!
144
+ end
145
+
146
+ state :stringescape do
147
+ rule /\\([\\abfnrtv"\']|\n|N\{.*?\}|u[a-fA-F0-9]{4}|U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})/,
148
+ Literal::String::Escape
149
+ end
150
+
151
+ state :blockcomment do
152
+ rule /[^=#]/, Comment::Multiline
153
+ rule /#=/, Comment::Multiline, :blockcomment
154
+ rule /\=#/, Comment::Multiline, :pop!
155
+ rule /[=#]/, Comment::Multiline
156
+ end
157
+
158
+ state :string do
159
+ mixin :stringescape
160
+
161
+ rule /"/, Literal::String, :pop!
162
+ rule /\\\\|\\"|\\\n/, Literal::String::Escape # included here for raw strings
163
+ rule /\$(\(\w+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?/, Literal::String::Interpol
164
+ rule /[^\\"$]+/, Literal::String
165
+ # quotes, dollar signs, and backslashes must be parsed one at a time
166
+ rule /["\\]/, Literal::String
167
+ # unhandled string formatting sign
168
+ rule /\$/, Literal::String
169
+ end
170
+ end
171
+ end
172
+ end
@@ -35,6 +35,7 @@ module Rouge
35
35
  rule /(\n[ \t]*)(```|~~~)(.*?)(\n.*?)(\2)/m do |m|
36
36
  sublexer = Lexer.find_fancy(m[3].strip, m[4])
37
37
  sublexer ||= PlainText.new(:token => Str::Backtick)
38
+ sublexer.reset!
38
39
 
39
40
  token Text, m[1]
40
41
  token Punctuation, m[2]
@@ -0,0 +1,203 @@
1
+ # -*- coding: utf-8 -*- #
2
+
3
+ module Rouge
4
+ module Lexers
5
+ class Nasm < RegexLexer
6
+ tag 'nasm'
7
+ filenames '*.asm'
8
+ #mimetypes 'text/x-chdr', 'text/x-csrc'
9
+
10
+ title "Nasm"
11
+ desc "Netwide Assembler"
12
+
13
+ ws = %r((?:\s|;.*?\n/)+)
14
+ id = /[a-zA-Z_][a-zA-Z0-9_]*/
15
+
16
+ #todo: pull more instructions from: http://www.nasm.us/doc/nasmdocb.html
17
+ #so far, we have sections 1.1 and 1.2
18
+
19
+ def self.keywords
20
+ @keywords ||= Set.new %w(
21
+ aaa aad aam aas adc add and arpl bb0_reset bb1_reset bound bsf bsr bswap bt btc btr bts
22
+ call cbw cdq cdqe clc cld cli clts cmc cmp cmpsb cmpsd cmpsq cmpsw cmpxchg
23
+ cmpxchg16b cmpxchg486 cmpxchg8b cpuid cpu_read cpu_write cqo cwd cwde daa das dec div
24
+ dmint emms enter equ f2xm1 fabs fadd faddp fbld fbstp fchs fclex fcmovb fcmovbe fcmove
25
+ fcmovnb fcmovnbe fcmovne fcmovnu fcmovu fcom fcomi fcomip fcomp fcompp fcos fdecstp
26
+ fdisi fdiv fdivp fdivr fdivrp femms feni ffree ffreep fiadd ficom ficomp fidiv fidivr
27
+ fild fimul fincstp finit fist fistp fisttp fisub fisubr fld fld1 fldcw fldenv fldl2e
28
+ fldl2t fldlg2 fldln2 fldpi fldz fmul fmulp fnclex fndisi fneni fninit fnop fnsave fnstcw
29
+ fnstenv fnstsw fpatan fprem fprem1 fptan frndint frstor fsave fscale fsetpm fsin fsincos
30
+ fsqrt fst fstcw fstenv fstp fstsw fsub fsubp fsubr fsubrp ftst fucom fucomi fucomip
31
+ fucomp fucompp fwait fxam fxch fxtract fyl2x fyl2xp1 hlt ibts icebp idiv imul in inc
32
+ incbin insb insd insw int int01 int03 int1 int3 into invd invlpg invlpga invpcid iret
33
+ iretd iretq iretw jcxz jecxz jmp jmpe jrcxz lahf lar lds lea leave les lfence lfs
34
+ lgdt lgs lidt lldt lmsw loadall loadall286 lodsb lodsd lodsq lodsw loop loope loopne
35
+ loopnz loopz lsl lss ltr mfence monitor monitorx mov movd movq movsb movsd movsq movsw
36
+ movsx movsxd movzx mul mwait mwaitx neg nop not or out outsb outsd outsw packssdw
37
+ packsswb packuswb paddb paddd paddsb paddsiw paddsw paddusb paddusw paddw pand pandn
38
+ pause paveb pavgusb pcmpeqb pcmpeqd pcmpeqw pcmpgtb pcmpgtd pcmpgtw pdistib pf2id pfacc
39
+ pfadd pfcmpeq pfcmpge pfcmpgt pfmax pfmin pfmul pfrcp pfrcpit1 pfrcpit2 pfrsqit1 pfrsqrt
40
+ pfsub pfsubr pi2fd pmachriw pmaddwd pmagw pmulhriw pmulhrwa pmulhrwc pmulhw pmullw
41
+ pmvgezb pmvlzb pmvnzb pmvzb pop popa popad popaw popf popfd popfq popfw por prefetch
42
+ prefetchw pslld psllq psllw psrad psraw psrld psrlq psrlw psubb psubd psubsb psubsiw
43
+ psubsw psubusb psubusw psubw punpckhbw punpckhdq punpckhwd punpcklbw punpckldq punpcklwd
44
+ push pusha pushad pushaw pushf pushfd pushfq pushfw pxor rcl rcr rdm rdmsr rdpmc rdshr
45
+ rdtsc rdtscp ret retf retn rol ror rsdc rsldt rsm rsts sahf sal salc sar sbb scasb scasd
46
+ scasq scasw sfence sgdt shl shld shr shrd sidt skinit sldt smi smint smintold smsw
47
+ stc std sti stosb stosd stosq stosw str sub svdc svldt svts swapgs syscall sysenter
48
+ sysexit sysret test ud0 ud1 ud2 ud2a ud2b umov verr verw wbinvd wrmsr wrshr xadd xbts
49
+ xchg xlat xlatb xor
50
+
51
+ cmova cmovae cmovb cmovbe cmovc cmove cmovg cmovge cmovl cmovle cmovna cmovnae cmovnb cmovnbe cmovnc cmovne cmovng cmovnge cmovnl cmovnle cmovno cmovnp cmovns cmovnz cmovo cmovp cmovpe cmovpo cmovs cmovz
52
+
53
+ ja jae jb jbe jc jcxz jecxz je jg jge jl jle jna jnae jnb jnbe jnc jne jng jnge jnl jnle jno jnp jns jnz jo jp jpe jpo js jz
54
+
55
+ seta setae setb setbe setc sete setg setge setl setle setna setnae setnb setnbe setnc setne setng setnge setnl setnle setno setnp setns setnz seto setp setpe setpo sets setz
56
+
57
+ AAA AAD AAM AAS ADC ADD AND ARPL BB0_RESET BB1_RESET BOUND BSF BSR BSWAP BT BTC BTR BTS
58
+ CALL CBW CDQ CDQE CLC CLD CLI CLTS CMC CMP CMPSB CMPSD CMPSQ CMPSW CMPXCHG
59
+ CMPXCHG16B CMPXCHG486 CMPXCHG8B CPUID CPU_READ CPU_WRITE CQO CWD CWDE DAA DAS DEC DIV
60
+ DMINT EMMS ENTER EQU F2XM1 FABS FADD FADDP FBLD FBSTP FCHS FCLEX FCMOVB FCMOVBE FCMOVE
61
+ FCMOVNB FCMOVNBE FCMOVNE FCMOVNU FCMOVU FCOM FCOMI FCOMIP FCOMP FCOMPP FCOS FDECSTP
62
+ FDISI FDIV FDIVP FDIVR FDIVRP FEMMS FENI FFREE FFREEP FIADD FICOM FICOMP FIDIV FIDIVR
63
+ FILD FIMUL FINCSTP FINIT FIST FISTP FISTTP FISUB FISUBR FLD FLD1 FLDCW FLDENV FLDL2E
64
+ FLDL2T FLDLG2 FLDLN2 FLDPI FLDZ FMUL FMULP FNCLEX FNDISI FNENI FNINIT FNOP FNSAVE FNSTCW
65
+ FNSTENV FNSTSW FPATAN FPREM FPREM1 FPTAN FRNDINT FRSTOR FSAVE FSCALE FSETPM FSIN FSINCOS
66
+ FSQRT FST FSTCW FSTENV FSTP FSTSW FSUB FSUBP FSUBR FSUBRP FTST FUCOM FUCOMI FUCOMIP
67
+ FUCOMP FUCOMPP FWAIT FXAM FXCH FXTRACT FYL2X FYL2XP1 HLT IBTS ICEBP IDIV IMUL IN INC
68
+ INCBIN INSB INSD INSW INT INT01 INT03 INT1 INT3 INTO INVD INVLPG INVLPGA INVPCID IRET
69
+ IRETD IRETQ IRETW JCXZ JECXZ JMP JMPE JRCXZ LAHF LAR LDS LEA LEAVE LES LFENCE LFS
70
+ LGDT LGS LIDT LLDT LMSW LOADALL LOADALL286 LODSB LODSD LODSQ LODSW LOOP LOOPE LOOPNE
71
+ LOOPNZ LOOPZ LSL LSS LTR MFENCE MONITOR MONITORX MOV MOVD MOVQ MOVSB MOVSD MOVSQ MOVSW
72
+ MOVSX MOVSXD MOVZX MUL MWAIT MWAITX NEG NOP NOT OR OUT OUTSB OUTSD OUTSW PACKSSDW
73
+ PACKSSWB PACKUSWB PADDB PADDD PADDSB PADDSIW PADDSW PADDUSB PADDUSW PADDW PAND PANDN
74
+ PAUSE PAVEB PAVGUSB PCMPEQB PCMPEQD PCMPEQW PCMPGTB PCMPGTD PCMPGTW PDISTIB PF2ID PFACC
75
+ PFADD PFCMPEQ PFCMPGE PFCMPGT PFMAX PFMIN PFMUL PFRCP PFRCPIT1 PFRCPIT2 PFRSQIT1 PFRSQRT
76
+ PFSUB PFSUBR PI2FD PMACHRIW PMADDWD PMAGW PMULHRIW PMULHRWA PMULHRWC PMULHW PMULLW
77
+ PMVGEZB PMVLZB PMVNZB PMVZB POP POPA POPAD POPAW POPF POPFD POPFQ POPFW POR PREFETCH
78
+ PREFETCHW PSLLD PSLLQ PSLLW PSRAD PSRAW PSRLD PSRLQ PSRLW PSUBB PSUBD PSUBSB PSUBSIW
79
+ PSUBSW PSUBUSB PSUBUSW PSUBW PUNPCKHBW PUNPCKHDQ PUNPCKHWD PUNPCKLBW PUNPCKLDQ PUNPCKLWD
80
+ PUSH PUSHA PUSHAD PUSHAW PUSHF PUSHFD PUSHFQ PUSHFW PXOR RCL RCR RDM RDMSR RDPMC RDSHR
81
+ RDTSC RDTSCP RET RETF RETN ROL ROR RSDC RSLDT RSM RSTS SAHF SAL SALC SAR SBB SCASB SCASD
82
+ SCASQ SCASW SFENCE SGDT SHL SHLD SHR SHRD SIDT SKINIT SLDT SMI SMINT SMINTOLD SMSW
83
+ STC STD STI STOSB STOSD STOSQ STOSW STR SUB SVDC SVLDT SVTS SWAPGS SYSCALL SYSENTER
84
+ SYSEXIT SYSRET TEST UD0 UD1 UD2 UD2A UD2B UMOV VERR VERW WBINVD WRMSR WRSHR XADD XBTS
85
+ XCHG XLAT XLATB XOR
86
+
87
+ CMOVA CMOVAE CMOVB CMOVBE CMOVC CMOVE CMOVG CMOVGE CMOVL CMOVLE CMOVNA CMOVNAE CMOVNB CMOVNBE CMOVNC CMOVNE CMOVNG CMOVNGE CMOVNL CMOVNLE CMOVNO CMOVNP CMOVNS CMOVNZ CMOVO CMOVP CMOVPE CMOVPO CMOVS CMOVZ
88
+
89
+ JA JAE JB JBE JC JCXZ JECXZ JE JG JGE JL JLE JNA JNAE JNB JNBE JNC JNE JNG JNGE JNL JNLE JNO JNP JNS JNZ JO JP JPE JPO JS JZ
90
+
91
+ SETA SETAE SETB SETBE SETC SETE SETG SETGE SETL SETLE SETNA SETNAE SETNB SETNBE SETNC SETNE SETNG SETNGE SETNL SETNLE SETNO SETNP SETNS SETNZ SETO SETP SETPE SETPO SETS SETZ
92
+ )
93
+ end
94
+
95
+ def self.keywords_type
96
+ @keywords_type ||= Set.new %w(
97
+ DB DW DD DQ DT DO DY DZ RESB RESW RESD RESQ REST RESO RESY RESZ
98
+ db dq dd dq dt do dy dz resb resw resd resq rest reso resy resz
99
+ )
100
+ end
101
+
102
+ def self.reserved
103
+ @reserved ||= Set.new %w(
104
+ global extern macro endmacro assign rep endrep section
105
+ GLOBAL EXTERN MACRO ENDMACRO ASSIGN REP ENDREP SECTION
106
+ )
107
+ end
108
+
109
+ # high priority for filename matches
110
+ def self.analyze_text(*)
111
+ 0.3
112
+ end
113
+
114
+ def self.builtins
115
+ @builtins ||= []
116
+ end
117
+
118
+ start { push :expr_bol }
119
+
120
+ state :expr_bol do
121
+ mixin :inline_whitespace
122
+ rule(//) { pop! }
123
+ end
124
+
125
+ state :inline_whitespace do
126
+ rule /[ \t\r]+/, Text
127
+ end
128
+
129
+ state :whitespace do
130
+ rule /\n+/m, Text, :expr_bol
131
+ rule %r(//(\\.|.)*?\n), Comment::Single, :expr_bol
132
+ mixin :inline_whitespace
133
+ end
134
+
135
+ state :expr_whitespace do
136
+ rule /\n+/m, Text, :expr_bol
137
+ mixin :whitespace
138
+ end
139
+
140
+ state :root do
141
+ mixin :expr_whitespace
142
+ rule (//) { push :statement }
143
+ rule /^%[a-zA-Z0-9]+/, Comment::Preproc, :statement
144
+
145
+ rule(
146
+ %r(&=|[*]=|/=|\\=|\^=|\+=|-=|<<=|>>=|<<|>>|:=|<=|>=|<>|[-&*/\\^+=<>.]),
147
+ Operator
148
+ )
149
+ rule /;.*/, Comment, :statement
150
+ rule /^[a-zA-Z]+[a-zA-Z0-9]*:/, Name::Function
151
+ rule /;.*/, Comment
152
+ end
153
+
154
+ state :statement do
155
+ mixin :expr_whitespace
156
+ mixin :statements
157
+ rule /;.*/, Comment
158
+ rule /^%[a-zA-Z0-9]+/, Comment::Preproc
159
+ rule /[a-zA-Z]+%[0-9]+:/, Name::Function
160
+ end
161
+
162
+ state :statements do
163
+ mixin :whitespace
164
+ rule /L?"/, Str, :string
165
+ rule /[a-zA-Z]+%[0-9]+:/, Name::Function #labels/subroutines/functions
166
+ rule %r(L?'(\\.|\\[0-7]{1,3}|\\x[a-f0-9]{1,2}|[^\\'\n])')i, Str::Char
167
+ rule /0x[0-9a-f]+[lu]*/i, Num::Hex
168
+ rule /\d+[lu]*/i, Num::Integer
169
+ rule %r(\*/), Error
170
+ rule %r([~&*+=\|?:<>/-]), Operator
171
+ rule /[(),.]/, Punctuation
172
+ rule /\[[a-zA-Z0-9]*\]/, Punctuation
173
+ rule /%[0-9]+/, Keyword::Reserved
174
+ rule /[a-zA-Z]+%[0-9]+/, Name::Function #labels/subroutines/functions
175
+
176
+ #rule /(?<!\.)#{id}/ do |m|
177
+ rule id do |m|
178
+ name = m[0]
179
+
180
+ if self.class.keywords.include? name
181
+ token Keyword
182
+ elsif self.class.keywords_type.include? name
183
+ token Keyword::Type
184
+ elsif self.class.reserved.include? name
185
+ token Keyword::Reserved
186
+ elsif self.class.builtins.include? name
187
+ token Name::Builtin
188
+ else
189
+ token Name
190
+ end
191
+ end
192
+ end
193
+
194
+ state :string do
195
+ rule /"/, Str, :pop!
196
+ rule /\\([\\abfnrtv"']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})/, Str::Escape
197
+ rule /[^\\"\n]+/, Str
198
+ rule /\\\n/, Str
199
+ rule /\\/, Str # stray backslash
200
+ end
201
+ end
202
+ end
203
+ end