Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2017-02

IsValidIdent() and identifiers escaped with &

6 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Howard Page-Clark

Consider this program, which returns False:

program Project1;
uses sysutils;
var
   &begin: boolean;
begin
   &begin:=IsValidIdent('&begin');
   WriteLn('IsValidIdent(''&begin'') evaluates to ', &begin);
end.

Should sysutils.IsValidIdent() be updated to return True in this case?

Jürgen Hestermann
to Howard Page-Clark
Howard Page-Clark wrote
var &begin: boolean;

Is that a valid identifier?
Here
http://wiki.lazarus.freepascal.org/Identifiers
it says:

Rules for identifiers:

* Must begin with a letter from the English alphabet or an underscore (_).
* Can be followed by alphanumeric characters (alphabetic characters and numerals), or the underscore (_).
* May not contain special characters, such as:

~ ! @ # $ % ^ & * ( ) + ` - = { } [ ] : " ; ' < > ? , . / | \

Mattias Gaertner
to Howard Page-Clark: Consider this program, which returns False: program Project1; uses sysutils; var &begin:…
Show quoted text 15 lines
Consider this program, which returns False: program Project1; uses sysutils; var &begin: boolean; begin &begin:=IsValidIdent('&begin'); WriteLn('IsValidIdent(''&begin'') evaluates to ', &begin); end. Should sysutils.IsValidIdent() be updated to return True in this case?

The identifier is "begin". The & is an operator.
For example:

type
  TMyEnum = (&begin);
var
  e: TMyEnum = &begin;
begin
  writeln(e);
end.

gives "begin".

Mattias

Sven Barth
to Jürgen Hestermann: Is that a valid identifier? Here http://wiki.lazarus.freepascal.org/Identifiers it says:…
"Jürgen Hestermann" wrote 18 lines
Am 2017-02-05 um 15:24 schrieb Howard Page-Clark: > > var > &begin: boolean; Is that a valid identifier? Here http://wiki.lazarus.freepascal.org/Identifiers it says: Rules for identifiers: Must begin with a letter from the English alphabet or an underscore (_). Can be followed by alphanumeric characters (alphabetic characters and

numerals), or the underscore (_).

May not contain special characters, such as: ~ ! @ # $ % ^ & * ( ) + ` - = { } [ ] : " ; ' < > ? , . / | \

http://freepascal.org/docs-html/current/ref/refse4.html#x16-150001.4

Regards,
Sven

Jürgen Hestermann
to Sven Barth
Sven Barth wrote 14 lines
> Is that a valid identifier? > Here > http://wiki.lazarus.freepascal.org/Identifiers > it says: > Rules for identifiers: > Must begin with a letter from the English alphabet or an underscore (_). > Can be followed by alphanumeric characters (alphabetic characters and numerals), or the underscore (_). > May not contain special characters, such as: > > ~ ! @ # $ % ^ & * ( ) + ` - = { } [ ] : " ; ' < > ? , . / | \ http://freepascal.org/docs-html/current/ref/refse4.html#x16-150001.4

Strange!
Why was it added to use reserved words as an identifier? What is the use of that?
It seems http://wiki.lazarus.freepascal.org/Identifiers needs an update too.

Michael Van Canneyt
to Jürgen Hestermann
Jürgen Hestermann wrote 20 lines
Am 2017-02-05 um 20:26 schrieb Sven Barth: > > > Is that a valid identifier? > > Here > > http://wiki.lazarus.freepascal.org/Identifiers > > it says: > > Rules for identifiers: > > Must begin with a letter from the English alphabet or an underscore (_). > > Can be followed by alphanumeric characters (alphabetic characters and > numerals), or the underscore (_). > > May not contain special characters, such as: > > > > ~ ! @ # $ % ^ & * ( ) + ` - = { } [ ] : " ; ' < > ? , . / | \ > > http://freepascal.org/docs-html/current/ref/refse4.html#x16-150001.4 > Strange! Why was it added to use reserved words as an identifier? What is the use of that?

For example:

If you import a SOAP webservice or REST API, often reserved words are used in the names of arguments or properties.
This trick allows to use them as-is in the pascal proxy classes.

Michael.