Parser for ini-like configuration options
Common Lisp
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples
src
test
.travis.yml
COPYING
README.org
parser.ini.asd
version-string.sexp

README.org

parser.ini README

Introduction

The parser.ini system provides a parser for the “ini-like” family of configuration syntaxes. A builder-based protocol is used to construct parse results.

https://travis-ci.org/scymtym/parser.ini.svg

Tutorial

To parse a string of configuration options and return the result as a simple list-based structure, the parse function is called with the symbol list instead of a more complicated builder object:

(parser.ini:parse "[section] option = value" 'list)
((:SECTION
  (:SECTION-OPTION
   (((:OPTION NIL :NAME ("option") :VALUE "value" :BOUNDS (10 . 24)))))
  :NAME ("section") :BOUNDS (0 . 9)))

Syntactic variants are controlled via special variables (note : instead of =):

(let ((parser.ini:*assignment-operator* #\:))
  (parser.ini:parse "[section] option: value" 'list))
((:SECTION
  (:SECTION-OPTION
   (((:OPTION NIL :NAME ("option") :VALUE "value" :BOUNDS (10 . 23)))))
  :NAME ("section") :BOUNDS (0 . 9)))

The builder-based protocol allows constructing arbitrary result objects:

(defstruct located bounds)
(defstruct (section (:include located)) name options)
(defstruct (option (:include located)) name value)

(defmethod architecture.builder-protocol:make-node
    ((builder (eql :my-builder)) (kind (eql :section)) &key name bounds)
  (make-section :name name :bounds bounds))

(defmethod architecture.builder-protocol:relate
    ((builder  (eql :my-builder))
     (relation (eql :section-option))
     (left     section)
     (right    option)
     &key)
  (alexandria:appendf (section-options left) (list right))
  left)

(defmethod architecture.builder-protocol:make-node
    ((builder (eql :my-builder)) (kind (eql :option)) &key name value bounds)
  (make-option :name name :value value :bounds bounds))

(parser.ini:parse "[section] option = value" :my-builder)
(#S(SECTION
    :BOUNDS (0 . 9)
    :NAME ("section")
    :OPTIONS (#S(OPTION :BOUNDS (10 . 24) :NAME ("option") :VALUE "value"))))
NIL
T

TODO Reference

Settings