# HG changeset patch # User Michael Pavone # Date 1429318247 25200 # Node ID 27477c8c2823d48b76b2342b527d8b0499c7bdcd # Parent f237d0cae58bec5d214672c12fa153fedeae6713 Add support for simple type annotations in parser and update llhello sample with a possible new low-level dialect syntax leveraging those annotations diff -r f237d0cae58b -r 27477c8c2823 modules/ast.tp --- a/modules/ast.tp Thu Apr 16 08:46:35 2015 -0700 +++ b/modules/ast.tp Fri Apr 17 17:50:47 2015 -0700 @@ -103,13 +103,18 @@ } } } - - symbol <- :_name { + + symbol:withType <- :_name :_type { #{ nodeType <- { _symbol } + type <- _type name <- _name stringIndent <- :indent { - name + _type value: :type { + name . " (" . type . ")" + } none: { + name + } } string <- { stringIndent: "" @@ -120,6 +125,10 @@ } } + symbol <- :_name { + symbol: _name withType: (option none) + } + funcall:withArgs:hasReceiver? <- :_tocall :_args :_receiver? { #{ nodeType <- { _call } diff -r f237d0cae58b -r 27477c8c2823 modules/parser.tp --- a/modules/parser.tp Thu Apr 16 08:46:35 2015 -0700 +++ b/modules/parser.tp Fri Apr 17 17:50:47 2015 -0700 @@ -756,6 +756,18 @@ } yield: { ast symbol: Name } + + typedsym <- matchOne: [ + match: Sym . hws . "(" . ws . Type . ws . ")" where: { + Sym <- match: symexpr + //TODO: Define full type syntax + Type <- match: symexpr + } yield: { + ast symbol: (Sym name) withType: (option value: Type) + } + symexpr + ] + namepart <- match: hws . Symbol . ":" where: { Symbol <- match: symexpr @@ -857,7 +869,7 @@ assignment <- match: ws . Symbol . hws . "<-" . Expr where: { Symbol <- matchOne: [ - symexpr + typedsym opsym ] Expr <- match: expr @@ -906,17 +918,30 @@ } yield: { Pre . Initial . Rest } + + typedarg <- match: Name . TypeInfo where: { + Name <- match: argname + TypeInfo <- matchOne: [ + match: hws . "(" . ws . Type . ws . ")" where: { + //TODO: Define full type syntax + Type <- match: symexpr + } yield: { option value: Type } + match: "" yield: { option none } + ] + } yield: { + ast symbol: Name withType: TypeInfo + } lambda <- match: hws . Arglist . hws . "{" . ws . Exprs . "}" where: { Arglist <- matchOne: [ match: ":" . First . Rest where: { - First <- match: symexpr - Rest <- zeroPlus: argname + First <- match: typedsym + Rest <- zeroPlus: typedarg } yield: { if: (Rest length) = 0 { Rest <- [] } - ":" . (First name) | Rest + ":" . First | Rest } match: "" yield: { [] } ]