parser.ini
2018-10-18
Provides parsing of Ini expressions.
Upstream URL
Author
Jan Moringen <jmoringe@techfak.uni-bielefeld.de>
Maintainer
Jan Moringen <jmoringe@techfak.uni-bielefeld.de>
License
LLGPLv3
parser.ini README
1Introduction
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.
2Tutorial
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 (comments, assignment operator, interpretation of
whitespace in values, etc.) 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