\begin{quote}
Fast, pluggable and easy-\/to-\/use parser-\/renderer factory. \end{quote}
\hypertarget{md_sfcode_node_modules_snapdragon_README_autotoc_md27364}{}\doxysection{Install}\label{md_sfcode_node_modules_snapdragon_README_autotoc_md27364}
Install with \href{https://www.npmjs.com/}{\texttt{ npm}}\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\$ npm install -\/-\/save snapdragon }

\end{DoxyCode}


Created by \href{https://github.com/jonschlinkert}{\texttt{ jonschlinkert}} and \href{https://github.com/doowb}{\texttt{ doowb}}.

{\bfseries{Features}}


\begin{DoxyItemize}
\item Bootstrap your own parser, get sourcemap support for free
\item All parsing and compiling is handled by simple, reusable middleware functions
\item Inspired by the parsers in \href{http://jade-lang.com}{\texttt{ pug}} and \href{https://github.com/reworkcss/css}{\texttt{ css}}.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_snapdragon_README_autotoc_md27365}{}\doxysection{History}\label{md_sfcode_node_modules_snapdragon_README_autotoc_md27365}
\hypertarget{md_sfcode_node_modules_snapdragon_README_autotoc_md27366}{}\doxysubsection{v0.\+5.\+0}\label{md_sfcode_node_modules_snapdragon_README_autotoc_md27366}
{\bfseries{Breaking changes}}

Substantial breaking changes were made in v0.\+5.\+0! Most of these changes are part of a larger refactor that will be finished in 0.\+6.\+0, including the introduction of a {\ttfamily Lexer} class.


\begin{DoxyItemize}
\item Renderer was renamed to {\ttfamily Compiler}
\item the {\ttfamily .render} method was renamed to {\ttfamily .compile}
\item Many other smaller changes. A more detailed overview will be provided in 0.\+6.\+0. If you don\textquotesingle{}t have to time review code, I recommend you wait for the 0.\+6.\+0 release.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_snapdragon_README_autotoc_md27367}{}\doxysection{Usage examples}\label{md_sfcode_node_modules_snapdragon_README_autotoc_md27367}

\begin{DoxyCode}{0}
\DoxyCodeLine{var Snapdragon = require('snapdragon');}
\DoxyCodeLine{var snapdragon = new Snapdragon(); }

\end{DoxyCode}


{\bfseries{Parse}}


\begin{DoxyCode}{0}
\DoxyCodeLine{var ast = snapdragon.parser('some string', options)}
\DoxyCodeLine{  // parser middleware that can be called by other middleware}
\DoxyCodeLine{  .set('foo', function () \{\})}
\DoxyCodeLine{  // parser middleware, runs immediately in the order defined}
\DoxyCodeLine{  .use(bar())}
\DoxyCodeLine{  .use(baz()) }

\end{DoxyCode}


{\bfseries{Render}}


\begin{DoxyCode}{0}
\DoxyCodeLine{// pass the `ast` from the parse method}
\DoxyCodeLine{var res = snapdragon.compiler(ast)}
\DoxyCodeLine{  // compiler middleware, called when the name of the middleware}
\DoxyCodeLine{  // matches the `node.type` (defined in a parser middleware)}
\DoxyCodeLine{  .set('bar', function () \{\})}
\DoxyCodeLine{  .set('baz', function () \{\})}
\DoxyCodeLine{  .compile() }

\end{DoxyCode}


See the \href{./examples/}{\texttt{ examples}}.\hypertarget{md_sfcode_node_modules_snapdragon_README_autotoc_md27368}{}\doxysection{Getting started}\label{md_sfcode_node_modules_snapdragon_README_autotoc_md27368}
{\bfseries{Parsers}}

Parsers are middleware functions used for parsing a string into an ast node.


\begin{DoxyCode}{0}
\DoxyCodeLine{var ast = snapdragon.parser(str, options)}
\DoxyCodeLine{  .use(function() \{}
\DoxyCodeLine{    var pos = this.position();}
\DoxyCodeLine{    var m = this.match(/\string^\(\backslash\)./);}
\DoxyCodeLine{    if (!m) return;}
\DoxyCodeLine{    return pos(\{}
\DoxyCodeLine{      // `type` specifies the compiler to use}
\DoxyCodeLine{      type: 'dot',}
\DoxyCodeLine{      val: m[0]}
\DoxyCodeLine{    \});}
\DoxyCodeLine{  \}) }

\end{DoxyCode}


{\bfseries{AST node}}

When the parser finds a match, {\ttfamily pos()} is called, pushing a token for that node onto the ast that looks something like\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\{ type: 'dot',}
\DoxyCodeLine{  val: '.',}
\DoxyCodeLine{  position:}
\DoxyCodeLine{   \{ start: \{ lineno: 1, column: 1 \},}
\DoxyCodeLine{     end: \{ lineno: 1, column: 2 \} \}\} }

\end{DoxyCode}


{\bfseries{Renderers}}

Renderers are {\itshape named} middleware functions that visit over an array of ast nodes to compile a string.


\begin{DoxyCode}{0}
\DoxyCodeLine{var res = snapdragon.compiler(ast)}
\DoxyCodeLine{  .set('dot', function (node) \{}
\DoxyCodeLine{    console.log(node.val)}
\DoxyCodeLine{    //=> '.'}
\DoxyCodeLine{    return this.emit(node.val);}
\DoxyCodeLine{  \}) }

\end{DoxyCode}


{\bfseries{Source maps}}

If you want source map support, make sure to emit the position as well.


\begin{DoxyCode}{0}
\DoxyCodeLine{var res = snapdragon.compiler(ast)}
\DoxyCodeLine{  .set('dot', function (node) \{}
\DoxyCodeLine{    return this.emit(node.val, node.position);}
\DoxyCodeLine{  \}) }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_snapdragon_README_autotoc_md27369}{}\doxysection{Docs}\label{md_sfcode_node_modules_snapdragon_README_autotoc_md27369}
\hypertarget{md_sfcode_node_modules_snapdragon_README_autotoc_md27370}{}\doxysubsection{Parser middleware}\label{md_sfcode_node_modules_snapdragon_README_autotoc_md27370}
A parser middleware is a function that returns an abject called a {\ttfamily token}. This token is pushed onto the AST as a node.

{\bfseries{Example token}}


\begin{DoxyCode}{0}
\DoxyCodeLine{\{ type: 'dot',}
\DoxyCodeLine{  val: '.',}
\DoxyCodeLine{  position:}
\DoxyCodeLine{   \{ start: \{ lineno: 1, column: 1 \},}
\DoxyCodeLine{     end: \{ lineno: 1, column: 2 \} \}\} }

\end{DoxyCode}


{\bfseries{Example parser middleware}}

Match a single {\ttfamily .} in a string\+:


\begin{DoxyEnumerate}
\item Get the starting position by calling {\ttfamily this.\+position()}
\item pass a regex for matching a single dot to the {\ttfamily .match} method
\item if {\bfseries{no match}} is found, return {\ttfamily undefined}
\item if a {\bfseries{match}} is found, {\ttfamily pos()} is called, which returns a token with\+:
\begin{DoxyItemize}
\item {\ttfamily type}\+: the name of the \mbox{[}compiler\mbox{]} to use
\item {\ttfamily val}\+: The actual value captured by the regex. In this case, a {\ttfamily .}. Note that you can capture and return whatever will be needed by the corresponding \mbox{[}compiler\mbox{]}.
\item The ending position\+: automatically calculated by adding the length of the first capture group to the starting position.
\end{DoxyItemize}
\end{DoxyEnumerate}\hypertarget{md_sfcode_node_modules_snapdragon_README_autotoc_md27371}{}\doxysection{Renderer middleware}\label{md_sfcode_node_modules_snapdragon_README_autotoc_md27371}
Renderers are run when the name of the compiler middleware matches the {\ttfamily type} defined on an ast {\ttfamily node} (which is defined in a parser).

{\bfseries{Example}}

Exercise\+: Parse a dot, then compile it as an escaped dot.


\begin{DoxyCode}{0}
\DoxyCodeLine{var ast = snapdragon.parser('.')}
\DoxyCodeLine{  .use(function () \{}
\DoxyCodeLine{    var pos = this.position();}
\DoxyCodeLine{    var m = this.match(/\string^\(\backslash\)./);}
\DoxyCodeLine{    if (!m) return;}
\DoxyCodeLine{    return pos(\{}
\DoxyCodeLine{      // define the `type` of compiler to use}
\DoxyCodeLine{      type: 'dot',}
\DoxyCodeLine{      val: m[0]}
\DoxyCodeLine{    \})}
\DoxyCodeLine{  \})}
\DoxyCodeLine{}
\DoxyCodeLine{var result = snapdragon.compiler(ast)}
\DoxyCodeLine{  .set('dot', function (node) \{}
\DoxyCodeLine{    return this.emit('\(\backslash\)\(\backslash\)' + node.val);}
\DoxyCodeLine{  \})}
\DoxyCodeLine{  .compile()}
\DoxyCodeLine{}
\DoxyCodeLine{console.log(result.output);}
\DoxyCodeLine{//=> '\(\backslash\).' }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_snapdragon_README_autotoc_md27372}{}\doxysection{API}\label{md_sfcode_node_modules_snapdragon_README_autotoc_md27372}
\hypertarget{md_sfcode_node_modules_snapdragon_README_autotoc_md27373}{}\doxysubsection{$<$a href=\char`\"{}lib/parser.\+js\#\+L19\char`\"{}$>$\+Parser$<$/a$>$}\label{md_sfcode_node_modules_snapdragon_README_autotoc_md27373}
Create a new {\ttfamily Parser} with the given {\ttfamily input} and {\ttfamily options}.

{\bfseries{Params}}


\begin{DoxyItemize}
\item {\ttfamily input} $\ast$$\ast$\{String\}$\ast$$\ast$
\item {\ttfamily options} $\ast$$\ast$\{Object\}$\ast$$\ast$
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_snapdragon_README_autotoc_md27374}{}\doxysubsection{$<$a href=\char`\"{}lib/parser.\+js\#\+L103\char`\"{}$>$.\+define$<$/a$>$}\label{md_sfcode_node_modules_snapdragon_README_autotoc_md27374}
Define a non-\/enumberable property on the {\ttfamily Parser} instance.

{\bfseries{Example}}


\begin{DoxyCode}{0}
\DoxyCodeLine{parser.define('foo', 'bar'); }

\end{DoxyCode}


{\bfseries{Params}}


\begin{DoxyItemize}
\item {\ttfamily key} $\ast$$\ast$\{String\}$\ast$$\ast$\+: propery name
\item {\ttfamily val} $\ast$$\ast$\{any\}$\ast$$\ast$\+: property value
\item {\ttfamily returns} $\ast$$\ast$\{Object\}$\ast$$\ast$\+: Returns the Parser instance for chaining.
\end{DoxyItemize}

Set parser {\ttfamily name} with the given {\ttfamily fn}

{\bfseries{Params}}


\begin{DoxyItemize}
\item {\ttfamily name} $\ast$$\ast$\{String\}$\ast$$\ast$
\item {\ttfamily fn} $\ast$$\ast$\{Function\}$\ast$$\ast$
\end{DoxyItemize}

Get parser {\ttfamily name}

{\bfseries{Params}}


\begin{DoxyItemize}
\item {\ttfamily name} $\ast$$\ast$\{String\}$\ast$$\ast$
\end{DoxyItemize}

Push a {\ttfamily token} onto the {\ttfamily type} stack.

{\bfseries{Params}}


\begin{DoxyItemize}
\item {\ttfamily type} $\ast$$\ast$\{String\}$\ast$$\ast$
\item {\ttfamily returns} $\ast$$\ast$\{Object\}$\ast$$\ast$ {\ttfamily token}
\end{DoxyItemize}

Pop a token off of the {\ttfamily type} stack

{\bfseries{Params}}


\begin{DoxyItemize}
\item {\ttfamily type} $\ast$$\ast$\{String\}$\ast$$\ast$
\item {\ttfamily returns} $\ast$$\ast$\{Object\}$\ast$$\ast$\+: Returns a token
\end{DoxyItemize}

Return true if inside a {\ttfamily stack} node. Types are {\ttfamily braces}, {\ttfamily parens} or {\ttfamily brackets}.

{\bfseries{Params}}


\begin{DoxyItemize}
\item {\ttfamily type} $\ast$$\ast$\{String\}$\ast$$\ast$
\item {\ttfamily returns} $\ast$$\ast$\{Boolean\}$\ast$$\ast$
\end{DoxyItemize}

{\bfseries{Example}}


\begin{DoxyCode}{0}
\DoxyCodeLine{parser.isType(node, 'brace'); }

\end{DoxyCode}


{\bfseries{Params}}


\begin{DoxyItemize}
\item {\ttfamily node} $\ast$$\ast$\{Object\}$\ast$$\ast$
\item {\ttfamily type} $\ast$$\ast$\{String\}$\ast$$\ast$
\item {\ttfamily returns} $\ast$$\ast$\{Boolean\}$\ast$$\ast$
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_snapdragon_README_autotoc_md27375}{}\doxysubsection{$<$a href=\char`\"{}lib/compiler.\+js\#\+L71\char`\"{}$>$.\+define$<$/a$>$}\label{md_sfcode_node_modules_snapdragon_README_autotoc_md27375}
Define a non-\/enumberable property on the {\ttfamily Compiler} instance.

{\bfseries{Example}}


\begin{DoxyCode}{0}
\DoxyCodeLine{compiler.define('foo', 'bar'); }

\end{DoxyCode}


{\bfseries{Params}}


\begin{DoxyItemize}
\item {\ttfamily key} $\ast$$\ast$\{String\}$\ast$$\ast$\+: propery name
\item {\ttfamily val} $\ast$$\ast$\{any\}$\ast$$\ast$\+: property value
\item {\ttfamily returns} $\ast$$\ast$\{Object\}$\ast$$\ast$\+: Returns the Compiler instance for chaining.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_snapdragon_README_autotoc_md27376}{}\doxysection{About}\label{md_sfcode_node_modules_snapdragon_README_autotoc_md27376}
\hypertarget{md_sfcode_node_modules_snapdragon_README_autotoc_md27377}{}\doxysubsection{Related projects}\label{md_sfcode_node_modules_snapdragon_README_autotoc_md27377}

\begin{DoxyItemize}
\item \href{https://www.npmjs.com/package/braces}{\texttt{ braces}}\+: Fastest brace expansion for node.\+js, with the most complete support for the Bash 4.\+3 braces… \href{https://github.com/jonschlinkert/braces}{\texttt{ more}} $\vert$ \href{https://github.com/jonschlinkert/braces}{\texttt{ homepage}}
\item \href{https://www.npmjs.com/package/expand-brackets}{\texttt{ expand-\/brackets}}\+: Expand POSIX bracket expressions (character classes) in glob patterns. $\vert$ \mbox{[}homepage\mbox{]}(\href{https://github.com/jonschlinkert/expand-brackets}{\texttt{ https\+://github.\+com/jonschlinkert/expand-\/brackets}} \char`\"{}\+Expand POSIX bracket expressions (character classes) in glob patterns.\char`\"{})
\item \href{https://www.npmjs.com/package/extglob}{\texttt{ extglob}}\+: Convert extended globs to regex-\/compatible strings. Add (almost) the expressive power of regular expressions to… \href{https://github.com/jonschlinkert/extglob}{\texttt{ more}} $\vert$ \mbox{[}homepage\mbox{]}(\href{https://github.com/jonschlinkert/extglob}{\texttt{ https\+://github.\+com/jonschlinkert/extglob}} \char`\"{}\+Convert extended globs to regex-\/compatible strings. Add (almost) the expressive power of regular expressions to glob patterns.\char`\"{})
\item \href{https://www.npmjs.com/package/micromatch}{\texttt{ micromatch}}\+: Glob matching for javascript/node.\+js. A drop-\/in replacement and faster alternative to minimatch and multimatch. $\vert$ \href{https://github.com/jonschlinkert/micromatch}{\texttt{ homepage}}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_snapdragon_README_autotoc_md27378}{}\doxysubsection{Contributing}\label{md_sfcode_node_modules_snapdragon_README_autotoc_md27378}
Pull requests and stars are always welcome. For bugs and feature requests, \href{../../issues/new}{\texttt{ please create an issue}}.\hypertarget{md_sfcode_node_modules_snapdragon_README_autotoc_md27379}{}\doxysubsection{Contributors}\label{md_sfcode_node_modules_snapdragon_README_autotoc_md27379}
\tabulinesep=1mm
\begin{longtabu}spread 0pt [c]{*{2}{|X[-1]}|}
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ {\bfseries{Commits}}   }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ {\bfseries{Contributor}}~\newline
    }\\\cline{1-2}
\endfirsthead
\hline
\endfoot
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ {\bfseries{Commits}}   }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ {\bfseries{Contributor}}~\newline
    }\\\cline{1-2}
\endhead
106   &\href{https://github.com/jonschlinkert}{\texttt{ jonschlinkert}}    \\\cline{1-2}
2   &\href{https://github.com/doowb}{\texttt{ doowb}}   \\\cline{1-2}
\end{longtabu}
\hypertarget{md_sfcode_node_modules_snapdragon_README_autotoc_md27380}{}\doxysubsection{Building docs}\label{md_sfcode_node_modules_snapdragon_README_autotoc_md27380}
\+\_\+(This document was generated by \href{https://github.com/verbose/verb-generate-readme}{\texttt{ verb-\/generate-\/readme}} (a \href{https://github.com/verbose/verb}{\texttt{ verb}} generator), please don\textquotesingle{}t edit the readme directly. Any changes to the readme must be made in .verb.md.)\+\_\+

To generate the readme and API documentation with \href{https://github.com/verbose/verb}{\texttt{ verb}}\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\$ npm install -\/g verb verb-\/generate-\/readme \&\& verb }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_snapdragon_README_autotoc_md27381}{}\doxysubsection{Running tests}\label{md_sfcode_node_modules_snapdragon_README_autotoc_md27381}
Install dev dependencies\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\$ npm install -\/d \&\& npm test }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_snapdragon_README_autotoc_md27382}{}\doxysubsection{Author}\label{md_sfcode_node_modules_snapdragon_README_autotoc_md27382}
{\bfseries{Jon Schlinkert}}


\begin{DoxyItemize}
\item \href{https://github.com/jonschlinkert}{\texttt{ github/jonschlinkert}}
\item \href{http://twitter.com/jonschlinkert}{\texttt{ twitter/jonschlinkert}}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_snapdragon_README_autotoc_md27383}{}\doxysubsection{License}\label{md_sfcode_node_modules_snapdragon_README_autotoc_md27383}
Copyright © 2016, \href{https://github.com/jonschlinkert}{\texttt{ Jon Schlinkert}}. Released under the \href{https://github.com/jonschlinkert/snapdragon/blob/master/LICENSE}{\texttt{ MIT license}}.

\DoxyHorRuler{0}


{\itshape This file was generated by \href{https://github.com/verbose/verb-generate-readme}{\texttt{ verb-\/generate-\/readme}}, v0.\+1.\+31, on October 10, 2016.} 