Code Monkey home page Code Monkey logo

parser.ini's Introduction

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 (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

TODO Reference

Settings

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.