zzyengineer / google-code-prettify

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

C#/Java Syntax issue #70

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Test the following lines
class Foo
{
   public string Version {get; set;}

   public void Bar()
   {
       //do something
   }
}

2. The class name "Foo" and the method name "Bar" are both marked as types
(i.e. css class "typ") so they end up having the same color.

3. Class names (Types) have the same CSS class name "typ" as Method &
Property names

What is the expected output? What do you see instead?
Method & Properpty names should have their own CSS class

Please use labels and text to provide additional information.

Original issue reported on code.google.com by taw...@gmail.com on 24 Mar 2009 at 12:45

GoogleCodeExporter commented 9 years ago
I don't see the issue in Java.
Java style guidelines specify that type names and only type names are 
upper-camel-case.

What is the convention for C#?

Original comment by mikesamuel@gmail.com on 19 May 2009 at 5:22

GoogleCodeExporter commented 9 years ago
This is not a convention issue. 
All I'm saying is class "names" and method "names" should not have the same CSS 
class 
name (i.e. "typ").
In any IDE (Visual Studio,Eclipse,TextMate etc.) class names have a different 
"color" 
from method names.

Original comment by taw...@gmail.com on 20 May 2009 at 11:03

GoogleCodeExporter commented 9 years ago
This implementation does not fully parse either language so it cannot 
distinguish
between a class and a package name except by convention.

Original comment by mikesamuel@gmail.com on 20 May 2009 at 7:19

GoogleCodeExporter commented 9 years ago
obviously you don't understand English.

This is what is expected:

<pre>
class <span class="type">Foo</span>
{
   public string Version {get; set;}

   public void <span class="method">Bar</span>()
   {
       //do something
   }
}
</pre>

Original comment by taw...@gmail.com on 21 May 2009 at 10:59

GoogleCodeExporter commented 9 years ago
In C#, properties and methods should be UpperCamelCase.

Original comment by alexey.v...@gmail.com on 14 Aug 2009 at 7:43

GoogleCodeExporter commented 9 years ago
I am not talking about coding style, I am talking about setting different css 
style 
classes for type names (e.g. class Boolean => Bolean = class name) and for 
method names 
(e.g. void UpdateCustomer(Customer c) => UpdateCustomer = method name).

FTW: UpperCamelCase ???

Original comment by taw...@gmail.com on 15 Aug 2009 at 4:53

GoogleCodeExporter commented 9 years ago
Type names and method names _are_ highlighted differently. Go to
http://google-code-prettify.googlecode.com/svn/trunk/tests/prettify_test.html#ja
va
and you can see that.

The problem here is that Prettify thinks Version and Bar are type names, 
because they
start with a capital letter. In Java this would make sense, because "Java style
guidelines specify that type names and only type names are upper-camel-case". 
In C#
it's just wrong, so this is only an issue for C#.

Original comment by alexey.v...@gmail.com on 15 Aug 2009 at 5:25

GoogleCodeExporter commented 9 years ago
Does anyone know how to distinguish method names from type names in C# at a 
purely
lexical level?

Original comment by mikesamuel@gmail.com on 17 Aug 2009 at 3:48

GoogleCodeExporter commented 9 years ago
I looked at http://msdn.microsoft.com/en-us/library/aa664812%28VS.71%29.aspx, 
and I'm
a bit unsure about delegates and such.

Is it the case that in C#, ignoring whitespace and comment tokens, a method 
name is
always followed by an open parenthesis, and a typename is never followed by an 
open
parenthesis.

There's no special syntax for dereferencing a method to return a delegable 
value, so
Foo(MyClass.MyMethod) contains one type name and two method names, and there's 
no way
to distinguish the two purely at the lexical level?

Original comment by mikesamuel@gmail.com on 17 Aug 2009 at 3:58

GoogleCodeExporter commented 9 years ago
> Is it the case that in C#, ignoring whitespace and comment tokens, a method 
name is
always followed by an open parenthesis, and a typename is never followed by an 
open
parenthesis.

Method names can be used as "method groups" without parentheses, as in your 
example
Foo(MyClass.MyMethod)

Type name can be followed by an open parenthesis in constructors, just as in 
Java.
E.g. new Class()

Properties (like Version in the original issue) should really be highlighted 
the same
as methods.

Original comment by alexey.v...@gmail.com on 18 Aug 2009 at 2:12

GoogleCodeExporter commented 9 years ago
Is there a set of symbols that typically precede or follow a type name so that 
I can
assume that all others are not types?

In java, a type name can follow the 'new' keyword; precede '.class'; follow '.' 
if
following 'import' or 'package'; follow 'class', 'extends', 'implements', 
'throws';
follow '<' or ',' in a parenthetical group at one level of curly bracket nesting
greater than an unclosed block preceded by a 'class', 'interface', 'enum' or
'@interface' keyword; or precede a '.' if upper-case by convention.

In C#, the last rule is giving us trouble.  Would some variation on the other 
rules
suffice?

Original comment by mikesamuel@gmail.com on 18 Aug 2009 at 5:02

GoogleCodeExporter commented 9 years ago
This is going to be hard, because you also have to keep in mind constructors 
(public 
Foo()) and that the visibility specifier is optional (instead of private void 
Something() you can write Something()).

Some tips:
Class names have lower-case class right before the class name and no 
parenthesis.
These are valid class specifications (may not be complete):
public class Something
internal static class Somethingelse
private class ThisImplementsAnInterface : IInterface
public class SubclassAndInterface : Exception, IDropTarget
(In the last example, SubclassAndInterface, Exception and IDropTarget should 
all be 
highlighted as Class Names)

These are invalid:
class static InvalidOne
class internal InvalidTwo
Class InvalidThree

(Uppercase Class or words between "class" and the name)

Generally in C#, there are no hard rules about casing of identifiers - 
Someclassname 
is as legal as someclassname, SomeClassName or SOMeclaSSNAme. There are 
Guidelines, 
but no hard rules.

Original comment by goo...@stum.de on 15 Oct 2009 at 8:06

GoogleCodeExporter commented 9 years ago
Actually my last comment should be "This should not be too hard" in 
retrospective. No 
idea how your parser works and if there are any exceptions to be aware of. One 
one 
caveat I know about: In C# it's legal to use keywords as identifiers if you put 
an @ in 
front of it, so this would be legal (although discouraged):
int @class = 13;

Not sure how your lexer works and how much work it would be to take care of the 
exceptions.

Original comment by goo...@stum.de on 15 Oct 2009 at 8:10

GoogleCodeExporter commented 9 years ago
Coloring rules:

All pascal case words after "new", "class" and "interface" but before "{" 
should be colored as types. All other pascal words should be colored as methods.

Original comment by jonas.ga...@gmail.com on 5 Nov 2010 at 1:04