1

Closed

primary_expression broken

description

Hi,
 
I don't think cs.g can parse a primary expression like "value < 0" because it decides that its a identifier+generic_argument_list. (e.g., try the code "if (value < 0) { fred() } else { fred() };"). Also there is whitespace allowed in "# endregion". Here's my diff:
 
 
diff --git a/CSharpTranslator/antlr3/src/cs2j/CSharp/cs.g b/CSharpTranslator/antlr3/src/cs2j/CSharp/cs.g
index 54f421e..95c0e1c 100644
--- a/CSharpTranslator/antlr3/src/cs2j/CSharp/cs.g
+++ b/CSharpTranslator/antlr3/src/cs2j/CSharp/cs.g
@@ -135,7 +135,7 @@ primary_expression:

primary_expression_start:
    predefined_type            
  • | (identifier '<') => identifier generic_argument_list
  • | (identifier generic_argument_list) => identifier generic_argument_list
    | identifier ('::'   identifier)?
    | 'this' 
    | 'base'
    @@ -1142,7 +1142,7 @@ IDENTIFIER:
    IdentifierStart IdentifierPart* ;
    Pragma:
    //      ignore everything after the pragma since the escape's in strings etc. are different
  • '#' ('pragma' | 'region' | 'endregion' | 'line' | 'warning' | 'error') ~('\n'|'\r')* ('\r' | '\n')+
  • '#' TS* ('pragma' | 'region' | 'endregion' | 'line' | 'warning' | 'error') ~('\n'|'\r')* ('\r' | '\n')+
    { Skip(); } ;
    PREPROCESSOR_DIRECTIVE:
    | PP_CONDITIONAL;
     
    works for me, but I might be missing something better.

file attachments

Closed Nov 5, 2010 at 3:21 PM by anbrad
Fixed

comments

keving wrote Nov 2, 2010 at 4:34 PM

whoops, just noticed you already fixed the primary_expression in rev 59060 (same fix :)). Sorry about that. The white space between # and endregion still stands though.

wrote Nov 3, 2010 at 2:30 PM

keving wrote Nov 3, 2010 at 2:30 PM

OK, tripped over this again. I believe that fix has to be made throughout cs.g. See attached diff. Today I was failing on code like

if ((cref.Length < 2) || (cref[1] != ':')) { ......

cs.g is parsing ".Length < 2 ....." looking for a primary_expression_part -> access_identifier -> '.' type_or_generic, and type_or_generic is committing on "Length <"

wrote Nov 3, 2010 at 3:15 PM

anbrad wrote Nov 4, 2010 at 11:14 AM

Fixed (and #endif)



** Closed by anbrad 11/3/2010 8:15 AM

keving wrote Nov 4, 2010 at 11:14 AM

Please see ga.diff and comment written at Wed, 3:30pm. The '<' -> generic_argument_list fix is needed elsewhere too. thanks.

wrote Nov 5, 2010 at 3:21 PM

wrote Feb 14, 2013 at 6:00 PM

wrote May 16, 2013 at 8:25 AM