From 64ac81bf2024e2e563a7a5f4284dccb92c3b5c56 Mon Sep 17 00:00:00 2001 From: vendethiel Date: Wed, 30 Dec 2015 20:52:16 +0100 Subject: [PATCH] Start working on type ascriptions --- src/ast.ls | 6 +++++- src/grammar.ls | 1 + src/lexer.ls | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ast.ls b/src/ast.ls index ca16730bf..5a03df23d 100644 --- a/src/ast.ls +++ b/src/ast.ls @@ -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) @@ -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 diff --git a/src/grammar.ls b/src/grammar.ls index dc4e8f2a0..d61c5976a 100644 --- a/src/grammar.ls +++ b/src/grammar.ls @@ -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 diff --git a/src/lexer.ls b/src/lexer.ls index 02b515d02..0a8ef974d 100644 --- a/src/lexer.ls +++ b/src/lexer.ls @@ -652,6 +652,8 @@ exports <<< @adi! val = 'prototype' tag = 'ID' + case '@:' + tag = 'ASCR' case '=>' @unline! @fset 'for' false @@ -1343,6 +1345,7 @@ SYMBOL = // | \([^\n\S]*\) # call | [!=]==? # strict equality, deep equals | !?\~= # fuzzy equality +| @: # type ascription | @@? # this / constructor | <\[(?:[\s\S]*?\]>)? # words | <<<