Skip to content

Commit

Permalink
common-lisp: Add #b, #o and #x parsing support
Browse files Browse the repository at this point in the history
  • Loading branch information
yitzchak committed Aug 12, 2024
1 parent 0f7b82f commit 3603360
Showing 1 changed file with 38 additions and 21 deletions.
59 changes: 38 additions & 21 deletions code/common-lisp/implementation.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,44 @@
(:set :code :infinity))
(:sequence #\-
(:set :code :quiet-nan))))
(:digits :exponent)))
(:alternate? #\+
(:sequence #\-
(:set :sign -1)))
(:alternate (:sequence (:assert :float t)
#\.
(:digits :fractional)
(:set :ratio nil
:integer nil)
:exponent?)
(:sequence (:digits :integral)
(:alternate (:sequence (:assert :ratio t)
#\/
(:set :integer nil :float nil)
(:digits :divisor))
(:sequence (:sequence? #\.
(:sequence? (:assert :float t)
(:digits :fractional)
(:set :ratio nil
:integer nil)))
:exponent?)))))
(:digits :exponent))
:sign? (:alternate? #\+
(:sequence #\-
(:set :sign -1))))
(:alternate (:sequence #\#
(:alternate (:sequence #\b
(:set :integral-base 2
:divisor-base 2))
(:sequence #\o
(:set :integral-base 8
:divisor-base 8))
(:sequence #\x
(:set :integral-base 16
:divisor-base 16)))
:sign?
(:digits :integral)
(:sequence? (:assert :ratio t)
#\/
(:set :integer nil :float nil)
(:digits :divisor)))
(:sequence :sign?
(:alternate (:sequence (:assert :float t)
#\.
(:digits :fractional)
(:set :ratio nil
:integer nil)
:exponent?)
(:sequence (:digits :integral)
(:alternate (:sequence (:assert :ratio t)
#\/
(:set :integer nil :float nil)
(:digits :divisor))
(:sequence (:sequence? #\.
(:sequence? (:assert :float t)
(:digits :fractional)
(:set :ratio nil
:integer nil)))
:exponent?)))))))

(defmethod quaviver:write-number ((client client) (base (eql 2)) (value integer) stream)
(write-string "#b" stream)
Expand Down

0 comments on commit 3603360

Please sign in to comment.