BVB Source Codes

rouge Show nasm.rb Source code

Return Download rouge: download nasm.rb Source code - Download rouge Source code - Type:.rb
  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
  204.  
downloadnasm.rb Source code - Download rouge Source code
Related Source Codes/Software:
spring-security-oauth - Support for adding OAuth1(a) and OAuth2 features (... 2017-04-23
Toucan - Fabulous Image Processing in Swift 2017-04-23
CoffeeScriptRedux - 2017-04-23
breakpoint - Really simple media queries in Sa 2017-04-23
libsvm - 2017-04-22
sphinx_rtd_theme - Sphinx theme for readthedocs.org 2017-04-23
BlurEffectForAndroidDesign - Sample to show how to implement blur graphical tri... 2017-04-23
mama2 - Mother plan - all firewood high flame 2017-04-23
JKeyboardPanelSwitch - For resolve the layout conflict when keybord & amp... 2017-04-23
viz.js - A hack to put Graphviz on the web. ... 2017-04-23
browser-diet - 2017-04-30
react-music - Make beats with React! http... 2017-04-30
java-code-styles - IntelliJ IDEA code style settings for Square's Jav... 2017-04-30
swing - A swipeable cards interface. The swipe-left/swipe-... 2017-04-30
qTip2 - qTip2 - Pretty powerful tooltips ... 2017-04-30
jo - JSON output from a shell 2017-04-30
Fluidbox - Replicating and improving the lightbox module seen... 2017-04-30
boto3 - AWS SDK for Python http://a... 2017-04-30
PreloadJS - PreloadJS makes preloading assets & getting ag... 2017-04-29
gotraining - Go Training Class Material : ... 2017-04-29

 Back to top