%YAML 1.2
---
name: c65cm
file_extensions: [c65]
scope: source.c65cm

contexts:
  main:
    - include: comments
    - include: asm-comments
    - include: strings
    - include: preprocessor
    - include: keywords
    - include: assembly-mnemonics
    - include: numbers

  comments:
    - match: //.*$
      scope: comment.line.double-slash.c65cm

  asm-comments:
    - match: ;.*$
      scope: comment.line.semicolon.asm.c65cm

  strings:
    - match: '"'
      push: string

  string:
    - meta_scope: string.quoted.double.c65cm
    - match: \\.
      scope: constant.character.escape.c65cm
    - match: '"'
      pop: true

  preprocessor:
    - match: '^[ \t]*#(INCLUDE|PRAGMA|IFDEF|IFNDEF|IFEND|PRINT|HALT|UNDEF|DEFINE).*$'
      scope: meta.preprocessor.c65cm

  keywords:
    - match: '\b(ADD|AND|AS|ASM|BREAK|BYTE|CALL|CASE|CONST|DEC|DECREMENT|DEFAULT|DO|ELSE|ENDASM|ENDIF|ENDSCRIPT|ENDSWITCH|EXIT|FEND|FOR|FUNC|GOSUB|GOTO|IF|INC|INCREMENT|LABEL|LET|LIBRARY|MACRO|NEXT|OR|ORIGIN|PASSING|PEEK|PEEKW|POINTER|POKE|POKEW|SCRIPT|STEP|SUBEND|SUBTRACT|SWITCH|THEN|TO|WHILE|WITH|WEND|WORD|XOR)\b'
      scope: keyword.control.c65cm
    - match: '\b(in|out|io)\b(?=\s*:)'
      scope: storage.modifier.parameter.c65cm
    - match: '\b(ACC|XREG|YREG)\b'
      scope: constant.language.register.c65cm

  assembly-mnemonics:
    - match: '\b(adc|and|asl|bcc|bcs|beq|bit|bmi|bne|bpl|brk|bvc|bvs|clc|cld|cli|clv|cmp|cpx|cpy|dec|dex|dey|eor|inc|inx|iny|jmp|jsr|lda|ldx|ldy|lsr|nop|ora|pha|php|pla|plp|rol|ror|rti|rts|sbc|sec|sed|sei|sta|stx|sty|tax|tay|tsx|txa|txs|tya)\b'
      scope: keyword.other.opcode.6502.c65cm

  numbers:
    - match: '\b(([0-9]+)|([0-9]+\.[0-9]+([Ee][-]?[0-9]+)?))\b'
      scope: constant.numeric.decimal.c65cm
    - match: '\$[0-9a-fA-F]+'
      scope: constant.numeric.hexadecimal.c65cm

