about summary refs log tree commit diff stats
path: root/lex.lsp
diff options
context:
space:
mode:
authorDarren Bane <darren.bane@gmail.com>2020-11-18 23:59:17 +0000
committerDarren Bane <darren.bane@gmail.com>2020-11-18 23:59:17 +0000
commit6e7cdcd4280f5330229ec9c943b9caf090846452 (patch)
tree7e7542c9edb9ef9805022ca105f42a56372aad9b /lex.lsp
parentf1dd340e2def134d0641ebbbf92934f69086b643 (diff)
downloadlsp-6e7cdcd4280f5330229ec9c943b9caf090846452.tar.gz
Checkpointing from my Mac
Diffstat (limited to 'lex.lsp')
-rw-r--r--lex.lsp38
1 files changed, 27 insertions, 11 deletions
diff --git a/lex.lsp b/lex.lsp
index 52eb822..9f10a03 100644
--- a/lex.lsp
+++ b/lex.lsp
@@ -1,4 +1,20 @@
-(defclass <string-lexer> () ((string :initarg :s :accessor string)
+(defpackage #:lex
+  (:use #:openlisp)
+  (:export
+   #:<lint>
+   #:<lsymbol>
+   #:<lstring>
+   #:<lend>))
+(in-package #:lex)
+
+(defclass <lexeme> () () (:abstractp t))
+(defclass <lint> (<lexeme>) ((int :reader int)))
+(defclass <lident> (<lexeme>) ((ident :reader ident)))
+(defclass <lsymbol> (<lexeme>) ((lsymbol :reader lsymbol)))
+(defclass <lstring> (<lexeme>) ((lstring :reader lstring)))
+(defclass <lend> (<lexeme>) ())
+
+(defclass <string-lexer> () ((string :initarg s :accessor string)
                              (current :initform 0 :accessor current)
                              (size :accessor size)))
 
@@ -26,16 +42,16 @@
 
 (defgeneric extract-int (cl))
 (defmethod extract-int ((cl <string-lexer>))
-  ;; TODO: flet?
-  (let ((is-int (lambda (x)
-                  (and (char>= x #\0) (char<= x #\9)))))
-    (convert (extract is-int cl) <number>)))
+   (flet ((is-int (x)
+             (and (char>= x #\0) (char<= x #\9))))
+      (convert (extract is-int cl) <number>)))
 
 (defgeneric extract-ident (cl))
 (defmethod extract-ident ((cl <string-lexer>))
-  (let ((is-alpha-num (lambda (x)
-                        (or (and (char>= x #\a) (char<= x #\z))
-                          (and (char>= x #\A) (char<= x #\Z))
-                          (and (char>= x #\0) (char<= x #\9))
-                          (char= x #\_)))))
-    (extract is-alpha-num)))
+   (flet ((is-alpha-num (x)
+             (or (and (char>= x #\a) (char<= x #\z))
+                 (and (char>= x #\A) (char<= x #\Z))
+                 (and (char>= x #\0) (char<= x #\9))
+                 (char= x #\_))))
+      (extract is-alpha-num)))
+(provide "lex")