diff --git a/entity/misc.go b/entity/misc.go index 78f6bb9..2608c2a 100644 --- a/entity/misc.go +++ b/entity/misc.go @@ -81,7 +81,7 @@ type Case struct { Expression } func (this *Case) String () string { - return fmt.Sprintf("| ", this.Declaration, this.Expression) + return fmt.Sprint("| ", this.Declaration, this.Expression) } // Operator determines which operation to apply to a value in an operation diff --git a/parser/fspl/expression.go b/parser/fspl/expression.go index 059f0ef..784f579 100644 --- a/parser/fspl/expression.go +++ b/parser/fspl/expression.go @@ -578,6 +578,7 @@ func (this *treeParser) parseMatch () (*entity.Match, error) { err = this.ExpectValue(lexer.Ident, "in") if err != nil { return nil, err } + this.Next() for this.Is(lexer.Symbol) && this.ValueIs("|") { cas, err := this.parseCase() @@ -598,7 +599,6 @@ func (this *treeParser) parseCase () (*entity.Case, error) { this.Next() cas.Declaration, err = this.parseDeclaration() if err != nil { return nil, err } - this.Next() cas.Expression, err = this.parseExpression() if err != nil { return nil, err } diff --git a/parser/fspl/parser_test.go b/parser/fspl/parser_test.go index 2f7c70f..e1db9df 100644 --- a/parser/fspl/parser_test.go +++ b/parser/fspl/parser_test.go @@ -71,7 +71,8 @@ testString (test, - [math] = {[+ 3 4 2 [/ 24 3]] [|| 3 [<< 56 4]] [++ 3] [-- 3] [- 3 1]} - [ifElse]:Int = if true then 4 else 5 - [dangleElse]:Int = if true then if false then 3 else 5 -- [loop]:Int = {i:Int=0 if [< i 3] then return 1 loop {[print 3] if [> i 3] then break 0 i=[++ i]}}`, +- [loop]:Int = {i:Int=0 if [< i 3] then return 1 loop {[print 3] if [> i 3] then break 0 i=[++ i]}} +- [matchToInt u:(| Int F64 F32 Int64 Int32)]:Int = match u on | u:Int u | u:F64 [~ Int u]`, // input ` [var] = sdfdf @@ -117,6 +118,9 @@ testString (test, i = [++ i] } } +[matchToInt u:(| Int F64 F32 Int64 Int32)]:Int = match u in + | u:Int u + | u:F64 [~Int u] `) }