Smash code syntax highlighting

Smash code syntax highlighting

youngr54

    Jul 13, 2005#1

    I'm trying to create a custom syntax highlighter for Smash code, a language for text-based adventure games:
    http://www.rinkworks.com/smash/tutorial/

    here is a simple block of code:

    Code: Select all

    c coins = 0
    	coins = r:10
    	p You have no money, you are given {coins} coins
    C 	
    	p You already have money.
    p You look at the coins, they have the letter c embossed into them	
    g outsideBank
    
    Statements in Smash code are represented by single letters.
    In the example above "c" represents an "if" statement, "C" is and "else" statement, "r:#" generates a random number, "p" prints text to the screen and "g" sends the player to a different location in the game.

    blocks of code are determined by tabs

    Here are some of the things I'd like to do with syntax highlighting:
    I'd like to highlight all the command codes ("c","C","p" etc. there are about 32")
    I'd like to have automatic indenting of "if" blocks
    Finally like to have code folding for "if" blocks and nested "if" blocks

    I've tried these things but I have run into several problems.
    Firstly, when I specify the commands that need to be highlighted ("c","C","p" etc) it works fine, except that letters in print statements also get highlited, for example, the second last lind of code in my example above, "c" in "they have the letter c embossed into them" is highlighted when it shouldn't be, how do I fix that?

    secondly, how can I implement autoindenting?

    and lastly, is code folding even possible?

    6,686585
    Grand MasterGrand Master
    6,686585

      Jul 14, 2005#2

      This could help you:

      Code: Select all

      /L20"Smash Files" String Chars = p DisableMLS File Extensions =
      /Delimiters = # $	()*+,./:;<=>\
      /Indent Strings = "c" "C" "c" "c"
      /Unindent Strings = "C" "g" "g" "c"
      /Open Fold Strings = "c" "C" "c" "c"
      /Close Fold Strings = "C" "g" "g" "c"
      /C1"Commands"
      C
      c
      g
      r
      Instead of String Chars = p DisableMLS also following can be used - note the 2 spaces before File Extensions.

      Code: Select all

      Noquote Line Comment Num = 2p  File Extensions =
      This "language" is case-sensitive. So never write C and c on the same line. The code folding will not work perfect, especially on "c" - "c" situations. I have already written a feature request for code folding with identical open and close fold strings. Maybe the support for identical open and close fold strings will be better in a future release.
      Best regards from an UC/UE/UES for Windows user from Austria

      youngr54
      youngr54

        Jul 14, 2005#3

        Thanks for your reply,
        Code folding is not that important, so I'll leace that aside for now.
        I've tried your highlighter code, it works perfectly for the sample code I gave you.
        Unfortunately, the sample code I gave you was faulty :?
        Sorry! I used two spaces instead of tabs when writing the code!

        Here's some slightly more complex example: (proper tabs this time!)
        EDIT: ahh, BBCode converts tabs to spaces! please make sure you convert them back to proper tabs!

        Code: Select all

        . You are in a bank\, the tiles below you are solid marble.
        c coins = 0
        	coins = r:10
        	p You have no money, you are given {coins} coins
        	c coins >=5
        		P ,just enough to buy that map!
        	C 
        		P ,you need more than that to buy the map!
        C   
        	P You already have money.
        P You look at the coins\, they have the letter c embossed into them.
        g outsideBank
        
        Some new commands, "." prints text to the "area description" screen while "p" prints text to the "action description" screen and "P" appends text to the "action description" screen.

        Here's my highlighter code:

        Code: Select all

        /L12 "Smash" Noquote Line Comment Num = 2p  Line Comment Alt = P File Extensions = SMA
        /Delimiters = # $   ()*+,./:;<=>\
        /Indent Strings = "c" "C" "c" "c"
        /Unindent Strings = "C" "g" "g" "c"
        /C1"Keywords"
        C
        c
        g
        r
        
        However it doesn't work as expected.

        And I just have one more question, why doesn't ultraedit allow regex in ALL the fields of the highlighter code? This would make things MUCH easier and MUCH more powerful

        Thanks, in advance, for taking the time to read my long posts!
        Brian Peiris

        6,686585
        Grand MasterGrand Master
        6,686585

          Jul 14, 2005#4

          Try this:

          Code: Select all

          /L12 "Smash" Noquote Line Comment Num = 2p  Line Comment Preceding Chars = [~0-9a-z] Line Comment Alt = P Line Comment Preceding Chars Alt = [~0-9a-z] Block Comment On Alt = . File Extensions = SMA
          /Delimiters = # $ ()*+,./:;<=>\
          /Indent Strings = "c" "C" "c" "c"
          /Unindent Strings = "C" "g" "g" "c"
          /C1"Keywords"
          C
          c
          g
          r
          Attention: The space between $ and ( in the delimiters definition must be a real tab - ASCII code 0x09 !!!
          I think, this was your problem with the first definition I wrote.

          The additional preceding characters definitions are just for restricting p or P comments even more. It is not possible to define an alternative "Num" line comment. The '.' as third line comment (block comment on without off) is a little bit dangerous for misinterpretation, but for your example it works.

          To your last question: Because regular expressions everywhere would be extremly time consuming and would slow down scrolling and editing dramatically. Have you ever opened the function list on a 'C' file with about 150 functions on a slow computer (< 1 GHz) - lean back and wait.
          And real languages have a good syntax, where regular expressions are not needed.
          Best regards from an UC/UE/UES for Windows user from Austria

          youngr54
          youngr54

            Jul 14, 2005#5

            yeah, thats fixes some problems, but I've only scratched the surface of the complexity of this language and as the code gets more complex, the highlighting will be doubly so.
            I think I'll try and find another editor, ultraedit is great, but the syntax highlighting hasn't developed for enough I think.
            But then again its probably this awkward language.
            Thanks a lot for you help Mofi
            Brian Peiris