<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/walk/atom.go
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2023-05-12 11:37:44 +0100
committerCharlie Stanton <charlie@shtanton.xyz>2023-05-12 11:37:44 +0100
commit551613765c9e60e2221ac920d2756b949e68f373 (patch)
treeac579a9e0d6c015edca694880f259c8dac4d7a04 /walk/atom.go
parente98ebbad387def55d8347adb5bf45034d542cce0 (diff)
downloadstred-go-551613765c9e60e2221ac920d2756b949e68f373.tar
Move reading and writing of tokens into a separate package to prepare for other input and output formats
Diffstat (limited to 'walk/atom.go')
-rw-r--r--walk/atom.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/walk/atom.go b/walk/atom.go
index 13ad2ff..dfe5fe4 100644
--- a/walk/atom.go
+++ b/walk/atom.go
@@ -43,12 +43,24 @@ func NewAtomNumber(v float64) Atom {
data: math.Float64bits(v),
}
}
+func (v Atom) Number() float64 {
+ if v.Typ != AtomNumber {
+ panic("Tried to use non-number as number")
+ }
+ return math.Float64frombits(v.data)
+}
func NewAtomTerminal(v ValueTerminal) Atom {
return Atom {
Typ: AtomTerminal,
data: uint64(v),
}
}
+func (v Atom) Terminal() ValueTerminal {
+ if v.Typ != AtomTerminal {
+ panic("Tried to use non-terminal as terminal")
+ }
+ return ValueTerminal(v.data)
+}
func NewAtomStringTerminal() Atom {
return Atom {
Typ: AtomStringTerminal,