Commits

Anonymous committed 8ea3089 Merge

Merge

Comments (0)

Files changed (5)

pygments/lexers/_mapping.py

     'CObjdumpLexer': ('pygments.lexers.asm', 'c-objdump', ('c-objdump',), ('*.c-objdump',), ('text/x-c-objdump',)),
     'CSharpAspxLexer': ('pygments.lexers.dotnet', 'aspx-cs', ('aspx-cs',), ('*.aspx', '*.asax', '*.ascx', '*.ashx', '*.asmx', '*.axd'), ()),
     'CSharpLexer': ('pygments.lexers.dotnet', 'C#', ('csharp', 'c#'), ('*.cs',), ('text/x-csharp',)),
+    'Ca65Lexer': ('pygments.lexers.asm', 'ca65', ('ca65',), ('*.s',), ()),
+    'CbmBasicV2Lexer': ('pygments.lexers.other', 'CBM BASIC V2', ('cbmbas',), ('*.bas',), ()),
     'Cfengine3Lexer': ('pygments.lexers.other', 'CFEngine3', ('cfengine3', 'cf3'), ('*.cf',), ()),
     'CheetahHtmlLexer': ('pygments.lexers.templates', 'HTML+Cheetah', ('html+cheetah', 'html+spitfire'), (), ('text/html+cheetah', 'text/html+spitfire')),
     'CheetahJavascriptLexer': ('pygments.lexers.templates', 'JavaScript+Cheetah', ('js+cheetah', 'javascript+cheetah', 'js+spitfire', 'javascript+spitfire'), (), ('application/x-javascript+cheetah', 'text/x-javascript+cheetah', 'text/javascript+cheetah', 'application/x-javascript+spitfire', 'text/x-javascript+spitfire', 'text/javascript+spitfire')),

pygments/lexers/asm.py

      Other, Keyword, Operator
 
 __all__ = ['GasLexer', 'ObjdumpLexer','DObjdumpLexer', 'CppObjdumpLexer',
-           'CObjdumpLexer', 'LlvmLexer', 'NasmLexer']
+           'CObjdumpLexer', 'LlvmLexer', 'NasmLexer', 'Ca65Lexer']
 
 
 class GasLexer(RegexLexer):
             (type, Keyword.Type)
         ],
     }
+
+class Ca65Lexer(RegexLexer):
+    """
+    For ca65 assembler sources.
+    """
+    name = 'ca65'
+    aliases = ['ca65']
+    filenames = ['*.s']
+    
+    flags = re.IGNORECASE
+    
+    tokens = {
+        'root': [
+            (r';.*', Comment.Single),
+            (r'\s+', Text),
+            (r'[\w.@$][\w.@$\d]*:', Name.Label),
+            (r'((ld|st)[axy]|(in|de)[cxy]|asl|lsr|ro[lr]|adc|sbc|cmp|cp[xy]'
+             r'|cl[cvdi]|se[cdi]|jmp|jsr|bne|beq|bpl|bmi|bvc|bvs|bcc|bcs'
+             r'|p[lh][ap]|rt[is]|brk|nop|ta[xy]|t[xy]a|txs|tsx|and|ora|eor'
+             r'|bit)\b', Keyword),
+            (r'\.[a-z0-9_]+', Keyword.Pseudo),
+            (r'[-+~*/^&|!<>=]', Operator),
+            (r'"[^"\n]*.', String),
+            (r"'[^'\n]*.", String.Char),
+            (r'\$[0-9a-f]+|[0-9a-f]+h\b', Number.Hex),
+            (r'\d+|%[01]+', Number.Integer),
+            (r'[#,.:()=]', Punctuation),
+            (r'[\w.@$][\w.@$\d]*', Name),
+        ]
+    }

pygments/lexers/other.py

            'NewspeakLexer', 'GherkinLexer', 'AsymptoteLexer', 'PostScriptLexer',
            'AutohotkeyLexer', 'GoodDataCLLexer', 'MaqlLexer', 'ProtoBufLexer',
            'HybrisLexer', 'AwkLexer', 'Cfengine3Lexer', 'SnobolLexer',
-           'ECLLexer', 'UrbiscriptLexer', 'OpenEdgeLexer', 'BroLexer']
+           'ECLLexer', 'UrbiscriptLexer', 'OpenEdgeLexer', 'BroLexer',
+           'CbmBasicV2Lexer']
 
 
 class ECLLexer(RegexLexer):
             (r'\\', String.Regex)
         ]
     }
+
+class CbmBasicV2Lexer(RegexLexer):
+    """
+    For CBM BASIC V2 sources.
+    """
+    name = 'CBM BASIC V2'
+    aliases = ['cbmbas']
+    filenames = ['*.bas']
+    
+    flags = re.IGNORECASE
+    
+    tokens = {
+        'root': [
+            (r'rem.*\n', Comment.Single),
+            (r'\s+', Text),
+            (r'new|run|end|for|to|next|step|go(to|sub)?|on|return|stop|cont'
+             r'|if|then|input#?|read|wait|load|save|verify|poke|sys|print#?'
+             r'|list|clr|cmd|open|close|get#?', Keyword.Reserved),
+            (r'data|restore|dim|let|def|fn', Keyword.Declaration),
+            (r'tab|spc|sgn|int|abs|usr|fre|pos|sqr|rnd|log|exp|cos|sin|tan|atn'
+             r'|peek|len|val|asc|(str|chr|left|right|mid)\$', Name.Builtin),
+            (r'[-+*/^<>=]', Operator),
+            (r'not|and|or', Operator.Word),
+            (r'"[^"\n]*.', String),
+            (r'\d+|[-+]?\d*\.\d*(e[-+]?\d+)?', Number.Float),
+            (r'[\(\),:;]', Punctuation),
+            (r'\w+[$%]?', Name),
+        ]
+    }

tests/examplefiles/ca65_example.s

+;--------------------------------------
+; Lychrel numbers.
+; 
+; :author: Marc 'BlackJack' Rintsch
+; :date: 2008-03-07
+; :version: 0.1
+; 
+; Prints all `Lychrel numbers`_ between 1 and 100000.
+; 
+; The numbers are stored as array of "digits" in little endian
+; order.  Each digit is a byte with a value between 0 and 9.
+; 
+; Runtime on C64: 00:21:01
+; 
+; .. _Lychrel numbers: http://en.wikipedia.org/wiki/Lychrel_number
+; 
+; .. cl65 -l -tnone -C simple.cfg lychrel.s -o lychrel.prg
+;--------------------------------------
+
+;--------------------------------------
+; External addresses.
+;--------------------------------------
+	chrout	= $ffd2
+
+;--------------------------------------
+; Constants.
+;--------------------------------------
+	TO		= 100000
+	TO_DIGITS	= 10
+	ITERATIONS	= 100
+	MAX_DIGITS	= TO_DIGITS + ITERATIONS
+
+;--------------------------------------
+; Global variables.
+;--------------------------------------
+.zeropage
+; 
+; Length of the currently tested `n` in digits.
+; 
+n_length:
+	.res 1
+; 
+; Length of the number(s) `xa` and `xb` while testing.
+; 
+length:
+	.res 1
+
+.bss
+; 
+; Number to be tested as digits i.e. bytes with values between
+; 0 and 9.  The length is stored in `n_length`.
+; 
+n:
+	.res TO_DIGITS
+; 
+; Space for calculating the reversed and added values.
+; In the `main` code the current number is copied into `xa`
+; and then repeatedly `reverse_add`\ed to itself with the
+; result of that adding stored in `xb`.
+; 
+xa:
+	.res MAX_DIGITS
+xb:
+	.res MAX_DIGITS
+
+;--------------------------------------
+; BASIC header.
+;--------------------------------------
+.code
+	.word 0800h		; Load address.
+	.byte 0
+	.word @line_end
+	.word 2008		; Line number.
+	.byte $9e		; SYS token.
+	.byte "2080 "		; SYS argument.
+	.byte "LYCHREL NUMBERS/BJ"
+@line_end:
+	.byte 0, 0, 0		; Line and program end marker.
+
+;--------------------------------------
+; Main program.
+;--------------------------------------
+.proc main
+
+.zeropage
+; 
+; Three byte counter for `TO` iterations (100000 = $0186a0).
+; 
+i:
+	.res 3
+
+.code
+; 
+; Clear and set `n` and `i` to 1.
+; 
+	lda #0		; n := 0; n := 1; i := 1
+	sta i+1
+	sta i+2
+	ldx #TO_DIGITS
+clear_n:
+	sta n-1,x
+	dex
+	bne clear_n
+	inx
+	stx i
+	stx n
+	stx n_length
+	
+mainloop:
+	jsr is_lychrel
+	bcc no_lychrel
+	jsr print_n
+no_lychrel:
+	jsr increase_n
+	
+	inc i		; INC(i)
+	bne skip
+	inc i+1
+	bne skip
+	inc i+2
+skip:
+	lda i
+	cmp #<TO
+	bne mainloop
+	lda i+1
+	cmp #>TO
+	bne mainloop
+	lda i+2
+	cmp #^TO
+	bne mainloop
+	
+	rts
+.endproc
+
+;--------------------------------------
+; Print `n` and a trailing newline.
+;
+; :in: `n_length`, `n`
+;--------------------------------------
+.proc print_n
+	ldy n_length
+L1:
+	lda n-1,y
+	ora #%110000    ; = '0'
+	jsr chrout
+	dey
+	bne L1
+	
+	lda #13
+	jmp chrout
+.endproc
+
+;--------------------------------------
+; Increase `n` by one.
+; 
+; This procedure expects n[n_length] == 0 in case the number gets
+; one digit longer.
+; 
+; :in: `n`, `n_length`
+; :out: `n`, `n_length`
+;--------------------------------------
+.proc increase_n
+	ldx #0
+L1:
+	inc n,x		; Increase digit.
+	lda n,x
+	cmp #10		; If "carry", store 0 and go to next digit.
+	bne return
+	lda #0
+	sta n,x
+	inx
+	bne L1
+return:
+	cpx n_length	; If "carry" after last digit, increase length.
+	bcc skip
+	inc n_length
+skip:
+	rts
+.endproc
+
+;--------------------------------------
+; Tests if `n` is a Lychrel number.
+; 
+; :in: `n`, `n_length`
+; :out: C is set if yes, cleared otherwise.
+; :uses: `length`, `xa`, `xb`
+;--------------------------------------
+.proc is_lychrel
+.zeropage
+i:
+	.res 1
+
+.code
+	ldx n_length		; xa := n; length := n_length
+	stx length
+L1:
+	lda n-1,x
+	sta xa-1,x
+	dex
+	bne L1
+	
+	lda #ITERATIONS		; i := ITERATIONS
+	sta i
+L2:
+	jsr reverse_add
+	jsr is_palindrome
+	bne no_palindrome
+	clc
+	rts
+no_palindrome:
+	ldx length		; a := b
+L3:
+	lda xb-1,x
+	sta xa-1,x
+	dex
+	bne L3
+	
+	dec i			; Loop body end.
+	bne L2
+	
+	sec
+	rts
+.endproc
+
+;--------------------------------------
+; Add the reverse to `xa` to itself and store the result in `xb`.
+; 
+; :in: `length`, `xa`
+; :out: `length`, `xb`
+;--------------------------------------
+.proc reverse_add
+.code
+	ldx #0
+	ldy length
+	clc
+L1:
+	lda xa,x
+	adc xa-1,y
+	
+	cmp #10
+	bcc no_adjust
+	sbc #10
+no_adjust:
+	sta xb,x
+	
+	dey
+	inx
+	txa		; ``eor`` instead of ``cpx`` to keep the carry flag
+	eor length	; of the addition above.
+	bne L1
+	
+	bcc no_carry
+	lda #1
+	sta xb,x
+	inc length
+no_carry:
+	rts
+.endproc
+
+;--------------------------------------
+; Checks if `xb` is a palindrome.
+; 
+; :in: `length`, `xb`
+; :out: Z flag set if `xb` is a palindrome, cleared otherwise.
+;--------------------------------------
+.proc is_palindrome
+.code
+	ldx #0
+	lda length
+	tay
+	lsr
+	sta L1+1	; Self modifying code!
+L1:
+	cpx #0		; <<< 0 replaced by (`length` / 2).
+	beq return
+	lda xb,x
+	cmp xb-1,y
+	bne return
+	dey
+	inx
+	bne L1
+return:
+	rts
+.endproc

tests/examplefiles/cbmbas_example.bas

+10 rem cbm basic v2 example
+20 rem comment with keywords: for, data
+30 dim a$(20)
+35 rem the typical space efficient form of leaving spaces out:
+40 fort=0to15:poke646,t:print"{revers on}     ";:next
+50 geta$:ifa$=chr$(0):goto40
+55 rem it is legal to omit the closing " on line end
+60 print"{white}":print"bye...
+70 end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.