deprecated syntax is inconsistent.

classic Classic list List threaded Threaded
28 messages Options
12
Reply | Threaded
Open this post in threaded view
|

deprecated syntax is inconsistent.

Graeme Geldenhuys-2

Hi,

Why is the usage of 'deprecated' inconsistent, depending where you use it.
I'm using the ObjFPC compiler mode.

  TRGBTriple = record
    Red: word;
    Green: word;
    Blue: word;
    Alpha: word;
  end deprecated;        // <<- Note: no semi-colon after 'end'.

vs

  TRGBTriple = record
    Red: word;
    Green: word;
    Blue: word;
    Alpha: word;
  end; deprecated;


The last example makes more sense because it is a type of hint/modifier
(similar to override, virtual etc), and that is how it is used in
functions/procedures?

eg:
  procedure MyProc; deprecated;
  function CalcMe(AParam: integer): boolean; deprecated;



Regards,
  - Graeme -

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://opensoft.homeip.net/fpgui/

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: deprecated syntax is inconsistent.

Marco van de Voort
In our previous episode, Graeme Geldenhuys said:
>
> Why is the usage of 'deprecated' inconsistent, depending where you use it.

As always, because Delphi does. See the recently submitted fcl-passrc
bugreports for more examples.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: deprecated syntax is inconsistent.

Graeme Geldenhuys-2
Marco van de Voort het geskryf:
> In our previous episode, Graeme Geldenhuys said:
>> Why is the usage of 'deprecated' inconsistent, depending where you use it.
>
> As always, because Delphi does. See the recently submitted fcl-passrc
> bugreports for more examples.


Shouldn't that inconsistent syntax be limited to the Delphi compiler mode
only? Like many other things are.



Regards,
  - Graeme -

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://opensoft.homeip.net/fpgui/

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: deprecated syntax is inconsistent.

Marco van de Voort
In our previous episode, Graeme Geldenhuys said:
> > As always, because Delphi does. See the recently submitted fcl-passrc
> > bugreports for more examples.
>
> Shouldn't that inconsistent syntax be limited to the Delphi compiler mode
> only? Like many other things are.

IMHO no.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: deprecated syntax is inconsistent.

Jonas Maebe-2
In reply to this post by Graeme Geldenhuys-2

On 29 Apr 2010, at 10:52, Graeme Geldenhuys wrote:

> Marco van de Voort het geskryf:
>> In our previous episode, Graeme Geldenhuys said:
>>> Why is the usage of 'deprecated' inconsistent, depending where you  
>>> use it.
>>
>> As always, because Delphi does. See the recently submitted fcl-passrc
>> bugreports for more examples.
>
> Shouldn't that inconsistent syntax be limited to the Delphi compiler  
> mode
> only? Like many other things are.

The general reason for putting modifiers before the semicolon in case  
of type declarations is that there can be ambiguity in other cases  
(modifiers are not reserved words, so in principle the modifier can  
also be used as a type or variable name).

In case procedures/function/method declarations, this is not the case  
since an identifier can never follow a function/procedure/method  
declaration: they have to be preceded either by
* "procedure"/"function" for routine declarations
* by "var"/"const"/"type" for var/const/type declarations
* by "property" for property declarations
* by "public"/"(strict) protected"/"(strict) private for field  
declarations

Conversely, adding it before the semicolon in case of procedure/
function declarations would be inconsistent with how other modifiers  
have always been used there.

So no, it should not be changed in FPC mode like many other things  
have been changed in the past, because it would have to be changed  
back later anyway (just like http://wiki.freepascal.org/User_Changes_Trunk#Passing_derived_classes_to_var-_and_out-parameters 
, http://wiki.freepascal.org/User_Changes_2.4.0#Order_of_field_and_method.2Fproperty_declarations 
  etc)


Jonas
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: deprecated syntax is inconsistent.

Graeme Geldenhuys-2
Jonas Maebe het geskryf:
>
> Conversely, adding it before the semicolon in case of procedure/
> function declarations would be inconsistent with how other modifiers  
> have always been used there.

I don't have problems with it's usage in procedures, functions or methods.
The modifier appearing after the semicolon seems like the correct syntax,
and that is how 'virtual', 'override' etc is used. This I think is correct
and should stay as is.


The issue I do have is using deprecated in a type declaration, where it
appears *before* the semicolon. This just doesn't look or feel right. It
affects variable, class and record declarations. This is what I was talking
about and think should be fixed in objfpc mode and inconsistent usage
limited to only delphi mode.


Regards,
  - Graeme -

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://opensoft.homeip.net/fpgui/

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: deprecated syntax is inconsistent.

Michael Van Canneyt


On Thu, 29 Apr 2010, Graeme Geldenhuys wrote:

> Jonas Maebe het geskryf:
>>
>> Conversely, adding it before the semicolon in case of procedure/
>> function declarations would be inconsistent with how other modifiers
>> have always been used there.
>
> I don't have problems with it's usage in procedures, functions or methods.
> The modifier appearing after the semicolon seems like the correct syntax,
> and that is how 'virtual', 'override' etc is used. This I think is correct
> and should stay as is.
>
>
> The issue I do have is using deprecated in a type declaration, where it
> appears *before* the semicolon. This just doesn't look or feel right. It
> affects variable, class and record declarations. This is what I was talking
> about and think should be fixed in objfpc mode and inconsistent usage
> limited to only delphi mode.

Jonas tried to explain that this is not possible.

Consider the following - what  you propose - statements:

Var
   A : Integer;
   deprecated : Boolean;

The compiler cannot decide whether the 'deprecated' is a modifier or the
name of a variable. Both are possible (deprecated is NOT a keyword) and
valid.

With the current syntax:

Var
   A : Integer deprecated;
   Deprecated : Boolean;

The compiler knows in both cases what is meant.

The matter could be resolved by making 'deprecated' and all other modifiers
into keywords, but that would be a major backwards incompatibility.


Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: deprecated syntax is inconsistent.

Graeme Geldenhuys-2
Michael Van Canneyt het geskryf:
>
> Jonas tried to explain that this is not possible.

Yes, but it is still very easy to detect the difference... I'll use your
example:


> Consider the following - what  you propose - statements:
>
> Var
>    A : Integer;
>    deprecated : Boolean;
>
> The compiler cannot decide whether the 'deprecated' is a modifier or the

Yes it can, because in your example 'deprecated' is followed by a colon and
a type.

 Var
    A : Integer; deprecated;

This is *not* ambiguous at all, because the hint directive is immediately
followed by a semicolon. That is not the case in a type declaration like
you showed. A pretty clear difference.


>
> Var
>    A : Integer deprecated;
>    Deprecated : Boolean;

My suggestion could still work...

 Var
    A: Integer; deprecated;
    Deprecated: Boolean;

One is a hint directive because it follows a (type with) semicolon and is
immediately followed by another semicolon.  The type declaration is
followed by a colon and a type. This looks pretty clear to me, and not
ambiguous at all.



Regards,
  - Graeme -

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://opensoft.homeip.net/fpgui/

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: deprecated syntax is inconsistent.

Jonas Maebe-2

On 29 Apr 2010, at 12:00, Graeme Geldenhuys wrote:

> Michael Van Canneyt het geskryf:
>> Consider the following - what  you propose - statements:
>>
>> Var
>>   A : Integer;
>>   deprecated : Boolean;
>>
>> The compiler cannot decide whether the 'deprecated' is a modifier  
>> or the
>
> Yes it can, because in your example 'deprecated' is followed by a  
> colon and
> a type.
>
> Var
>    A : Integer; deprecated;
>
> This is *not* ambiguous at all,

It is ambiguous to the compiler, as is explained in one of the links I  
posted previously: http://wiki.freepascal.org/User_Changes_2.4.0#Order_of_field_and_method.2Fproperty_declarations

"The above code was ambiguous to the compiler, because when it  
finished parsing the property, it could not decide based on seeing the  
default token whether this meant that the property was a default  
property, or whether a field coming after the property was called  
"default". It did find this out after it had parsed the default token  
(because the next token was a ":" rather than a ";"), but by then it  
was too late."

The compiler uses only a single lookahead token, while disambiguating  
your example would require two.


Jonas

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: deprecated syntax is inconsistent.

ik-6
On Thu, Apr 29, 2010 at 13:39, Jonas Maebe <[hidden email]> wrote:

On 29 Apr 2010, at 12:00, Graeme Geldenhuys wrote:

Michael Van Canneyt het geskryf:
Consider the following - what  you propose - statements:


Var
 A : Integer;
 deprecated : Boolean;

The compiler cannot decide whether the 'deprecated' is a modifier or the

Yes it can, because in your example 'deprecated' is followed by a colon and
a type.

Var
  A : Integer; deprecated;

This is *not* ambiguous at all,

It is ambiguous to the compiler, as is explained in one of the links I posted previously: http://wiki.freepascal.org/User_Changes_2.4.0#Order_of_field_and_method.2Fproperty_declarations

"The above code was ambiguous to the compiler, because when it finished parsing the property, it could not decide based on seeing the default token whether this meant that the property was a default property, or whether a field coming after the property was called "default". It did find this out after it had parsed the default token (because the next token was a ":" rather than a ";"), but by then it was too late."

The compiler uses only a single lookahead token, while disambiguating your example would require two.

I probably missing something here but how does the compiler knows about override, cdecl etc... directives in one pass ?
 


Jonas


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Ido

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: deprecated syntax is inconsistent.

Marco van de Voort
In our previous episode, ik said:

> > The compiler uses only a single lookahead token, while disambiguating your
> > example would require two.
> >
>
> I probably missing something here but how does the compiler knows about
> override, cdecl etc... directives in one pass ?

A procedure declaration never is followed by an identifier, so the ambiguity
doesn't exist there. (at least not after the 2.4.0 fixes)
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: deprecated syntax is inconsistent.

Graeme Geldenhuys-2
In reply to this post by Jonas Maebe-2
On 29 April 2010 12:39, Jonas Maebe <[hidden email]> wrote:
>
> The compiler uses only a single lookahead token, while disambiguating your
> example would require two.

I did look at the links you posted and still couldn't see the problem.
The paragraph above gives the key information -  the FPC parses only
uses a single lookahead.

This still seems rather trivial to fix - resulting in a bit more sane
syntax. Simply keep an extra backpointer, so that when the compiler
finally knows what 'default' (wiki example) or 'deprecated' (my
example) relates to, that it can still apply the hint directive by
using the backpointer.  Or (like I have seen in many pascal parsers
before), allow for more than one lookahead. I have frequently seen
object pascal parsers allow for 3 lookaheads (parser available in
PSP/PWU web framework does this).

It seems rather silly to limit the syntax (wiki example) or force a
rather weird inconsistent syntax (my example) on the developers when
the parser could easily be fixed.

More examples:
fpdoc often uses back pointers to write LaTeX or IPF output. Also, it
would imagine the parsing would be pretty similar to what FPC already
does with:  ....; virtual; abstract;
After the method declaration, it has to keep track of that so it can
apply 'virtual', and then again 'abstract' to it.

Out of interest, I am looking at the fcl-passrc to see if I can modify
it to work with my suggested syntax. I don't know the code at all, so
it might take longer than normal. But it should show it is quite
possible.

--
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: deprecated syntax is inconsistent.

Michael Van Canneyt


On Thu, 29 Apr 2010, Graeme Geldenhuys wrote:

> On 29 April 2010 12:39, Jonas Maebe <[hidden email]> wrote:
>>
>> The compiler uses only a single lookahead token, while disambiguating your
>> example would require two.
>
> I did look at the links you posted and still couldn't see the problem.
> The paragraph above gives the key information -  the FPC parses only
> uses a single lookahead.

As far as I remember, this was one of the key strengths of the Pascal
Language: that parsing is possible using a single lookahead token.
(it makes for faster parsing)

The other parsers simply parse the source 'wrong', hence they need
more than one lookahead.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: deprecated syntax is inconsistent.

Florian Klämpfl
Michael Van Canneyt schrieb:

>
>
> On Thu, 29 Apr 2010, Graeme Geldenhuys wrote:
>
>> On 29 April 2010 12:39, Jonas Maebe <[hidden email]> wrote:
>>>
>>> The compiler uses only a single lookahead token, while disambiguating
>>> your
>>> example would require two.
>>
>> I did look at the links you posted and still couldn't see the problem.
>> The paragraph above gives the key information -  the FPC parses only
>> uses a single lookahead.
>
> As far as I remember, this was one of the key strengths of the Pascal
> Language: that parsing is possible using a single lookahead token.

Having a bigger lookahead makes a lot more things far more complex
epecially in combination with include files, macros, generics.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: deprecated syntax is inconsistent.

Graeme Geldenhuys-2
On 29 April 2010 14:51, Florian Klaempfl <[hidden email]> wrote:
>
> Having a bigger lookahead makes a lot more things far more complex
> epecially in combination with include files, macros, generics.

Why?  You only apply the extra lookaheads where needed (code that
could be ambiguous). All other parts of the code will be parsed as
normal - as it is done now.

So far I know of only two examples where extra lookaheads need to be used.
  * wiki example where 'default' is used
  * my example to fix the inconsistent syntax for hint directives (deprecated).

--
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: deprecated syntax is inconsistent.

Graeme Geldenhuys-2
In reply to this post by Michael Van Canneyt
On 29 April 2010 14:48, Michael Van Canneyt <[hidden email]> wrote:
>
> As far as I remember, this was one of the key strengths of the Pascal
> Language: that parsing is possible using a single lookahead token.
> (it makes for faster parsing)

And because of that age old statement, we now have to live with
inconsistent syntax. I'd rather vote for consistent syntax compared to
loosing a millisecond here and there while parsing.

The 'Hint Directive' syntax is so bad that it couldn't even be
described in the documentation via the syntax diagrams (Language
Reference - section 1.5). That says a lot.


--
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: deprecated syntax is inconsistent.

Florian Klämpfl
In reply to this post by Graeme Geldenhuys-2
Graeme Geldenhuys schrieb:
> On 29 April 2010 14:51, Florian Klaempfl <[hidden email]> wrote:
>> Having a bigger lookahead makes a lot more things far more complex
>> epecially in combination with include files, macros, generics.
>
> Why?  

Because you've always to take care of the possible extra lookahead. The
scanner knows nothing about syntax.

> You only apply the extra lookaheads where needed (code that
> could be ambiguous). All other parts of the code will be parsed as
> normal - as it is done now.
>
> So far I know of only two examples where extra lookaheads need to be used.
>   * wiki example where 'default' is used
>   * my example to fix the inconsistent syntax for hint directives (deprecated).
>

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: deprecated syntax is inconsistent.

Marco van de Voort
In reply to this post by Graeme Geldenhuys-2
In our previous episode, Graeme Geldenhuys said:
> > Language: that parsing is possible using a single lookahead token.
> > (it makes for faster parsing)
>
> And because of that age old statement, we now have to live with
> inconsistent syntax.

And get better quality errormessages in return. Way more important IMHO.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: deprecated syntax is inconsistent.

Aleksa Todorovic-2
In reply to this post by Graeme Geldenhuys-2
During my experiments with FPC, I had to to exactly that - support two
lookahead symbols - to implement (in)famous semicolon before 'else'.
One of problems I had was combination of macros and include files with
two lookahead symbols - I "fixed" it in a dirty way, but I'm not
completely sure that solution covered all possible situations.

Just think of include directive which includes file in which there is
macro which expands to 'deprecated'. That wouldn't be that easy with
two lookahead symbols, because you would have to keep lots of data
about both symbols (they could be in two different files, for
example). Now, just think of refactoring in FPC on such low level -
doesn't smell good at all :-)

I would rather stick to on lookahead symbol even if that means
"inconsistent" (subject to this discussion) syntax.


On Thu, Apr 29, 2010 at 14:55, Graeme Geldenhuys
<[hidden email]> wrote:

> On 29 April 2010 14:51, Florian Klaempfl <[hidden email]> wrote:
>>
>> Having a bigger lookahead makes a lot more things far more complex
>> epecially in combination with include files, macros, generics.
>
> Why?  You only apply the extra lookaheads where needed (code that
> could be ambiguous). All other parts of the code will be parsed as
> normal - as it is done now.
>
> So far I know of only two examples where extra lookaheads need to be used.
>  * wiki example where 'default' is used
>  * my example to fix the inconsistent syntax for hint directives (deprecated).
>
> --
> Regards,
>  - Graeme -
>
>
> _______________________________________________
> fpGUI - a cross-platform Free Pascal GUI toolkit
> http://opensoft.homeip.net/fpgui/
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>



--
Aleksa Todorovic - Lead Programmer
Eipix Entertainment
www eipix com
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: deprecated syntax is inconsistent.

etrusco
In reply to this post by Michael Van Canneyt
On Thu, Apr 29, 2010 at 6:44 AM, Michael Van Canneyt
<[hidden email]> wrote:
> On Thu, 29 Apr 2010, Graeme Geldenhuys wrote:
>> Jonas Maebe het geskryf:
(...)

>
> Jonas tried to explain that this is not possible.
>
> Consider the following - what  you propose - statements:
>
> Var
>  A : Integer;
>  deprecated : Boolean;
>
> The compiler cannot decide whether the 'deprecated' is a modifier or the
> name of a variable. Both are possible (deprecated is NOT a keyword) and
> valid.
>
> With the current syntax:
>
> Var
>  A : Integer deprecated;
>  Deprecated : Boolean;
>
> The compiler knows in both cases what is meant.
>
> The matter could be resolved by making 'deprecated' and all other modifiers
> into keywords, but that would be a major backwards incompatibility.
>
>
> Michael.

But I firmly believe that the breakage would be really really minimal.
FPC had made backwards incompatible changes before... Please? ;)

Best regards,
Flávio
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
12