Skip to content

URI shorthands, allow reserved words. #3984

Closed
@lrhn

Description

@lrhn

I propose to allow reserved words to occur in unquoted URIs like any other identifier, because URI/file-system paths are not Dart code, and have no reason to be restricted by what happens to be Dart reserved words.

The proposal for URI shorthands allows sequence of tokens of the form: <dottedIdentifierList> ('/' <dottedIdentifierList>)* as unquoted imports.

It's a syntactic grammar, not a lexical grammar, which means that it does not affect tokenization, which would otherwise need to be context sensitive, and so it can reuse existing grammar productions.

An example import could be import somepackage/somelibrary;.

By using <dottedIdentifier> it only allows identifiers as parts of the path segments of the URI, which means that reserved words are not allowed.
Directory names and URI path segments have no notion of Dart identifiers, so linking the shorthand to only Dart identifiers seems unnecessarily restrictive, and may disallow using the syntax for a URIs like:

import package.for.dart/banana; // contains `for`.
import mypkg/src/new/library; // contains `new`

Dart reserved words are small common words that can occur as directory names, or as parts of dotted names (if anyone used dotted names).

It's easy to allow reserved words in unquoted URIs.
Rather than using <dottedIdentifierList>, use:

<dottedUriWords> ::= (<uriWord> '.')* <uriWord> 
<uriWord> ::= <identifier> | <RESERVED_WORD>

It does nothing except allow reserved words too. Grammatically it should be no harder to work with than <dottedIdentifierList>, and it allows users to not worry about whether their file paths contain Dart reserved words, which have no reason to be special in that context.

Further, if we add more reserved words in the future, we will not introduce compile-time errors if someone used that word as a directory name.

(Why only disallow reserved words, and not built-in identifiers? If it's because there is no reason to disallow built-in identifiers, then there is equally no reason to disallow reserved words.)

We should consider that URIs can be followed by if in conditional imports:

import foo/bar.
  if (condition) foo/qux;

A mistaken trailing ., like after bar above, would include the if in the URI, then complain about the (.
That won't happen if we don't allow reserved words. It also won't happen if we disallow internal whitespace (#3983), and it's not significantly different from import foo/bar. hide banana;, which we do allow.
I don't think it's a reason to not allow reserved words.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureProposed language feature that solves one or more problemsunquoted-urisThe unquoted URI feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions