Syntax Highlighting
Root / Submissions / [.]
MZ952Created:
Download:73XKNXCXVersion:Size:
Whoops meant to upload this like forever ago.
Custom syntax highlighter geared towards highlighting SmileBASIC code.
I tried to optimize it for highlighting other custom languages, and, well, it can be done, but it's not perfect. I took a few shortcuts that seats it rather firmly at the moment in SB syntax.
bugs:
- ? next alphanumeric chars isn't highlighted
- .E is allowed in numbers
Weird code:
DEF ISALPHNUM(C$) DIM C0=C$=="_" DIM C1=C$>="0",C2=C$<="9" DIM C3=C$>="A",C4=C$<="Z" DIM C5=C$>="a",C6=C$<="z" RETURN C0||C1&&C2||C3&&C4||C5&&C6 END 'vs DEF ISALPHNUM(C$) RETURN C$=="_"||C$>="0"&&C$<="9"||C$>="A"&&C$<="Z"||C$>="a"&&C$<="z" END 'etcSB is very very good at optimizing comparison chains like this; here's a disassembly of the bytecode generated:
== param(0),"_" JF @RET >= param(0),"0" JNF @30 <= param(0),"9" JF @RET @30: >= param(0),"A" JNF @4C <= param(0),"Z" JF @RET @4C: >= param(0),"a" JNF @RET <= param(0),"z" @RET: MOVFLAG ->return ENDDEF(JF: jump if flag set (if comparison was true) JNF: jump if flag not set (if compare was false)) vs your function:
== param(0),"_" MOVFLAG ->local(0) >= param(0),"0" MOVFLAG ->local(1) <= param(0),"9" MOVFLAG ->local(2) >= param(0),"A" MOVFLAG ->local(1) <= param(0),"Z" MOVFLAG ->local(2) >= param(0),"a" MOVFLAG ->local(1) <= param(0),"z" MOVFLAG ->local(2) != local(0),0 JF @RET != local(1),0 JNF @7E != local(2),0 JF @RET @7E: != local(3),0 JNF @96 != local(4),0 JF @RET @96: != local(5),0 JNF @RET != local(6),0 @RET:MOVFLAG ->return ENDDEF
Replying to:12Me21
bugs:
- ? next alphanumeric chars isn't highlighted
- .E is allowed in numbers
Weird code:
DEF ISALPHNUM(C$) DIM C0=C$=="_" DIM C1=C$>="0",C2=C$<="9" DIM C3=C$>="A",C4=C$<="Z" DIM C5=C$>="a",C6=C$<="z" RETURN C0||C1&&C2||C3&&C4||C5&&C6 END 'vs DEF ISALPHNUM(C$) RETURN C$=="_"||C$>="0"&&C$<="9"||C$>="A"&&C$<="Z"||C$>="a"&&C$<="z" END 'etcSB is very very good at optimizing comparison chains like this; here's a disassembly of the bytecode generated:
== param(0),"_" JF @RET >= param(0),"0" JNF @30 <= param(0),"9" JF @RET @30: >= param(0),"A" JNF @4C <= param(0),"Z" JF @RET @4C: >= param(0),"a" JNF @RET <= param(0),"z" @RET: MOVFLAG ->return ENDDEF(JF: jump if flag set (if comparison was true) JNF: jump if flag not set (if compare was false)) vs your function:
== param(0),"_" MOVFLAG ->local(0) >= param(0),"0" MOVFLAG ->local(1) <= param(0),"9" MOVFLAG ->local(2) >= param(0),"A" MOVFLAG ->local(1) <= param(0),"Z" MOVFLAG ->local(2) >= param(0),"a" MOVFLAG ->local(1) <= param(0),"z" MOVFLAG ->local(2) != local(0),0 JF @RET != local(1),0 JNF @7E != local(2),0 JF @RET @7E: != local(3),0 JNF @96 != local(4),0 JF @RET @96: != local(5),0 JNF @RET != local(6),0 @RET:MOVFLAG ->return ENDDEF
Already fixed the first, thought I already fixed the last lol thanks
Edit: wait, sorry, .E? Like,
.E1for example? That's not legal code, or it doesn't seem to be. Stuff like
1.0E1 .1E1is though.
Replying to:12Me21
bugs:
- ? next alphanumeric chars isn't highlighted
- .E is allowed in numbers
Weird code:
DEF ISALPHNUM(C$) DIM C0=C$=="_" DIM C1=C$>="0",C2=C$<="9" DIM C3=C$>="A",C4=C$<="Z" DIM C5=C$>="a",C6=C$<="z" RETURN C0||C1&&C2||C3&&C4||C5&&C6 END 'vs DEF ISALPHNUM(C$) RETURN C$=="_"||C$>="0"&&C$<="9"||C$>="A"&&C$<="Z"||C$>="a"&&C$<="z" END 'etcSB is very very good at optimizing comparison chains like this; here's a disassembly of the bytecode generated:
== param(0),"_" JF @RET >= param(0),"0" JNF @30 <= param(0),"9" JF @RET @30: >= param(0),"A" JNF @4C <= param(0),"Z" JF @RET @4C: >= param(0),"a" JNF @RET <= param(0),"z" @RET: MOVFLAG ->return ENDDEF(JF: jump if flag set (if comparison was true) JNF: jump if flag not set (if compare was false)) vs your function:
== param(0),"_" MOVFLAG ->local(0) >= param(0),"0" MOVFLAG ->local(1) <= param(0),"9" MOVFLAG ->local(2) >= param(0),"A" MOVFLAG ->local(1) <= param(0),"Z" MOVFLAG ->local(2) >= param(0),"a" MOVFLAG ->local(1) <= param(0),"z" MOVFLAG ->local(2) != local(0),0 JF @RET != local(1),0 JNF @7E != local(2),0 JF @RET @7E: != local(3),0 JNF @96 != local(4),0 JF @RET @96: != local(5),0 JNF @RET != local(6),0 @RET:MOVFLAG ->return ENDDEF
There was also a bug with &H... and &B... when preceded by uh alphanumerics, fixed that too.
I'm trying to create a new better version that allows the user to like select which types of tokens are highlighted and whatnot. I also want it to be faster.
Replying to:12Me21
bugs:
- ? next alphanumeric chars isn't highlighted
- .E is allowed in numbers
Weird code:
DEF ISALPHNUM(C$) DIM C0=C$=="_" DIM C1=C$>="0",C2=C$<="9" DIM C3=C$>="A",C4=C$<="Z" DIM C5=C$>="a",C6=C$<="z" RETURN C0||C1&&C2||C3&&C4||C5&&C6 END 'vs DEF ISALPHNUM(C$) RETURN C$=="_"||C$>="0"&&C$<="9"||C$>="A"&&C$<="Z"||C$>="a"&&C$<="z" END 'etcSB is very very good at optimizing comparison chains like this; here's a disassembly of the bytecode generated:
== param(0),"_" JF @RET >= param(0),"0" JNF @30 <= param(0),"9" JF @RET @30: >= param(0),"A" JNF @4C <= param(0),"Z" JF @RET @4C: >= param(0),"a" JNF @RET <= param(0),"z" @RET: MOVFLAG ->return ENDDEF(JF: jump if flag set (if comparison was true) JNF: jump if flag not set (if compare was false)) vs your function:
== param(0),"_" MOVFLAG ->local(0) >= param(0),"0" MOVFLAG ->local(1) <= param(0),"9" MOVFLAG ->local(2) >= param(0),"A" MOVFLAG ->local(1) <= param(0),"Z" MOVFLAG ->local(2) >= param(0),"a" MOVFLAG ->local(1) <= param(0),"z" MOVFLAG ->local(2) != local(0),0 JF @RET != local(1),0 JNF @7E != local(2),0 JF @RET @7E: != local(3),0 JNF @96 != local(4),0 JF @RET @96: != local(5),0 JNF @RET != local(6),0 @RET:MOVFLAG ->return ENDDEF
code like this:
?.ENDshould be parsed as ?. END rather than ? .E ND (E can't be directly after . in number literals, so it's treated as a separate token) Note that ?1END is not valid in SB though
Replying to:12Me21
bugs:
- ? next alphanumeric chars isn't highlighted
- .E is allowed in numbers
Weird code:
DEF ISALPHNUM(C$) DIM C0=C$=="_" DIM C1=C$>="0",C2=C$<="9" DIM C3=C$>="A",C4=C$<="Z" DIM C5=C$>="a",C6=C$<="z" RETURN C0||C1&&C2||C3&&C4||C5&&C6 END 'vs DEF ISALPHNUM(C$) RETURN C$=="_"||C$>="0"&&C$<="9"||C$>="A"&&C$<="Z"||C$>="a"&&C$<="z" END 'etcSB is very very good at optimizing comparison chains like this; here's a disassembly of the bytecode generated:
== param(0),"_" JF @RET >= param(0),"0" JNF @30 <= param(0),"9" JF @RET @30: >= param(0),"A" JNF @4C <= param(0),"Z" JF @RET @4C: >= param(0),"a" JNF @RET <= param(0),"z" @RET: MOVFLAG ->return ENDDEF(JF: jump if flag set (if comparison was true) JNF: jump if flag not set (if compare was false)) vs your function:
== param(0),"_" MOVFLAG ->local(0) >= param(0),"0" MOVFLAG ->local(1) <= param(0),"9" MOVFLAG ->local(2) >= param(0),"A" MOVFLAG ->local(1) <= param(0),"Z" MOVFLAG ->local(2) >= param(0),"a" MOVFLAG ->local(1) <= param(0),"z" MOVFLAG ->local(2) != local(0),0 JF @RET != local(1),0 JNF @7E != local(2),0 JF @RET @7E: != local(3),0 JNF @96 != local(4),0 JF @RET @96: != local(5),0 JNF @RET != local(6),0 @RET:MOVFLAG ->return ENDDEF
All of the code is weird.
Yeah, I know it's better to just straight return the raw logical condition. Guess I didn't optimize it further after getting it working.
Replying to:12Me21
bugs:
- ? next alphanumeric chars isn't highlighted
- .E is allowed in numbers
Weird code:
DEF ISALPHNUM(C$) DIM C0=C$=="_" DIM C1=C$>="0",C2=C$<="9" DIM C3=C$>="A",C4=C$<="Z" DIM C5=C$>="a",C6=C$<="z" RETURN C0||C1&&C2||C3&&C4||C5&&C6 END 'vs DEF ISALPHNUM(C$) RETURN C$=="_"||C$>="0"&&C$<="9"||C$>="A"&&C$<="Z"||C$>="a"&&C$<="z" END 'etcSB is very very good at optimizing comparison chains like this; here's a disassembly of the bytecode generated:
== param(0),"_" JF @RET >= param(0),"0" JNF @30 <= param(0),"9" JF @RET @30: >= param(0),"A" JNF @4C <= param(0),"Z" JF @RET @4C: >= param(0),"a" JNF @RET <= param(0),"z" @RET: MOVFLAG ->return ENDDEF(JF: jump if flag set (if comparison was true) JNF: jump if flag not set (if compare was false)) vs your function:
== param(0),"_" MOVFLAG ->local(0) >= param(0),"0" MOVFLAG ->local(1) <= param(0),"9" MOVFLAG ->local(2) >= param(0),"A" MOVFLAG ->local(1) <= param(0),"Z" MOVFLAG ->local(2) >= param(0),"a" MOVFLAG ->local(1) <= param(0),"z" MOVFLAG ->local(2) != local(0),0 JF @RET != local(1),0 JNF @7E != local(2),0 JF @RET @7E: != local(3),0 JNF @96 != local(4),0 JF @RET @96: != local(5),0 JNF @RET != local(6),0 @RET:MOVFLAG ->return ENDDEF
Ah I see. I'll probably handle the whole numerics dilemma a bit different in my next iteration. Numbers have .... versatile syntaxes.