Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C#/Java Syntax issue #70

Open
GoogleCodeExporter opened this issue Jan 14, 2016 · 14 comments
Open

C#/Java Syntax issue #70

GoogleCodeExporter opened this issue Jan 14, 2016 · 14 comments

Comments

@GoogleCodeExporter
Copy link

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 [email protected] on 24 Mar 2009 at 12:45

@GoogleCodeExporter
Copy link
Author

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 [email protected] on 19 May 2009 at 5:22

@GoogleCodeExporter
Copy link
Author

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 [email protected] on 20 May 2009 at 11:03

@GoogleCodeExporter
Copy link
Author

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 [email protected] on 20 May 2009 at 7:19

@GoogleCodeExporter
Copy link
Author

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 [email protected] on 21 May 2009 at 10:59

@GoogleCodeExporter
Copy link
Author

In C#, properties and methods should be UpperCamelCase.

Original comment by [email protected] on 14 Aug 2009 at 7:43

@GoogleCodeExporter
Copy link
Author

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 [email protected] on 15 Aug 2009 at 4:53

@GoogleCodeExporter
Copy link
Author

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 [email protected] on 15 Aug 2009 at 5:25

@GoogleCodeExporter
Copy link
Author

Does anyone know how to distinguish method names from type names in C# at a 
purely
lexical level?

Original comment by [email protected] on 17 Aug 2009 at 3:48

@GoogleCodeExporter
Copy link
Author

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 [email protected] on 17 Aug 2009 at 3:58

@GoogleCodeExporter
Copy link
Author

> 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 [email protected] on 18 Aug 2009 at 2:12

@GoogleCodeExporter
Copy link
Author

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 [email protected] on 18 Aug 2009 at 5:02

@GoogleCodeExporter
Copy link
Author

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 [email protected] on 15 Oct 2009 at 8:06

@GoogleCodeExporter
Copy link
Author

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 [email protected] on 15 Oct 2009 at 8:10

@GoogleCodeExporter
Copy link
Author

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 [email protected] on 5 Nov 2010 at 1:04

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant