1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Syntax highlighting in the IDE

Discussion in 'Support' started by TLis, Dec 21, 2012.

  1. TLis

    Joined:
    Dec 9, 2012
    Messages:
    20
    Likes Received:
    0
    I have noticed, that the IDE does not highlight the "then", "else", "to" (in a DO loop) keywords. Why aren't they coloured as "iff", "endiff" or "do" are.
     
  2. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,854
    Likes Received:
    83
    None of those are keywords in a DO statement. (Except for "to", which is only valid in 1 out of 13 possible DO syntaxes -- and the editor isn't able to determine when that is true.)
     
  3. TLis

    Joined:
    Dec 9, 2012
    Messages:
    20
    Likes Received:
    0
    I see, I wasn't clear enough. Only "to" may be a keyword in a DO statement, that's right. What about IFF statement then? The "THEN" keyword is mandatory, so I believe it could be recognised properly. The "ELSE" keyword, when present, must be alone on the line - this, I presume, gives also the editor to ability to recognise it as a keyword. It is just weird to see them not coloured, as keywords ...
     
  4. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,854
    Likes Received:
    83
    Can you provide an example of the syntax you're using?
     
  5. TLis

    Joined:
    Dec 9, 2012
    Messages:
    20
    Likes Received:
    0
    Sure:
    For "to" with DO ("to" not coloured):
    For "then" and "else" not being coloured:
     
  6. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,934
    Likes Received:
    30
    That was easy to repro. In BDEBUGGER I typed what appears below. "Then" and "else" were not highlighted.
    Code:
    iff 1 == 1 then
        echo foo
    else
        echo bar
    endiff
    
     
  7. TLis

    Joined:
    Dec 9, 2012
    Messages:
    20
    Likes Received:
    0
    Same goes for "elseiff" - not highlighted either
     
  8. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,854
    Likes Received:
    83
    Keywords inside an internal command (like DO or IFF) are not colorized; only commands, operators, strings, variables, and comments. The colorizing lexer cannot differentiate between something like a "then" or "to" and any other command argument. Doing that would require a custom lexer for every command; not a feasible approach.
     
  9. TLis

    Joined:
    Dec 9, 2012
    Messages:
    20
    Likes Received:
    0
    I have tried some incorrect syntax in the IDE, as e.g.
    and found that the statement/command keywords are colored regardless of the syntax ("iff", "do", "if" only). This suggests that the colorizing lexer in the IDE does not care much about the syntax of the actual command. That's OK, I believe. Then, however, it sounds feasible to me, if the lexer just colored specific additional keywords also whenever they are encountered, hence coloring "to", "then", "else" and "elseiff" as well. I gather the arguments of commands are not very likely to match these keywords exactly, the closest match that comes to my mind is when such a keyword is preceded by "/", "-" or "%" prefixes. If these prefixes would be present, the keywords would not be colored. That could be the maximum level of the required lexer's "inteligence".

    I believe, that by applying the above scheme we can gain more legibility of the TCC source code than without it, where it is difficult to recognize the starts and ends of command sections (then - endiff, then - else, then - elseiff, else - endiff, etc.) and some parts of the command, vital for its understanding are less visible, than they could (e.g. do ... to).

    UPDATE: If we would like to have some syntax-dependent coloring, then I another idea comes to my mind, based on the assumption, that the lexer does recognise (and color) the main commands and statements, so it knows, when it is INSIDE such a command or statement. The statements and commands could provide a dictionary of additional keywords to color in the context of that particular statement or command. Then, they would be just colored, whenever they come within that statement or command. I am not sure, though, if the benefit are big enough to justify the effort in comparison with the first idea presented above ...
     

Share This Page