summaryrefslogtreecommitdiff
path: root/src/parse.lisp
blob: 8bd8c502ab35069d4baec322f3260e18e335e89c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
(in-package #:parse)

(defun tokens->ast (program)
  (let ((program (remove nil (mapcar #'extract-label program))))
    ;; TODO
    program))

(let ((i 0))
  (defun extract-label (line)
    "Given a series of tokens LINE, determines if LINE is
in the form STRING {colon}. If it is, then it is treated as a
label, and pushed onto the stack with the line index.

Note that this function is intended to be called using mapcar,
so that labels can be added to a map and otherwise removed from
processing."
    (trivia:match line
      ((list (and id (type string))
             (satisfies (lambda (x) (equal x 'lex::colon))))
       (progn (push (cons (read-from-string id) i) util:label-loc) nil))
      (_ (progn (incf i) line)))))