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

Start working on type ascriptions #803

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/ast.ls
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,8 @@ class exports.Var extends Atom

maybe-key: -> Key(@value) <<< {@line}

set-type: (@type) -> this

var-name: ::show

compile: (o) -> sn(this, if @temp then o.scope.free @value else @value)
Expand Down Expand Up @@ -1915,7 +1917,9 @@ class exports.Fun extends Node
vr = v
else if df
assigns.push Assign vr, p.second, \=, p.op, true
names.push (scope.add vr.value, \arg, p), ', '
names.push (scope.add vr.value, \arg, p)
names.push " : #that" if vr.type?
names.push ', '
if rest
while splace-- then rest.unshift Arr!
assigns.push Assign Arr(rest), Literal \arguments
Expand Down
1 change: 1 addition & 0 deletions src/grammar.ls
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ bnf =
ArgList:
o '' -> []
o 'Arg' -> [$1]
o 'Arg ASCR ID' -> [$1.set-type $3]
o 'ArgList , Arg' -> $1 ++ $3
o 'ArgList OptComma NEWLINE Arg' -> $1 ++ $4
o 'ArgList OptComma INDENT ArgList OptComma DEDENT' ditto
Expand Down
3 changes: 3 additions & 0 deletions src/lexer.ls
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,8 @@ exports <<<
@adi!
val = 'prototype'
tag = 'ID'
case '@:'
tag = 'ASCR'
case '=>'
@unline!
@fset 'for' false
Expand Down Expand Up @@ -1343,6 +1345,7 @@ SYMBOL = //
| \([^\n\S]*\) # call
| [!=]==? # strict equality, deep equals
| !?\~= # fuzzy equality
| @: # type ascription
| @@? # this / constructor
| <\[(?:[\s\S]*?\]>)? # words
| <<<<? # import
Expand Down