Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (429)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (466)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2
  ignore  |  Print  
  New feature: serverside syntax highlighting  (Read 4255 times)
0 Members and 1 Guest are viewing this topic.
Online Riven
« League of Dukes »

JGO Overlord


Medals: 613
Projects: 4
Exp: 16 years


Hand over your head.


« 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  
/*
 * multi-line comment
 */


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;

   /**
    * Javadoc
    */


   @Annotation(14)
   @Annotator("fourteen")
   public static void main(String[] args) throws IOException {

      // single line comment

      try {
         char secret = 'X';
         int requested = 5;
         int offered = Integer.parseInt(args[0]);

        if(offered > WAY_TOO_MUCH) { // I prefixed the line with @@ to trigger the highlight
           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 Smiley

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline sproingie

JGO Kernel


Medals: 200



« 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... Grin
Online Riven
« League of Dukes »

JGO Overlord


Medals: 613
Projects: 4
Exp: 16 years


Hand over your head.


« 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.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline 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... Grin


Is that valid Java code? o_O

Myomyomyo.
Offline Bonbon-Chan

JGO Coder


Medals: 12



« 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  
/* ******************* / ********************
A old test function

public int testComment(String cmt)
{
  System.out.println("*/
");
  System.out.println(cmt);
  System.out.println("
/*");
}

// Next the new function, " // " change

Funny no ?

* * * *  **/



public int testComment(String cmt)
{
  System.out.println("/*");
  System.out.println(cmt);
  System.out.println("*/");
}


Commenting a full code block with /* */ doesn't work  Wink
Offline Evil-Devil

Senior Member


Medals: 2


Fir Tree Master


« 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.");
     
      // fill fourCC with whitespaces if length is shorter than 4
     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.
Online Riven
« League of Dukes »

JGO Overlord


Medals: 613
Projects: 4
Exp: 16 years


Hand over your head.


« 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.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline ReBirth
« Reply #7 - Posted 2011-11-10 14:05:51 »

Nice! reminds me to my first editors, editplus and notepad++

Offline BoBear2681

JGO Coder


Medals: 18



« 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.
Online Riven
« League of Dukes »

JGO Overlord


Medals: 613
Projects: 4
Exp: 16 years


Hand over your head.


« 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

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline 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 Grin. Also is there by chance an xml file or, something for that syntax highlighting color scheme, I like it. persecutioncomplex
Offline sproingie

JGO Kernel


Medals: 200



« 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.
Offline 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/

Offline 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 Smiley
Online Riven
« League of Dukes »

JGO Overlord


Medals: 613
Projects: 4
Exp: 16 years


Hand over your head.


« 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. persecutioncomplex

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 Smiley

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline JL235

JGO Coder


Medals: 10



« Reply #15 - Posted 2011-11-11 01:50:17 »

Use Droid Sans Mono for the font, it's pretty!

Offline 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 Smiley
Thanks Smiley I kinda like it's quirkiness, and it differentiates well between different things.

JL235: That does look pretty! Good suggestion Smiley
Online Riven
« League of Dukes »

JGO Overlord


Medals: 613
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #17 - Posted 2011-11-11 02:07:32 »

You can't beat this. You really can't.


Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline 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  Cool )with a few modifications.
Online Riven
« League of Dukes »

JGO Overlord


Medals: 613
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #19 - Posted 2011-11-11 02:51:42 »

Derailing my own thread...

1  
2  
3  
4  
5  
6  
      // fill fourCC with whitespaces if length is shorter than 4
     if (fourCC.length() < 4) {
         for (int i=0; i<(4-fourCC.length()); i++) { // <--------------- this is a bug!
           /* fourCC = */ fourCC.concat(" "); // <--------------- this is a bug!
        }
      }

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  
      // fill fourCC with whitespaces if length is shorter than 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 Smiley

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline ra4king

JGO Kernel


Medals: 322
Projects: 2
Exp: 4 years


I'm the King!


« 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....

Offline sproingie

JGO Kernel


Medals: 200



« 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.
Offline Evil-Devil

Senior Member


Medals: 2


Fir Tree Master


« Reply #22 - Posted 2011-11-11 12:19:13 »

Derailing my own thread...

1  
2  
3  
4  
5  
6  
      // fill fourCC with whitespaces if length is shorter than 4
     if (fourCC.length() < 4) {
         for (int i=0; i<(4-fourCC.length()); i++) { // <--------------- this is a bug!
           /* fourCC = */ fourCC.concat(" "); // <--------------- this is a bug!
        }
      }

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  
      // fill fourCC with whitespaces if length is shorter than 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 Smiley
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
Offline pitbuller
« Reply #23 - Posted 2011-11-11 13:47:58 »

Blue background brings up good memories from QBasic.
Online Riven
« League of Dukes »

JGO Overlord


Medals: 613
Projects: 4
Exp: 16 years


Hand over your head.


« 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

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline appel

JGO Wizard


Medals: 49
Projects: 4


I always win!


« 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]?

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline aazimon
« Reply #26 - Posted 2011-11-12 01:21:50 »

The code color works much better.  Smiley Thanks for the effort.
Online Riven
« League of Dukes »

JGO Overlord


Medals: 613
Projects: 4
Exp: 16 years


Hand over your head.


« 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) { // ORLY!
     System.out.println("One is my lucky number!");
   }
}

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline 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!  Smiley

Praxis LIVE - open-source intermedia toolkit and live interactive visual editor
Digital Prisoners - interactive spaces and projections
Online Riven
« League of Dukes »

JGO Overlord


Medals: 613
Projects: 4
Exp: 16 years


Hand over your head.


« 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?

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Pages: [1] 2
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (80 views)
2014-04-15 18:08:23

BurntPizza (72 views)
2014-04-15 03:46:01

UprightPath (83 views)
2014-04-14 17:39:50

UprightPath (67 views)
2014-04-14 17:35:47

Porlus (83 views)
2014-04-14 15:48:38

tom_mai78101 (107 views)
2014-04-10 04:04:31

BurntPizza (167 views)
2014-04-08 23:06:04

tom_mai78101 (263 views)
2014-04-05 13:34:39

trollwarrior1 (213 views)
2014-04-04 12:06:45

CJLetsGame (222 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!