dart-lang / language

Design of the Dart language
Other
2.65k stars 203 forks source link

EBNF for <identifier> #1331

Open kaby76 opened 3 years ago

kaby76 commented 3 years ago

I think the EBNF for <identifier> in the spec is wrong. It is stated as follows (not in Latex, but as it appears in the .pdf):

<identifier> ::= <IDENTIFIER> .

Notice the "." (DOT) after <IDENTIFIER>. This must a typo because <IDENTIFIER> is defined:

<IDENTIFIER> ::= <IDENTIFIER_START> <IDENTIFIER_PART>*

I know of no other language which defines an identifier with a trailing ".", whether a literal period, or a wildcard. This makes no sense. No other EBNF rule ends in a period, but it is here for <identifier>.

In any case, it would mean that no identifier could be only one character in length.

Can someone please comment?

(I am scraping the grammar from the spec. Afterward this, I will scrape the grammar from the implementation itself, because I do not trust what anyone ever types.)

lrhn commented 3 years ago

@eernstg Is this a leftover from a previous way of specifying the grammar?

kaby76 commented 3 years ago

I'm looking at line 14156 of https://raw.githubusercontent.com/dart-lang/language/master/specification/dartLangSpec.tex. For whatever reason, Github.com does not display the Latex file correctly, showing only 13564 lines. I know because I cloned this and I'm working on "master" aka "main" or whatever they want to call the main branch nowadays or past. I would provide a link to the exact line but Github is not working.

eernstg commented 3 years ago

True, we should remove that ., and it is on my todo list of small fixes. [Edit: https://github.com/dart-lang/language/pull/1328 fixed this, as well as another typo concerning ::=, has just been landed.]

@kaby76, if you are scraping the grammar from the spec in order to use it for actual parsing you may also wish to take a look at Dart.g, which is an ANTLR v4 specification that is kept in alignment with the grammar in the language specification, but also models things like the special treatment of yield and await when in a sync*, async, or async* function body.

The problem with github only showing about 14K lines from dartLangSpec.tex is known, it has been like that for quite a while. A reload may solve the problem, but not reliably. There should not be a conflict with the github limits. I've reported the issue recently, but not yet received a response.

kaby76 commented 3 years ago

take a look at Dart.g

Excelllent. I'll apply that to the grammar diff program I am writing.