-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UNFINISHED syntax-extension: Rational float Literal
fixes #54
- Loading branch information
Showing
5 changed files
with
69 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
(cl:defpackage #:eclector.syntax-extensions.rational-float | ||
(:use | ||
#:cl) | ||
|
||
(:export | ||
)) | ||
|
||
(cl:in-package #:eclector.syntax-extensions.rational-float) | ||
|
||
(defclass client () | ||
()) | ||
|
||
#+TODO (defmethod eclector.reader::reader-float-format (client &optional exponent-marker) | ||
(if (eql exponent-marker #\R) | ||
'rational | ||
(call-next-method))) | ||
|
||
(defmethod eclector.reader:make-literal ((client client) | ||
(class eclector.reader::float-kind) | ||
&key type sign decimal-mantissa decimal-exponent | ||
exponent-sign exponent) | ||
(case type | ||
(:custom (* (* sign decimal-mantissa) | ||
(expt 10 (- (* exponent-sign exponent) decimal-exponent)))) | ||
(t (call-next-method)))) | ||
|
||
; eclector.reader::trait->index | ||
|
||
(let ((eclector.base:*client* (make-instance 'client))) | ||
(eclector.reader:read-from-string "1.234R2")) | ||
(let ((eclector.base:*client* (make-instance 'client))) | ||
(eclector.reader:call-with-state-value | ||
eclector.base:*client* | ||
(eclector.reader:read-from-string "1R") | ||
'*read-default-float-format* :custom)) | ||
;;; 1.234R2 => 617/5 (= 123.4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
(cl:defpackage #:eclector.syntax-extensions.rational-float.test | ||
(:use | ||
#:cl | ||
#:fiveam)) | ||
|
||
(cl:in-package #:eclector.syntax-extensions.rational-float.test) | ||
|
||
(def-suite* :eclector.syntax-extensions.rational-float | ||
:in :eclector.syntax-extensions) | ||
|
||
(test smoke | ||
"TODO" | ||
(error "TODO")) |