about summary refs log tree commit diff stats
path: root/ccmd.lisp
blob: a3eeabde29de8b5bafe9eeb54612879752a4b67c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
(require "split-sequence")
(defpackage #:ccmd
  (:use #:common-lisp #:split-sequence)
  (:export
    #:parse
    #:create-tab
    #:fun
    #:lookup)
  )
(in-package #:ccmd)
(defclass <buf> () ((buf :initarg b :reader buf) (f :initarg f :reader f)))
(defun parse (p)
  (let ((toks (split-sequence-if (lambda (c) (member c '(#\Space #\Tab))) p)))
    (format *error-output* "parse: p ~A toks ~A~%" p toks)
    (make-instance (find-class '<buf>) 'b (car toks) 'f toks)))
(defclass <tab> () ((fun :initarg f :reader fun)
                    (cmd :initarg c :reader cmd)
                    (narg :initarg n :reader narg)))
(defun create-tab (f c n)
  (make-instance (find-class '<tab>) 'f f 'c c 'n n))
(defgeneric lookup (buf tab))
(defmethod lookup ((buf <buf>) tabs)
  (let ((cmd (buf buf)))
    (find-if (lambda (tab)
               (let ((c (cmd tab)))
                 (string= c cmd)))
             tabs)))
(provide "ccmd")