Skip to content

Commit

Permalink
Remove SynMatchPattern
Browse files Browse the repository at this point in the history
  • Loading branch information
vipentti committed Dec 22, 2023
1 parent d9b6beb commit 2c4c94b
Show file tree
Hide file tree
Showing 5 changed files with 1,069 additions and 1,322 deletions.
33 changes: 0 additions & 33 deletions src/Visp.Compiler/Parser.fsy
Original file line number Diff line number Diff line change
Expand Up @@ -1338,39 +1338,6 @@ match:
| syn_pat LPAREN WHEN expr RPAREN expr_list
{ SynMatch.SynMatch($1, Some($4), $6, lhs parseState) }

match_tuple_list: rev_match_tuple_list %prec prec_match_tuple_list { List.rev $1 }
rev_match_tuple_list:
| match_pattern %prec prec_match_pattern { [$1] }
| rev_match_tuple_list COMMA match_pattern %prec prec_match_tuple_list
{ $3 :: (SynMatchPattern.Trivia(SynPatternTriviaKind.Comma, (rhs parseState 2))) :: $1 }
| rev_match_tuple_list DOT match_pattern %prec prec_match_tuple_list
{ $3 :: (SynMatchPattern.Trivia(SynPatternTriviaKind.Dot, (rhs parseState 2))) :: $1 }
| rev_match_tuple_list COLON_COLON match_pattern %prec prec_match_tuple_list
{ $3 :: (SynMatchPattern.Trivia(SynPatternTriviaKind.ColonColon, (rhs parseState 2))) :: $1 }
| rev_match_tuple_list match_pattern %prec prec_match_tuple_list
{ $2 :: $1 }

match_pattern:
| constant %prec prec_match_pattern_const { SynMatchPattern.Const(fst $1, snd $1) }
| symbol {
let text = $1
if ((Syntax.textOfSymbol text) = "_") then
SynMatchPattern.Discard (lhs parseState)
else
SynMatchPattern.Symbol (text, lhs parseState) }
| LBRACKET RBRACKET
{ SynMatchPattern.Trivia(SynPatternTriviaKind.Brackets, (lhs parseState)) }
| LPAREN LBRACKET RBRACKET RPAREN
{ SynMatchPattern.Trivia(SynPatternTriviaKind.Brackets, (lhs parseState)) }
| LPAREN BANG_TUPLE match_tuple_list RPAREN
{ SynMatchPattern.Tuple ($3, lhs parseState) }
| LPAREN match_tuple_list RPAREN
{ SynMatchPattern.List($2, lhs parseState) }

syn_pat_list: rev_syn_pat_list { List.rev $1 }
rev_syn_pat_list:
| syn_pat %prec prec_match_pattern { [$1] }

syn_trivia_kind:
| COMMA { SynPatternTriviaKind.Comma }
| DOT { SynPatternTriviaKind.Dot }
Expand Down
2,316 changes: 1,068 additions & 1,248 deletions src/Visp.Compiler/Syntax/FsLexYaccOutput/Parser.fs

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions src/Visp.Compiler/Syntax/FsLexYaccOutput/Parser.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,6 @@ type nonTerminalId =
| NONTERM_rev_match_list
| NONTERM_match_start
| NONTERM_match
| NONTERM_match_tuple_list
| NONTERM_rev_match_tuple_list
| NONTERM_match_pattern
| NONTERM_syn_pat_list
| NONTERM_rev_syn_pat_list
| NONTERM_syn_trivia_kind
| NONTERM_syn_pat_trivia
| NONTERM_syn_pat_trivia_list
Expand Down
29 changes: 1 addition & 28 deletions src/Visp.Compiler/Syntax/SynWriter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -619,35 +619,8 @@ module Write =
w
WriteState.Body
newlineIndent
(fun w st (SynMatch.SynMatch(pat, cond, body, _)) ->
let rec writeMatchPattern w _ pat =
match pat with
// | SynMatchPattern.CommaOrDot _ -> failwith "not supported"
| SynMatchPattern.Trivia(kind, _) ->
match kind with
| SynPatternTriviaKind.Brackets -> string w "[]"
| SynPatternTriviaKind.ColonColon -> string w "::"
| SynPatternTriviaKind.Comma
| SynPatternTriviaKind.Dot -> string w ","

()
| SynMatchPattern.Const(cnst, _) ->
writeConst w false cnst
()
| SynMatchPattern.Discard _ -> string w "_"
| SynMatchPattern.Symbol(sym, _) -> symbol w sym true
| SynMatchPattern.Tuple(pats, _) ->
string w "("
writeInlineCommaSeparated w writeMatchPattern pats
string w ")"
| SynMatchPattern.List(pats, _) ->
string w "("
writeInlineSpaceSeparated w writeMatchPattern pats
string w ")"


(fun w _ (SynMatch.SynMatch(pat, cond, body, _)) ->
string w "| "
//writeMatchPattern w st pat
synPat w pat
string w " "

Expand Down
8 changes: 0 additions & 8 deletions src/Visp.Compiler/Syntax/Syntax.fs
Original file line number Diff line number Diff line change
Expand Up @@ -462,14 +462,6 @@ and [<NoEquality; NoComparison; RequireQualifiedAccess>] SynPat =
| IsInst of pat: SynType * range: range
| As of lhsPat: SynPat * rhsPat: SynPat * range: range

and [<RequireQualifiedAccess>] SynMatchPattern =
| Const of value: SynConst * range: range
| Tuple of pats: SynMatchPattern list * range: range
| List of pats: SynMatchPattern list * range: range
| Symbol of name: SynSymbol * range: range
| Discard of range: range
| Trivia of kind: SynPatternTriviaKind * range: range

and SynMemberGet =
| SynMemberGet of args: SynPat * exprs: SynExpr list * range: range

Expand Down

0 comments on commit 2c4c94b

Please sign in to comment.