kasperkuo / google-code-prettify

Automatically exported from code.google.com/p/google-code-prettify
Apache License 2.0
0 stars 0 forks source link

Using lang-cs doesn't highlight the keywords `namespace` and `using` #299

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I found that this isn't highlighting the keywords 'namespace' and 'using' with 
the default highlighting or the 'lang-cs' tag. But it works when using 
'lang-csharp' which isn't mentioned in your README.

I had originally thought that it's the error in SO but it's not being detected 
in my own html file as well. See the original topic at

http://meta.stackoverflow.com/questions/189802/error-in-c-syntax-highlighting?no
redirect=1#comment586854_189802

Original issue reported on code.google.com by sriharshachilakapati@gmail.com on 22 Jul 2013 at 4:53

GoogleCodeExporter commented 8 years ago
The original problem is identified in that thread. The C# keywords list is 
missing keywords 'namespace' 'using' and 'get'

Original comment by sriharshachilakapati@gmail.com on 23 Jul 2013 at 3:31

GoogleCodeExporter commented 8 years ago
This related to issue #283. Currently [the code][1] tries to reduce repetition
by having a list of common keywords and inheriting this list from the various
languages. Unfortunately, a couple of extra keywords slip through, as well as 
missing a few specific ones.

I went through this [list][2], and came up with the following (basically I 
"unrolled" the list of inherited keywords and removed the extra tokens, while 
adding a few missing ones):

  var CSHARP_KEYWORDS = [FLOW_CONTROL_KEYWORDS,

      "case,char,const,default," + 
      "double,enum,extern,float,goto,int,long,short," +
      "sizeof,static,struct,switch,void,volatile," +

      "catch,class,false," +
      "new,operator,private,protected,public,this,throw,true,try,typeof," +

      "abstract,as,base,bool,byte,checked,decimal,delegate,descending," +
      "dynamic,event,finally,fixed,foreach,from,group,implicit,in,interface," +
      "internal,into,is,let,lock,null,object,out,override,orderby,params," +
      "partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong," +
      "unchecked,unsafe,ushort,var,virtual,where," +

      "ascending,async,await,explicit,get,global,join,namespace,set,using,yield"];

This should fix the case of the missing keywords you mentioned, along with a 
few others. Note that C# has some contextual keywords, meaning that the token 
is only considered in certain contexts, which is not possible without a proper 
grammatical parsing.

btw, Stack Overflow is apparently not using the latest version of 
code-prettify, so it might take some time for you to see the changes over 
there..

 [1]: http://code.google.com/p/google-code-prettify/source/browse/trunk/src/prettify.js#110
 [2]: http://msdn.microsoft.com/en-us/library/x53a06bb.aspx

Original comment by amroamro...@gmail.com on 4 Aug 2013 at 3:03