chiark / gitweb /
Work in progress, recovered from old crybaby.
[sod] / src / parser / proto-scanner.lisp
index 87a382e241d2ef8d1f73da13fa6ab85f466ce2f5..966c77c700068619f7cf0c9ba63f297750f4fe49 100644 (file)
@@ -44,8 +44,8 @@ (defclass scanner-context ()
    state.  So the scanner context is a compile-time context which expands to
    calls to use the run-time scanner.  See?
 
-   This class provides common compile-time behaviour for PARSER-AT-EOF-P and
-   friends by invoking corresponding methods on the scanner object at
+   This class provides common compile-time behaviour for `parser-at-eof-p'
+   and friends by invoking corresponding methods on the scanner object at
    run-time."))
 
 ;;;--------------------------------------------------------------------------
@@ -190,8 +190,8 @@ (defstruct token-scanner-place
   (next nil :type (or token-scanner-place null))
   (type nil :read-only t)
   (value nil :read-only t)
-  (line 1 :type fixnum :read-only t)
-  (column 0 :type fixnum :read-only t))
+  (line 1 :type (or fixnum null) :read-only t)
+  (column 0 :type (or fixnum null) :read-only t))
 
 ;; The token scanner base class and parser context.
 
@@ -201,7 +201,7 @@ (defclass token-scanner ()
    (value :reader token-value)
    (captures :initform 0 :type fixnum)
    (tail :initform nil :type (or token-scanner-place null))
-   (filename :initarg filename :type string :reader scanner-filename)
+   (filename :initarg :filename :type string :reader scanner-filename)
    (line :initarg :line :initform 1 :type fixnum :accessor scanner-line)
    (column :initarg :column :initform 0
           :type fixnum :accessor scanner-column))
@@ -255,4 +255,15 @@ (defclass character-scanner-stream (fundamental-character-input-stream)
    `stream-read-sequence' and `stream-read-line' in a scanner-specific
    manner."))
 
+(export 'make-scanner-stream)
+(defgeneric make-scanner-stream (scanner)
+  (:documentation
+   "Return a stream which reads from the SCANNER.
+
+   The default method simply constructs a `character-scanner-stream'
+   instance.  Subclasses of `character-scanner' can override this method in
+   order to return instances of more efficient stream subclasses.")
+  (:method ((scanner character-scanner))
+    (make-instance 'character-scanner-stream :scanner scanner)))
+
 ;;;----- That's all, folks --------------------------------------------------