Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Paths as type names for instantiation. #152

Closed
faultyserver opened this issue Feb 9, 2018 · 0 comments
Closed

Allow Paths as type names for instantiation. #152

faultyserver opened this issue Feb 9, 2018 · 0 comments
Labels
bug.parser A bug specifically relating to the parser source code bug Generic label for bugs. Every bug should have this tag in addition to the more specific bug tag good first issue An issue that provides a good intro to working with the Myst codebase. Be helpful!
Milestone

Comments

@faultyserver
Copy link
Member

This issue has been marked as a "Good First Issue"! If you'd like to tackle this issue as your first contribution to the project, be sure to read the Get Involved section of the README for some help with how to get started.

Right now, the parser isn't able to understand type names for instantiations that include a namespace. For example, something like this:

%IO.FileDescriptor{}

would fail to parse, where the parser is expecting the opening curly brace after IO, rather than the dot that is actually given. A quick workaround for this is using a ValueInterpolation for the type, but I feel like this should be something that will be a common use case, and should be supported naturally.

This should be fairly simple to implement. Right now, the parser just checks for a single token for the type name:

type =
case current_token.type
when Token::Type::CONST
token = current_token
read_token
Const.new(token.value).at(token.location)
else
parse_value_interpolation
end

Instead, it should use a loop, checking for a CONST token, then also checking if the next token is a POINT. If it is, repeat the loop, otherwise break from the loop. This behavior was actually already implemented recently in the parse_type_path method, and should be re-used here instead of the case shown above.

However, parse_type_path will also need a little modification to move the ParseError about supertypes into parse_type_def rather than that method itself. This will require adding a check on current_token.type in parse_type_def as well. Once that is removed, parse_type_path should be good to go for use here with instantiations.

For specs, there's an existing section of tests around using a ValueInterpolation for the type name. A few similar specs should be added for using a namespaced type path as the name.

As always, if you have any questions, feel free to ask here or on Discord :)

@faultyserver faultyserver added bug Generic label for bugs. Every bug should have this tag in addition to the more specific bug tag bug.parser A bug specifically relating to the parser source code good first issue An issue that provides a good intro to working with the Myst codebase. Be helpful! labels Feb 9, 2018
faultyserver added a commit to faultyserver/myst that referenced this issue Feb 21, 2018
The type of an Instantiation can now be specified directly as a Type Path, without requiring that it be wrapped in a value interpolation.

For example, what would have been `%<IO.FileDescriptor>{}` can now just be written as `%IO.FileDescriptor{}`.
@faultyserver faultyserver added this to the Next milestone Feb 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug.parser A bug specifically relating to the parser source code bug Generic label for bugs. Every bug should have this tag in addition to the more specific bug tag good first issue An issue that provides a good intro to working with the Myst codebase. Be helpful!
Projects
None yet
Development

No branches or pull requests

1 participant