Skip to content

Commit

Permalink
core: add support for expressions as match clause targets
Browse files Browse the repository at this point in the history
  • Loading branch information
thesephist committed Apr 24, 2021
1 parent 6e26a93 commit 45a8319
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ BinaryExpr: (Atom | BinaryExpr) BinaryOp (Atom | BinaryExpr)
MatchExpr: (Atom | BinaryExpr) '::' '{' MatchClause* '}'
MatchClause: Atom '->' Expression
MatchClause: Expression '->' Expression
UnaryOp: (
Expand Down
2 changes: 1 addition & 1 deletion cmd/ink.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/thesephist/ink/pkg/ink"
)

const cliVersion = "0.1.7"
const cliVersion = "0.1.9"

const helpMessage = `
Ink is a minimal, powerful, functional programming language.
Expand Down
4 changes: 2 additions & 2 deletions pkg/ink/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ func parseExpression(tokens []Tok) (Node, int, error) {
// consuming dangling separator
return atom, idx, nil

case KeyValueSeparator, RightParen:
case RightParen, KeyValueSeparator, CaseArrow:
// these belong to the parent atom that contains this expression,
// so return without consuming token (idx - 1)
return atom, idx - 1, nil
Expand Down Expand Up @@ -758,7 +758,7 @@ func parseMatchBody(tokens []Tok) ([]MatchClauseNode, int, error) {
}

func parseMatchClause(tokens []Tok) (MatchClauseNode, int, error) {
atom, idx, err := parseAtom(tokens)
atom, idx, err := parseExpression(tokens)
if err != nil {
return MatchClauseNode{}, 0, err
}
Expand Down

0 comments on commit 45a8319

Please sign in to comment.