Skip to content

Commit

Permalink
Parser cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vipentti committed Dec 19, 2023
1 parent 0dcf03f commit 374f284
Show file tree
Hide file tree
Showing 4 changed files with 1,819 additions and 2,122 deletions.
63 changes: 12 additions & 51 deletions src/Visp.Compiler/Parser.fsy
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ let mkRecoveryPat s = Syntax.parserRecoveryPat (lhs s)

%nonassoc prec_at_expr
%nonassoc prec_expr
%nonassoc prec_new_exprs
%nonassoc prec_new_no_exprs

%nonassoc INT8 INT16 INT32 INT64 NATIVEINT UINT8 UINT16 UINT32 UINT64 UNATIVEINT IEEE32 IEEE64 DECIMAL
%nonassoc TRUE FALSE NIL SYMBOL KEYWORD RAWSTRING DOT_METHOD APPLY_METHOD STRING UNIT CHAR
Expand All @@ -115,7 +117,6 @@ let mkRecoveryPat s = Syntax.parserRecoveryPat (lhs s)
%nonassoc prec_syn_pat_open
%nonassoc prec_syn_type_open


%nonassoc OP_LESS OP_GREATER THREAD_FIRST

%nonassoc OP_MULT
Expand All @@ -124,10 +125,12 @@ let mkRecoveryPat s = Syntax.parserRecoveryPat (lhs s)
// %left COMMA
// %right COMMA
%nonassoc prec_syn_type
%nonassoc prec_syn_type_commas
%nonassoc prec_attribute

%nonassoc prec_attribute_comma

%nonassoc prec_union_field

%nonassoc prec_dot_no_paren
%nonassoc prec_paren
Expand Down Expand Up @@ -287,7 +290,6 @@ paren_bar:
lambda_short_expr_list:
| parens_expr { $1 }


vector_start:
| LBRACKET RBRACKET { CollExpr.mkVector [] (lhs parseState) }
| LBRACKET expr_list RBRACKET { CollExpr.mkVector $2 (lhs parseState) }
Expand Down Expand Up @@ -535,6 +537,8 @@ new_expr:
{ SynExpr.New($2, [], lhs parseState) }
| NEW syntype_ident expr_list
{ SynExpr.New($2, $3, lhs parseState) }
| NEW
{ SynExpr.New(Syntax.parserRecoveryType (lhs parseState), [], lhs parseState) }

threadable_list: rev_threadable_list { List.rev $1 }
rev_threadable_list:
Expand Down Expand Up @@ -886,23 +890,11 @@ record_label_or_member_parens:

record_label_or_member:
| member_in_parens { Choice1Of2($1) }
| symbol COLON syntype_ident
| symbol COLON syn_type
{ Choice2Of2 (RecordLabel(RecordLabelKind.Default, $1, $3, lhs parseState)) }
| MUT symbol COLON syntype_ident
| MUT symbol COLON syn_type
{ Choice2Of2 (RecordLabel(RecordLabelKind.Mutable, $2, $4, lhs parseState)) }

typed_list: rev_typed_list { List.rev $1 }
rev_typed_list:
| error { [] }
| syntyped %prec prec_syntyped { [$1] }
| rev_typed_list syntyped %prec prec_syntyped { $2 :: $1 }

syntyped:
| LPAREN symbol COLON syntype_ident RPAREN
{ SynTyped($2, $4, lhs parseState )}
| LBRACKET symbol COLON syntype_ident RBRACKET
{ SynTyped($2, $4, lhs parseState )}

record_members:
| LPAREN MEMBERS member_list_start RPAREN { $3 }

Expand Down Expand Up @@ -1120,22 +1112,18 @@ syn_type:
{ SynType.Paren($2, lhs parseState) }
| LBRACKET syn_type RBRACKET %prec prec_syn_type_paren
{ SynType.Paren($2, lhs parseState) }
// | LPAREN syn_type recover %prec prec_syn_type_paren
// { SynType.Paren($2, lhs parseState) }
// | LBRACKET syn_type recover %prec prec_syn_type_paren
// { SynType.Paren($2, lhs parseState) }
| syn_type OP_MULT syn_type_tuple_list %prec prec_syn_type_mult
{ SynType.Tuple(false, SynTypeTupleSegment.Type($1) :: SynTypeTupleSegment.Star(rhs parseState 2) :: $3, lhs parseState) }
| syn_type THREAD_FIRST syn_type %prec prec_syn_type_array
{ SynType.Fun ($1, $3, lhs parseState) }
| syn_type arrayTypeSuffixHelp %prec prec_syn_type_array
{ SynType.Array($2, $1, lhs parseState) }
| SYMBOL %prec prec_syn_type
{ let text = $1
if (text = "_") then
SynType.Discard(lhs parseState)
else
SynType.Ident(Ident(text, lhs parseState)) }
| syn_type THREAD_FIRST syn_type %prec prec_syn_type_array
{ SynType.Fun ($1, $3, lhs parseState) }
| syn_type arrayTypeSuffixHelp %prec prec_syn_type_array
{ SynType.Array($2, $1, lhs parseState) }
| syn_type OP_LESS syn_type OP_GREATER %prec prec_syn_type_generic
{ SynType.Generic($1, [$3], lhs parseState) }
| syn_type OP_LESS syn_type COMMA syn_type_generic_list OP_GREATER %prec prec_syn_type_generic
Expand Down Expand Up @@ -1257,33 +1245,6 @@ invalid_function_def:
| FN INLINE symbol function_def_args %prec prec_invalid_fn
{ SynExpr.FunctionDef($3, FunctionFlags.Inline, $4, [], (lhs parseState)) }

arg_list_start:
| UNIT { [] }
| LPAREN RPAREN { [] }
| LBRACKET RBRACKET { [] }
| lparen_or_lbracket arg_list rparen_or_rbracket { $2 }
| lparen_or_lbracket recover %prec prec_recover { [] }
| recover %prec prec_recover { [] }

arg_list: rev_arg_list { List.rev $1 }
rev_arg_list:
| arg %prec prec_arg { [$1] }
| rev_arg_list arg { $2 :: $1 }

arg:
| symbol { SynArg.InferredArg($1, lhs parseState) }
| arg_in_parens_or_brackets_start { $1 }

arg_in_parens_or_brackets_start:
| LPAREN arg_in_parens_or_brackets RPAREN { $2 }
| LBRACKET arg_in_parens_or_brackets RBRACKET { $2 }

arg_in_parens_or_brackets:
| symbol COLON syntype_ident
{ SynArg.TypedArg($1, $3, lhs parseState) }
| symbol
{ SynArg.InferredArg($1, lhs parseState) }

function_call:
| expr expr_list { Syntax.mkFunctionCallOrCexpr $1 $2 (lhs parseState)}
| expr { SynExpr.FunctionCall($1, [], (lhs parseState))}
Expand Down
Loading

0 comments on commit 374f284

Please sign in to comment.