Jump to content
  • 0
SerErris

ATOM cson grammar file

Question

Hi I looked at the language-65asm package, but missed some things.. So I created my own grammar file based on that.

This grammar file now highlights labels and symbols as well as registers and separates the # sign from the following constant/label. 

I attached the ca64.cson file, that you need to put into your language-65asm/grammars folder. Then restart Atom and the new grammar file can be selected. You can also define it for your filetypes as default in your config.json file.

To enable all colours, you need to change the base.less file in your syntax-theme to refer to the new values, as not all of them are honored in all syntax-themes.

I will create a specific Syntax-theme, that does include only the required variants and makes it specific to cc65.

Attached find a example how it could look like:
image.thumb.png.cc897f81e4120e1518356c169415a536.png

ca65.cson

  • Like 2

Share this post


Link to post
Share on other sites

10 answers to this question

Recommended Posts

  • 0

I still have some minor issue with it.

1. My register statement does not work as I would like it to be. I addressed this question in another thread put like to pull it out there, as it is not related to the original topic.

So here we go. If I hit a Register as a parameter to a Assembly call I like to highlight it For instance I like to highlight the X in LDA ADDR,X where LDA should be highlighted as Mnemonic, ADDR should be highlighted as symbol/label , as operator and X as register.

That works great with the current file. 

However if I just put X anywhere on the line (without anything else) it is getting highlighted to.

I got a recommendation from @Ender to try that:

{
  match: '^\\s*\\S+.*\\b([AXY])\\b'
  captures:
    1:
      name: 'keyword.parameter.register.ca65'
}

The result is not as I expected it to be. Now every X or A will be highlighted and the rest of the line will be not highlighted at all.

image.png.3ead0de28f2cfda15658426faf70e6a5.png

I also tried to change the match to this - but same result:

match: '^\\s*\\w+.*\\b([AXY])\\b' ..

Same result.

So obviously I am overwriting the comment rule and this rule has somehow precendence.

I would love to write it this way:

If the line does not start with A or X or Y with any number of Whitespaces in front, then tread a word which consists only of the letter A or X or Y as a register.

So the normal way would be like that:

match :'(?!^\\s*[AXY])\\b[AXY])\\b'

This part is the if not start+any number of whitespaces+[A or X or Y]. If that hits, the rest will be ignored. If that does not hit, the rest will get matched. 

However it does not work. It works if I put X in the first column. But as soon as I put it in second column with a space in front, the not part does not seem to work and it is getting matched as a register.

This is what regex101 has to say about it:

image.thumb.png.59425d7a1d02a3f80977f2e25b156dfa.png

I cannot see what is wrong with it - but it is even there doing the highlighting for the " X" string

Share this post


Link to post
Share on other sites
  • 0

Okay after reading the Regex Tutorial again .. it turns out that it should be this - which works in the JavaScript on regex101:

\b[AXY](?<!^\s*[AXY]|^\s*;.*)\b

Hower  converting it to this

      # Registers
      {
        match:  '\\b[AXY](?<!^\\s*[AXY]|^\\s*;.*)\\b'
        name:   'keyword.parameter.register.ca65'
      }

Leads to nothing parsed anymore (all characters white now). 

I tried a lot of stuff but I cannot get my head around to something working in Atom.. 

This is my test text for regex101:

Quote

 

; ASDT X
lda X
   X
X
X: 

lda 1,X

 

Only the second and the last entry shall be matched.

This does the trick as well (?<!^\s*|;.*)\b[AXY]\b ... it reads: Match  [AXY] if it as single letter and if infront of it there is neither a ";" sign nor only whitespaces. 
 

Works again with JavaScript in regex101 - but not in atom.

Edited by SerErris

Share this post


Link to post
Share on other sites
  • 0

Ah. I didn't think of the situation where there might be a X, Y, or A in the comments.  I think we want to just match the first instance, right? I can't think of a situation where there would be more than one register on a line (besides in comments).  To match only the first instance, we can make the + and * be non-greedy by adding a ? after, like this:

^\\s*\\S+?.*?\\b([AXY])\\b

Share this post


Link to post
Share on other sites
  • 0

There is actually only one valid Register ... if the first part is a mnemonic.

This statment you have given will also show stuff in the comments ..

LDA #50  ; This load A Register.

would highlight the A in front of "A Register". However it is part of the comment and should not be highlighted anyway different, but highlighted as a comment. 

I cannot thing of any way really other the excluding stuff. Cause you need to exclude a match if a ; is in Front of the [AXY] ... Or in other words: try to match it, but if you meet a ";" ignore the rest of the string completely (never match). Not sure if something like that exists.

 

Share this post


Link to post
Share on other sites
  • 0

D'oh, I forgot about that situation too. After some more fiddling I came up with this. It seems like it's probably not the most elegant solution, but it seems to work for me.  Basically it just asserts there's at least one character that's not space, semicolon, or a register followed by anything not a semicolon, followed by a register.

^\\s*[^ ;AXY][^;]*\\b([AXY])\\b

Share this post


Link to post
Share on other sites
  • 0

Don't try to match those registers together -- they're different.

"A" is the accumulator.  Highlight it only where it's the isolated operand of certain mnemonics (inc, dec, shifts, and rotates).

"X" and "Y" (and "S" on the 65816) are index registers.  Highlight them only where they're immediately on the right side of commas (ignoring spaces).

Share this post


Link to post
Share on other sites
  • 0

That sounds like a good approach ... You are right A is very uncommon ... I can specifically look for certain mnemonics and X Y have a leading comma .. however still my problem with the comment apply.

LDA (ADDR),X       ;   This is a ,X comment would still hightlight both X.

I cannot find any statement that is highlighting anything only if it NOT part of a comment.

@Greg King Why should I ignore spaces? The syntax will be still interpreted by the Assembler if there is a space between the comma and the Register. So if it is valid Syntax it should also be highlighted correctly. Haveing whitespaces between comma and the Register is not a big issue.  ... However having a comment (;) anywhere  in front of such a structure is a problem. 

Share this post


Link to post
Share on other sites
  • 0

So this is it ...

Quote

      # Registers
      # A
      {
        match:  '^\\s*((?i:dec|inc|asl|lsr|rol|ror))\\s*(A)\\b'
        captures:
          1:
            name: 'keyword.mnemonic.65c02.65c02-opcodes'
          2:
            name: 'keyword.operator.register.ca65'
      }
      # X and Y
      {
        match: ',\\s*[XY]\\b'
        name: 'keyword.operator.register.ca65'
      }

I solved it by searching for the whole regex ( Line Start;any # of whitespaces;one of the allowed Mnemonics;any # of whitespaces; and then the letter 'A');followed by a word boundary). Setting both the Mnemonic and the Register in a group and then highlighten both individually works. The problem is that you need to highlight both parts otherwise the Mnemonic would be unhighlighted.

I am not sure why the "X and Y" part does not highlight anything in the comments, but I do not care - it works.

Attached you find the new ca65.cson file.

ca65.cson

 1722697257_Screenshot2020-09-27145533.thumb.jpg.3570320607b4a44037621ddbd4b7f4ee.jpg

Share this post


Link to post
Share on other sites
  • 0
23 hours ago, SerErris said:

Why should I ignore spaces?

I meant that you should use "\\s*" to ignore spaces when looking for a match.  (So that it won't matter how many spaces are, or are not, at that spot in matched text.)  It's exactly what you did.

There must be whitespace between a mnemonic and the "A".  Otherwise, it's a macro name (such as "RORA").  Therefore, you should use "\\s+" instead of "\\s*".

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Please review our Terms of Use