Skip to content

Commit

Permalink
Merge pull request #164 from faultyserver/feature/paths_in_instantiation
Browse files Browse the repository at this point in the history
Closes #152. Allow Paths as Instantiation type names.
  • Loading branch information
faultyserver authored Feb 21, 2018
2 parents a773676 + 51bd978 commit 56d3726
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 10 additions & 2 deletions spec/syntax/parser_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ describe "Parser" do



# Type initialization
# Type instantiation

# Instances of types are created with a percent characeter and brace syntax
# akin to blocks.
Expand Down Expand Up @@ -1151,7 +1151,7 @@ describe "Parser" do
{}
)

# The type can be either a Const or an interpolation. Any interpolation is
# The type can be either a Const, a Path or an interpolation. Any interpolation is
# valid, and may span multiple lines.
it_parses %q(%<thing>{}), Instantiation.new(i(Call.new(nil, "thing")))
it_parses %q(%<@type>{}), Instantiation.new(i(iv("type")))
Expand All @@ -1162,6 +1162,14 @@ describe "Parser" do
type
)>{}
), Instantiation.new(i(Call.new(nil, "type")))
it_parses %q(%IO.FileDescriptor{}), Instantiation.new(Call.new(c("IO"), "FileDescriptor"))
it_parses %q(%A.B.C.D{}), Instantiation.new(Call.new(Call.new(Call.new(c("A"), "B"), "C"), "D"))
# Type paths must only contain constants
it_does_not_parse %q(%A.b{})
it_does_not_parse %q(%a.B{})
it_does_not_parse %q(%A.b.C{})
it_does_not_parse %q(%A.B.c{})
it_does_not_parse %q(%a.b{})

# Any other node is invalid as a type specification.
it_does_not_parse %q(%nil{})
Expand Down
10 changes: 1 addition & 9 deletions src/myst/syntax/parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -987,15 +987,7 @@ module Myst

def parse_instantiation
start = expect(Token::Type::MODULO)
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
type = parse_type_path

inst = Instantiation.new(type).at(start.location)
skip_space
Expand Down

0 comments on commit 56d3726

Please sign in to comment.