FascinatedBox / lily

Interpreted language focused on expressiveness and type safety.

Home Page:http://lily-lang.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

String literal import paths

FascinatedBox opened this issue · comments

There are currently two kinds of import paths:

import xyz

and

import some_dir/xyz

Paths are currently limited to being identifiers. As a result, it's not possible to have paths that are relative, or paths that include a space.

Some time ago I thought this would be as easy as import ../../some_dir/xyz. However, after experimenting with the interpreter, it turns out that the above is not as easy to do as expected. In particular, the case of import (...) somepath means that, internally, the lexer will see the first "token" of the path before path scanning can scoop it all up.

To allow relative paths as well as spaces in paths, I've decided to take the advice of #336 and allow import paths to take a string. However, there will be some caveats:

  • The string must be this kind: " ... " and not this kind: """ ... """. No multi-line strings, even if the string doesn't span multiple lines.

  • The string must not have invalid or escape characters

  • The string will still replace / with the appropriate path character.

  • The string must have at least one non-identifier character, or a slash. Simple paths like import foo will be required to be non-quoted. This is to simplify the syntax: Only quote when it's necessary for more interesting paths.

Since this will adjust the import syntax, I'll take care of this before swinging over to target #338.

The patch for this won't be dropping the old "slashed paths" syntax of the language immediately. But the syntax will be considered deprecated. Some time before 1.3 is released, unquoted slashed paths will be removed from the language.

I don't like to break syntax, but this is a rarer case (slashed paths), and I don't want to see the language accumulate cruft.