Add match test to parser, fixed parsing and stringing of match
This commit is contained in:
parent
ab8db825c0
commit
965adb3de6
|
@ -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
|
||||
|
|
|
@ -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 }
|
||||
|
||||
|
|
|
@ -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]
|
||||
`)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue