-(defpackage #:cl-nl.lexer
- (:use :common-lisp)
- (:export :lex))
-
-(in-package #:cl-nl.lexer)
+(in-package #:clnl-lexer)
; I played around with using #'read for netlogo code, which would have been neat.
; However, it provides too many instances where people could inject CL code
(defun lex (text)
(if (string= "" text)
(let
- ((lex (find-if (lambda (f) (funcall f *state* :eof)) *lexes* :key #'car)))
+ ((lex (find-if (lambda (f) (funcall f *state* :eof)) *lexes* :from-end t :key #'car)))
(when lex (list (funcall (third lex) :eof))))
(let
- ((lex (find-if (lambda (f) (funcall f *state* text)) *lexes* :key #'car)))
+ ((lex (find-if (lambda (f) (funcall f *state* text)) *lexes* :from-end t :key #'car)))
(when (not lex) (error "Can't lex this: ~S" text))
(let
((val (funcall (third lex) (subseq text 0 (funcall (cadr lex) text)))))
(defvar *letter* "\\w")
(defvar *digit* "\\d")
;(defparameter *identifier-char* "[\\w\\d_\\.?=\*!<>:#\+/%\$\^\'&-]")
-(defvar *identifier-char* "[\\w\\d]")
+(defvar *identifier-char* "[\\w\\d-.]")
;(defvar *extension-literal-depth* 0)
;(defstruct extension-literal text)
(deflex :initial *nonnewline_white_space_char* (constantly nil))
(deflex :initial "\\n|\\r" (constantly nil))
;(deflex :initial ";.*[\n\r]?" nil)
-;(deflex :initial (format nil "-?\.?[0-9]~A" *identifier-char*)
-; (lambda (text)
-; (let
-; ((num?
-; (let
-; ((*readtable* (copy-readtable nil))
-; (*read-eval* nil))
-; (read-from-string text))))
-; (if (numberp num?) num? (error "Invalid number")))))
+(deflex :initial (format nil "-?\.?[0-9]~A*" *identifier-char*)
+ (lambda (text)
+ (let
+ ((num?
+ (let
+ ((*readtable* (copy-readtable nil))
+ (*read-eval* nil))
+ (read-from-string text))))
+ (if (numberp num?) num? (error "Invalid number")))))
(deflex :initial (format nil "~A*" *identifier-char*) #'as-symbol)
;(deflex :initial (format nil "\"~A*\"" *string-text*))