Riven
|
 |
«
Posted
2011-11-10 02:22:13 » |
|
I got tired of the buggy, CPU hogging Javascript syntax highlighter. Hence I wrote some horrific PHP that spits out: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
public class Test { public static final double WAY_TOO_MUCH = 25.4f; public static final long[] DISARRAY = {-1, 1, 2L, 0xf3L};
public volatile Map<String, Map<Integer,double>> lastNameToAgeToCreditRating;
@Annotation(14) @Annotator("fourteen") public static void main(String[] args) throws IOException {
try { char secret = 'X'; int requested = 5; int offered = Integer.parseInt(args[0]);
if(offered > WAY_TOO_MUCH) { System.out.println("get off my "+args[(int)DISARRAY[offered]]+"!"); } else { System.out.println("hm. kay."); } } finally { System.out.println ("thx."); } } }
|
it's far from flawless, and you guys will easily break it, if only due to failing to comply with java naming conventions 
|
|
|
|
sproingie
|
 |
«
Reply #1 - Posted
2011-11-10 03:31:59 » |
|
Ooh let's see what we can do to it... 1 2 3 4
| class $x { volatile strictfp double \u2603 = 0.; @_(@__() Void.class) foo(Object ... o) { foo<Integer>(123,o) } } |
Damn, not bad at all... 
|
|
|
|
|
Riven
|
 |
«
Reply #2 - Posted
2011-11-10 03:57:45 » |
|
Thanks for your test-case, just fixed a bunch of screwups and your typical off-by-one bugs.
|
|
|
|
Games published by our own members! Check 'em out!
|
|
theagentd
|
 |
«
Reply #3 - Posted
2011-11-10 10:46:21 » |
|
Ooh let's see what we can do to it... 1 2 3 4
| class $x { volatile strictfp double \u2603 = 0.; @_(@__() Void.class) foo(Object ... o) { foo<Integer>(123,o) } } |
Damn, not bad at all...  Is that valid Java code? o_O
|
Myomyomyo.
|
|
|
Bonbon-Chan
|
 |
«
Reply #4 - Posted
2011-11-10 11:19:14 » |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| "); System.out.println(cmt); System.out.println("
public int testComment(String cmt) { System.out.println("/*"); System.out.println(cmt); System.out.println("*/"); } |
Commenting a full code block with /* */ doesn't work 
|
|
|
|
|
Evil-Devil
|
 |
«
Reply #5 - Posted
2011-11-10 12:13:59 » |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| public class Util { public static final String fourCC(int fourCC) { byte[] fourCCString = new byte[4]; fourCCString[0] = (byte)fourCC; fourCCString[1] = (byte)(fourCC >> 8); fourCCString[2] = (byte)(fourCC >> 16); fourCCString[3] = (byte)(fourCC >> 24); return new String(fourCCString); } public static final int fourCC(String fourCC) { if (fourCC.length() > 4) throw new IllegalArgumentException("FourCC String must have 4 or less characters."); if (fourCC.length() < 4) { for (int i=0; i<(4-fourCC.length()); i++) { fourCC.concat(" "); } } int fourCCInt = 0; fourCCInt = (((byte)fourCC.charAt(0) & 0xFFFFFFFF) | ((byte)fourCC.charAt(1) & 0xFFFFFFFF) << 8 | ((byte)fourCC.charAt(2) & 0xFFFFFFFF) << 16 | ((byte)fourCC.charAt(3) & 0xFFFFFFFF) << 24); return fourCCInt; } } |
Looks good except for the byte array in line 4.
|
|
|
|
|
Riven
|
 |
«
Reply #6 - Posted
2011-11-10 13:12:37 » |
|
There seem to be quite a lot off-by-one bugs left. I will fix it tonight.
|
|
|
|
ReBirth
|
 |
«
Reply #7 - Posted
2011-11-10 14:05:51 » |
|
Nice! reminds me to my first editors, editplus and notepad++
|
|
|
|
BoBear2681
|
 |
«
Reply #8 - Posted
2011-11-10 18:43:28 » |
|
Riven, can you also modify the size of a tab? Seems like it's using the "standard" of 8 spaces, but for code snippets it should probably be set to something smaller like 4, to minimize the chance of much horizontal scrolling.
|
|
|
|
|
Riven
|
 |
«
Reply #9 - Posted
2011-11-10 21:25:28 » |
|
Ditched the entire thing and wrote a state-machine. It can distinguish variables and fields from methods now. I added support for nested generics, but the numbers are still split on the periods.
@Bonbon-Chan: the example you gave might look incorrect now, but this is how it's supposed to look.
@BoBear2681: converted tabs to 3 spaces
|
|
|
|
Games published by our own members! Check 'em out!
|
|
Z-Man
|
 |
«
Reply #10 - Posted
2011-11-11 01:03:16 » |
|
Nice! Looks good. , my only suggestion is to make the font a little bigger. It just looks a bit small to me, maybe it's my fault or maybe I'm weird . Also is there by chance an xml file or, something for that syntax highlighting color scheme, I like it. 
|
|
|
|
|
sproingie
|
 |
«
Reply #11 - Posted
2011-11-11 01:14:17 » |
|
The font is perfectly fine for me, in fact it's a bit on the large side. I can't see where it's set in CSS, so I think it's dependent on the monospace font you have set in your browser.
|
|
|
|
|
CommanderKeith
|
 |
«
Reply #12 - Posted
2011-11-11 01:16:24 » |
|
Great stuff. it's such a pity that there's no easy to rip off code out there from netbeans or eclipse. The best I could find when I needed this in swing was jsyntaxpane but it was very buggy when I used it back in 2009 http://code.google.com/p/jsyntaxpane/
|
|
|
|
Z-Man
|
 |
«
Reply #13 - Posted
2011-11-11 01:22:01 » |
|
The font is perfectly fine for me, in fact it's a bit on the large side. I can't see where it's set in CSS, so I think it's dependent on the monospace font you have set in your browser.
Yep, it's using my browser's (Firefox 8's) monospace font. Thanks 
|
|
|
|
|
Riven
|
 |
«
Reply #14 - Posted
2011-11-11 01:30:54 » |
|
Also is there by chance an xml file or, something for that syntax highlighting color scheme, I like it.  1 2 3 4 5 6 7 8 9 10 11 12
| span.javaLineComment { color: #080; } span.javaMultiComment { color: #080; } span.javaDocComment { color: #088; } span.javaKeyword { color: #808; } span.javaClass { color: #800; } span.javaAnnotation { color: #888; } span.javaField { color: #00c; } span.javaStatic { color: #404; } span.javaMethod { color: #008; } span.javaNumber { color: #c00; } span.javaString { color: #488; } span.javaChar { color: #f00; } |
I kinda picked random colors, mostly for debugging purposes. My home workspace looks nothing like it. I'll probably adjust it further to make it match the rest of the layout. I think a bunch of you just threw up in your mouth, screaming 'no more stale blue!', but I guess you can't please everyone 
|
|
|
|
JL235
|
 |
«
Reply #15 - Posted
2011-11-11 01:50:17 » |
|
Use Droid Sans Mono for the font, it's pretty!
|
|
|
|
Z-Man
|
 |
«
Reply #16 - Posted
2011-11-11 02:04:43 » |
|
I kinda picked random colors, mostly for debugging purposes. My home workspace looks nothing like it. I'll probably adjust it further to make it match the rest of the layout. I think a bunch of you just threw up in your mouth, screaming 'no more stale blue!', but I guess you can't please everyone  Thanks  I kinda like it's quirkiness, and it differentiates well between different things. JL235: That does look pretty! Good suggestion 
|
|
|
|
|
Riven
|
 |
«
Reply #17 - Posted
2011-11-11 02:07:32 » |
|
You can't beat this. You really can't. 
|
|
|
|
Z-Man
|
 |
«
Reply #18 - Posted
2011-11-11 02:15:45 » |
|
That's nice as well. It's very unobtrusive to the eye, not to bright and not to dark, and it also differentiates well. I simply use Netbean's color scheme (in Eclipse  )with a few modifications.
|
|
|
|
|
Riven
|
 |
«
Reply #19 - Posted
2011-11-11 02:51:42 » |
|
Derailing my own thread... 1 2 3 4 5 6
| if (fourCC.length() < 4) { for (int i=0; i<(4-fourCC.length()); i++) { fourCC.concat(" "); } } |
1. fourCC will not be modified (strings are immutable), you're basically doing nothing. 2. if they were, it still wouldn't work, so adding the assignment wouldn't help (much) You can see that if you pass an empty string, it will stop once it reaches a length of 2, instead of 4. Trivial fix: 1 2 3 4
| while (fourCC.length() < 4) { fourCC = fourCC.concat(" "); } |
Besides that, shoving arbitrary bytes in a byte[4] into a String(...) is extremely dangerous, as you get a conversation to a char[] using the default system dependent charset which is not at all guaranteed to result into a char[4], and even when it's a char[4] within the String, that doesn't mean each char holds the value each original byte had. Spooky nicely colored code 
|
|
|
|
ra4king
|
 |
«
Reply #20 - Posted
2011-11-11 04:20:48 » |
|
What is the font used in that image? I really like it! I'm getting tired of Courier New....
|
|
|
|
sproingie
|
 |
«
Reply #21 - Posted
2011-11-11 04:34:21 » |
|
Looks like Terminal to me.
I'm a big fan of DejaVu Sans Mono. Use it for emacs and all my terminals.
|
|
|
|
|
Evil-Devil
|
 |
«
Reply #22 - Posted
2011-11-11 12:19:13 » |
|
Derailing my own thread... 1 2 3 4 5 6
| if (fourCC.length() < 4) { for (int i=0; i<(4-fourCC.length()); i++) { fourCC.concat(" "); } } |
1. fourCC will not be modified (strings are immutable), you're basically doing nothing. 2. if they were, it still wouldn't work, so adding the assignment wouldn't help (much) You can see that if you pass an empty string, it will stop once it reaches a length of 2, instead of 4. Trivial fix: 1 2 3 4
| while (fourCC.length() < 4) { fourCC = fourCC.concat(" "); } |
Besides that, shoving arbitrary bytes in a byte[4] into a String(...) is extremely dangerous, as you get a conversation to a char[] using the default system dependent charset which is not at all guaranteed to result into a char[4], and even when it's a char[4] within the String, that doesn't mean each char holds the value each original byte had. Spooky nicely colored code  Erm, well...i only knew the code worked like intented back in 2005/2006 and using the systems default charset was out of scope as the FourCC was part of the fileheader. Which was IIRC lower endian ...though concat returns a new string object
|
|
|
|
|
pitbuller
|
 |
«
Reply #23 - Posted
2011-11-11 13:47:58 » |
|
Blue background brings up good memories from QBasic.
|
|
|
|
|
Riven
|
 |
«
Reply #24 - Posted
2011-11-11 14:24:10 » |
|
Erm, well...i only knew the code worked like intented back in 2005/2006
It only works correctly if the argument String length is already 4
|
|
|
|
appel
|
 |
«
Reply #25 - Posted
2011-11-11 14:46:44 » |
|
Can you [size=13pt]color code[/size] and change the [size=16pt]font[/size][/b] of what [size=20pt]I[/size] say so it [size=12pt]matches[/size] my mood and [size=14pt]feelings[/size][/color]?
|
|
|
|
aazimon
|
 |
«
Reply #26 - Posted
2011-11-12 01:21:50 » |
|
The code color works much better.  Thanks for the effort.
|
|
|
|
|
Riven
|
 |
«
Reply #27 - Posted
2012-01-04 18:30:42 » |
|
There are still some bugs in it, but well, that's mostly caused by SMF html-encoding a lot of characters which messes up the tokenizer. What I forgot to mention though that since a few weeks, you can use the '@@' prefix to highlight lines: 1 2 3 4 5
| for(int i=-13; i<13; i++) { if(i==1) { System.out.println("One is my lucky number!"); } } |
|
|
|
|
nsigma
|
 |
«
Reply #28 - Posted
2012-01-04 18:37:16 » |
|
What I forgot to mention though that since a few weeks, you can use the '@@' prefix to highlight lines:
For a moment I was like, wtf is he on about? Then I squinted and tilted my laptop screen ... and I can just about make it out. Maybe my screen's set up badly, but a little bit darker, please! 
|
|
|
|
Riven
|
 |
«
Reply #29 - Posted
2012-01-04 18:40:18 » |
|
Hm, it's very clear on both my monitors.
If your monitor displays "#ffc" as "#fff" you're really going to experience the inter tubes differently.
I adjusted it to "#ffa". Better now?
|
|
|
|
|