HH-Parse / types.lisp

(in-package :hh-parse )
;; =====================================================================================================================
;; Helpers
;; =====================================================================================================================

(defun make-lines ()
  (make-array 0 :element-type 'source-code-line :adjustable t)

;; =====================================================================================================================
;; Types
;; =====================================================================================================================

;; Source code
(defclass source-code-line ()
  ((parser :initform nil :initarg :parser :accessor parser-of
	   :documentation "Parser positioned at end of the line")
   (text :initform "" :initarg :text :accessor text-of)))

(defclass source-code-position ()
  ((line :initform 0 :initarg :line :accessor line-at)
   (column :initform 0 :initarg :column :accessor column-at))
  (:documentation "Represents a location within a file"))

(defclass source-code-file ()
  ((lines :initform (make-lines) :accessor lines-of)
   (position :initform (make-instance 'source-code-position) :accessor current-position))
  (:documentation "Represents the state of a file being edited or parsed"))

;; Grammar

(defclass production ()
  ((rule-name :initarg :rule)
   (options :initarg :options)
   (rhs :initarg :rhs)))

(defclass lr1-item ()
  ((position :initarg :position)
   (lookahead :initarg :lookahead )
   (production :initarg :production)))

(defclass lr1-state ()
  ((items :initarg :items :accessor items)
   (exits :initform (make-hash-table) :accessor exits
	  :documentation "Contains a mapping between symbols and integers representing the next state 
                          after encountering the symbol")))

(defclass lr-parse-table ()
  ((number-of-states :initarg :states :accessor number-of-states)
   (entries :initform (make-hash-table :test #'equal) :accessor entries))) 

(defclass lalr1-grammar ()
  ((specification :initarg :specification :accessor specification)
   (states :initarg :states :accessor states)
   (actions :initarg :actions :accessor actions)
   (gotos :initarg :gotos :accessor gotos)))

;; Lexer

(defclass lexer ()
  ((source :initform (make-instance 'source-code-file) :initarg :source :accessor source)
   (position :initform (make-instance 'source-code-position) :initarg :position :accessor parse-position)
   (state :initform :any :accessor state)))

;; Parser

(defclass lalr1-parser ()
  ((grammar :initarg :grammar :accessor grammar)
   (lexer :initarg :lexer :accessor lexer)
   (stack :initform () :accessor stack)))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.