-
Notifications
You must be signed in to change notification settings - Fork 10
/
EDNParserTypes.fs
119 lines (110 loc) · 4.62 KB
/
EDNParserTypes.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright (c) Thortech Solutions, LLC. All rights reserved.
// The use and distribution terms for this software are covered by the
// Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
// which can be found in the file epl-v10.html at the root of this distribution.
// By using this software in any fashion, you are agreeing to be bound by
// the terms of this license.
// You must not remove this notice, or any other, from this software.
//
// Authors: Mark Perrotta, Dimitrios Kapsalis
//
namespace EDNReaderWriter
open System.Numerics
open EDNTypes
module EDNParserTypes =
type EDNException(message : string) =
inherit System.Exception(message)
type QualifiedSymbol =
struct
val prefix: string
val name: string
new (prefix, name) = {prefix = prefix; name = name}
override this.ToString() = "QualifiedSymbol Prefix: " + this.prefix + " Name: " + this.name
end
type EDNValue = EDNNil
| EDNBoolean of bool
| EDNString of string
| EDNCharacter of char
| EDNSymbol of QualifiedSymbol
| EDNKeyword of QualifiedSymbol
| EDNInteger of BigInteger
| EDNFloat of double
| EDNComment of string
| EDNDiscard of EDNValueParsed
| EDNTaggedValue of QualifiedSymbol * EDNValueParsed
| EDNList of EDNValueParsed list
| EDNVector of EDNValueParsed array
| EDNMap of List<EDNValueParsed>
| EDNSet of List<EDNValueParsed>
and EDNValueParsed =
struct
val line: int64
val col: int64
val ednValue: EDNValue
new (ednValue, line, col) = { ednValue = ednValue; line = line; col = col }
override this.ToString() =
sprintf "%A" this.ednValue
end
let getLineColString (valueParsed : EDNValueParsed) =
System.String.Format("line: {0}, column: {1}", valueParsed.line, valueParsed.col);
let isNotCommentOrDiscard (v : EDNValueParsed) =
match v.ednValue with
| EDNComment _ | EDNDiscard _ -> false
| _ -> true
(*
type IEDNSymbol =
inherit System.IComparable
abstract member getPrefix : unit -> string
abstract member getName : unit -> string
let getSymbolString (symbol : IEDNSymbol )=
if System.String.IsNullOrWhiteSpace(symbol.getPrefix()) then
System.String.Empty
else symbol.getPrefix() + "/"
+ symbol.getName()
type EDNSymbolType(prefix: string, name: string) =
interface IEDNPrintable with
member this.PrintEDN(stream) =
PrintUtils.WriteEDNToStream(this.ToString(), stream)
member this.PrintEDN() =
this.ToString()
interface IEDNSymbol with
member this.getPrefix() = prefix
member this.getName() = name
member this.CompareTo obj =
this.ToString().CompareTo( obj.ToString())
override this.ToString() = getSymbolString this
override this.GetHashCode() =
this.ToString().GetHashCode()
override this.Equals (obj : System.Object) =
if System.Object.ReferenceEquals(this, obj) then
true
elif obj.GetType() <> Operators.typeof<EDNSymbolType> then
false
elif this.ToString() = obj.ToString() then
true
else
false
type EDNKeywordType(prefix: string, name: string) =
interface IEDNPrintable with
member this.PrintEDN(stream) =
PrintUtils.WriteEDNToStream(":" + this.ToString(), stream)
member this.PrintEDN() =
":" + this.ToString()
interface IEDNSymbol with
member this.getPrefix() = prefix
member this.getName() = name
member this.CompareTo obj =
this.ToString().CompareTo( obj.ToString())
override this.ToString() = getSymbolString this
override this.GetHashCode() =
this.ToString().GetHashCode()
override this.Equals (obj : System.Object) =
if System.Object.ReferenceEquals(this, obj) then
true
elif obj.GetType() <> Operators.typeof<EDNKeywordType> then
false
elif this.ToString() = obj.ToString() then
true
else
false
*)