Skip to content

Commit

Permalink
Remove SynName
Browse files Browse the repository at this point in the history
  • Loading branch information
vipentti committed Dec 22, 2023
1 parent 95f351b commit 9bb9e88
Show file tree
Hide file tree
Showing 6 changed files with 853 additions and 1,152 deletions.
29 changes: 0 additions & 29 deletions src/Visp.Compiler/Parser.fsy
Original file line number Diff line number Diff line change
Expand Up @@ -1069,35 +1069,6 @@ rev_binding_list:
binding:
| syn_pat expr { SynBinding($1, $2, lhs parseState) }

name:
| symbol { SynName.Inferred($1, lhs parseState) }
| name_in_parens_or_brackets_start { $1 }

name_in_parens_or_brackets_start:
| LPAREN name_in_parens_or_brackets RPAREN { $2 }
| LBRACKET name_in_parens_or_brackets RBRACKET { $2 }

name_in_parens_or_brackets:
| symbol COLON syntype_ident
{ SynName.Typed($1, $3, lhs parseState) }
| symbol
{ SynName.Inferred($1, lhs parseState) }

empty_name_list:
| LPAREN RPAREN { [] }
| LBRACKET RBRACKET { [] }

name_list_start:
| empty_name_list %prec prec_name_list { $1 }
| LPAREN name_list RPAREN %prec prec_name_list { $2 }
| LBRACKET name_list RBRACKET %prec prec_name_list { $2 }

name_list: rev_name_list { List.rev $1 }
rev_name_list:
| name %prec prec_name { [$1] }
| rev_name_list name { $2 :: $1 }


macro_name:
| MACRO_NAME
{ let text = $1
Expand Down
1,881 changes: 853 additions & 1,028 deletions src/Visp.Compiler/Syntax/FsLexYaccOutput/Parser.fs

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions src/Visp.Compiler/Syntax/FsLexYaccOutput/Parser.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -399,13 +399,6 @@ type nonTerminalId =
| NONTERM_binding_list
| NONTERM_rev_binding_list
| NONTERM_binding
| NONTERM_name
| NONTERM_name_in_parens_or_brackets_start
| NONTERM_name_in_parens_or_brackets
| NONTERM_empty_name_list
| NONTERM_name_list_start
| NONTERM_name_list
| NONTERM_rev_name_list
| NONTERM_macro_name
| NONTERM_dot_method
| NONTERM_apply_method
Expand Down
58 changes: 0 additions & 58 deletions src/Visp.Compiler/Syntax/SynWriter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -521,17 +521,6 @@ module Write =

and writeTypeHelp w _ = writeType w


let synName (w: SynWriter) (n: SynName) =
match n with
| SynName.Inferred(n, _) -> symbol w n true
| SynName.Typed(nm, typ, _) ->
char w '('
symbol w nm true
string w ": "
writeType w typ
char w ')'

let rec synPat (w: SynWriter) (n: SynPat) =
match n with
| SynPat.Const(cnst, _) ->
Expand Down Expand Up @@ -1516,53 +1505,6 @@ module Write =
w.LeaveLet()
()

and private writeLetFull (w: SynWriter) (st: WriteState) mut (name: SynName) (body: SynExpr) =
w.EnterLet()

let isLiteral =
not mut
&& match body with
| SynExpr.Literal _ -> true
| _ -> false

if isLiteral then
string w "[<Literal>]"
newline w
indent w

string w "let "

if mut then
string w "mutable "

synName w name
string w " ="

let should_indent =
match body with
| SynExpr.Const _
| SynExpr.Literal _
| SynExpr.Keyword _
| SynExpr.Symbol _ -> false
| _ -> true

if should_indent then
use _ = withIndent w false
newline w
writeExpr w WriteState.Body body
else
space w
writeExpr w WriteState.Inline body

w.LeaveLet()

()


and private writeLet w (st: WriteState) (name: SynName) (body: SynExpr) =
writeLetFull w st false name body
()

and private writeExprInParens w (st: WriteState) ex =
let needsParens =
match ex with
Expand Down
24 changes: 0 additions & 24 deletions src/Visp.Compiler/Syntax/Syntax.fs
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,6 @@ type RecordLabelKind =
type RecordLabel =
| RecordLabel of kind: RecordLabelKind * name: SynSymbol * argtype: SynType * range: range

[<NoEquality; NoComparison; RequireQualifiedAccess>]
type SynName =
// Argument with explicit type
| Typed of name: SynSymbol * argtype: SynType * range: range
// Argument with inferred type
| Inferred of name: SynSymbol * range: range
//[<NoEquality; NoComparison; RequireQualifiedAccess>]

[<NoEquality; NoComparison; RequireQualifiedAccess>]
type SynOpenDeclTarget =
| ModuleOrNamespace of longId: SynLongIdent * range: range
Expand Down Expand Up @@ -625,9 +617,6 @@ module Syntax =

let parserRecoverySymbol r = SynSymbol(Ident(parserRecovery, r))

let parserRecoveryName r =
SynName.Inferred(parserRecoverySymbol r, r)

let parserRecoveryPat r = SynPat.Named(parserRecoverySymbol r, r)

let parserRecoveryType r = SynType.Ident(Ident(parserRecovery, r))
Expand All @@ -648,16 +637,6 @@ module Syntax =
let (SynKeyword s) = id
textOfIdent s

let textOfName =
function
| SynName.Inferred(it, _) -> textOfSymbol it
| SynName.Typed(it, _, _) -> textOfSymbol it

let rangeOfName =
function
| SynName.Inferred(it, _) -> rangeOfSymbol it
| SynName.Typed(it, _, _) -> rangeOfSymbol it

let mkFunctionCall sym ex range = SynExpr.FunctionCall(sym, ex, range)

let mkCons lhs rhs range = SynExpr.Cons(lhs, rhs, range)
Expand All @@ -676,9 +655,6 @@ module Syntax =

let mkSynTypeIdent s range = (SynType.Ident(Ident(s, range)))

let mkInferredName n range =
SynName.Inferred(mkSynSymbol n range, range)

let mkInferredNamePat n range =
SynPat.Named(mkSynSymbol n range, range)

Expand Down
6 changes: 0 additions & 6 deletions src/Visp.Compiler/Syntax/SyntaxPrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,6 @@ type SynMacroBody with
Print.writeSimpleDoc sw <| Print.renderPrettyDefault doc
sb.ToStringAndReturn()

let nameToDoc =
function
| SynName.Inferred(it, _) -> text it.Text
| SynName.Typed(name, typ, _) ->
brackets <| (cat [ text name.Text; colon; space; text "todo types" ])

let patToDoc =
function
| SynPat.Named(it, _) -> text it.Text
Expand Down

0 comments on commit 9bb9e88

Please sign in to comment.