Tokenizes strings that represent a regular expressions.

\href{http://travis-ci.org/fent/ret.js}{\texttt{ }} \href{https://david-dm.org/fent/ret.js}{\texttt{ }} \href{https://codecov.io/gh/fent/ret.js}{\texttt{ }}\hypertarget{md_sfcode_node_modules_ret_README_autotoc_md24841}{}\doxysection{Usage}\label{md_sfcode_node_modules_ret_README_autotoc_md24841}

\begin{DoxyCode}{0}
\DoxyCodeLine{var ret = require('ret');}
\DoxyCodeLine{}
\DoxyCodeLine{var tokens = ret(/foo|bar/.source); }

\end{DoxyCode}


{\ttfamily tokens} will contain the following object


\begin{DoxyCode}{0}
\DoxyCodeLine{\{}
\DoxyCodeLine{  "{}type"{}: ret.types.ROOT}
\DoxyCodeLine{  "{}options"{}: [}
\DoxyCodeLine{    [ \{ "{}type"{}: ret.types.CHAR, "{}value"{}, 102 \},}
\DoxyCodeLine{      \{ "{}type"{}: ret.types.CHAR, "{}value"{}, 111 \},}
\DoxyCodeLine{      \{ "{}type"{}: ret.types.CHAR, "{}value"{}, 111 \} ],}
\DoxyCodeLine{    [ \{ "{}type"{}: ret.types.CHAR, "{}value"{},  98 \},}
\DoxyCodeLine{      \{ "{}type"{}: ret.types.CHAR, "{}value"{},  97 \},}
\DoxyCodeLine{      \{ "{}type"{}: ret.types.CHAR, "{}value"{}, 114 \} ]}
\DoxyCodeLine{  ]}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_ret_README_autotoc_md24842}{}\doxysection{Token Types}\label{md_sfcode_node_modules_ret_README_autotoc_md24842}
{\ttfamily ret.\+types} is a collection of the various token types exported by ret.\hypertarget{md_sfcode_node_modules_ret_README_autotoc_md24843}{}\doxysubsubsection{ROOT}\label{md_sfcode_node_modules_ret_README_autotoc_md24843}
Only used in the root of the regexp. This is needed due to the posibility of the root containing a pipe {\ttfamily $\vert$} character. In that case, the token will have an {\ttfamily options} key that will be an array of arrays of tokens. If not, it will contain a {\ttfamily stack} key that is an array of tokens.


\begin{DoxyCode}{0}
\DoxyCodeLine{\{}
\DoxyCodeLine{  "{}type"{}: ret.types.ROOT,}
\DoxyCodeLine{  "{}stack"{}: [token1, token2...],}
\DoxyCodeLine{\} }

\end{DoxyCode}



\begin{DoxyCode}{0}
\DoxyCodeLine{\{}
\DoxyCodeLine{  "{}type"{}: ret.types.ROOT,}
\DoxyCodeLine{  "{}options"{} [}
\DoxyCodeLine{    [token1, token2...],}
\DoxyCodeLine{    [othertoken1, othertoken2...]}
\DoxyCodeLine{    ...}
\DoxyCodeLine{  ],}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_ret_README_autotoc_md24844}{}\doxysubsubsection{GROUP}\label{md_sfcode_node_modules_ret_README_autotoc_md24844}
Groups contain tokens that are inside of a parenthesis. If the group begins with {\ttfamily ?} followed by another character, it\textquotesingle{}s a special type of group. A \textquotesingle{}\+:\textquotesingle{} tells the group not to be remembered when {\ttfamily exec} is used. \textquotesingle{}=\textquotesingle{} means the previous token matches only if followed by this group, and \textquotesingle{}!\textquotesingle{} means the previous token matches only if NOT followed.

Like root, it can contain an {\ttfamily options} key instead of {\ttfamily stack} if there is a pipe.


\begin{DoxyCode}{0}
\DoxyCodeLine{\{}
\DoxyCodeLine{  "{}type"{}: ret.types.GROUP,}
\DoxyCodeLine{  "{}remember"{} true,}
\DoxyCodeLine{  "{}followedBy"{}: false,}
\DoxyCodeLine{  "{}notFollowedBy"{}: false,}
\DoxyCodeLine{  "{}stack"{}: [token1, token2...],}
\DoxyCodeLine{\} }

\end{DoxyCode}



\begin{DoxyCode}{0}
\DoxyCodeLine{\{}
\DoxyCodeLine{  "{}type"{}: ret.types.GROUP,}
\DoxyCodeLine{  "{}remember"{} true,}
\DoxyCodeLine{  "{}followedBy"{}: false,}
\DoxyCodeLine{  "{}notFollowedBy"{}: false,}
\DoxyCodeLine{  "{}options"{} [}
\DoxyCodeLine{    [token1, token2...],}
\DoxyCodeLine{    [othertoken1, othertoken2...]}
\DoxyCodeLine{    ...}
\DoxyCodeLine{  ],}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_ret_README_autotoc_md24845}{}\doxysubsubsection{POSITION}\label{md_sfcode_node_modules_ret_README_autotoc_md24845}
{\ttfamily \textbackslash{}b}, {\ttfamily \textbackslash{}B}, {\ttfamily $^\wedge$}, and {\ttfamily \$} specify positions in the regexp.


\begin{DoxyCode}{0}
\DoxyCodeLine{\{}
\DoxyCodeLine{  "{}type"{}: ret.types.POSITION,}
\DoxyCodeLine{  "{}value"{}: "{}\string^"{},}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_ret_README_autotoc_md24846}{}\doxysubsubsection{SET}\label{md_sfcode_node_modules_ret_README_autotoc_md24846}
Contains a key {\ttfamily set} specifying what tokens are allowed and a key {\ttfamily not} specifying if the set should be negated. A set can contain other sets, ranges, and characters.


\begin{DoxyCode}{0}
\DoxyCodeLine{\{}
\DoxyCodeLine{  "{}type"{}: ret.types.SET,}
\DoxyCodeLine{  "{}set"{}: [token1, token2...],}
\DoxyCodeLine{  "{}not"{}: false,}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_ret_README_autotoc_md24847}{}\doxysubsubsection{RANGE}\label{md_sfcode_node_modules_ret_README_autotoc_md24847}
Used in set tokens to specify a character range. {\ttfamily from} and {\ttfamily to} are character codes.


\begin{DoxyCode}{0}
\DoxyCodeLine{\{}
\DoxyCodeLine{  "{}type"{}: ret.types.RANGE,}
\DoxyCodeLine{  "{}from"{}: 97,}
\DoxyCodeLine{  "{}to"{}: 122,}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_ret_README_autotoc_md24848}{}\doxysubsubsection{REPETITION}\label{md_sfcode_node_modules_ret_README_autotoc_md24848}

\begin{DoxyCode}{0}
\DoxyCodeLine{\{}
\DoxyCodeLine{  "{}type"{}: ret.types.REPETITION,}
\DoxyCodeLine{  "{}min"{}: 0,}
\DoxyCodeLine{  "{}max"{}: Infinity,}
\DoxyCodeLine{  "{}value"{}: token,}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_ret_README_autotoc_md24849}{}\doxysubsubsection{REFERENCE}\label{md_sfcode_node_modules_ret_README_autotoc_md24849}
References a group token. {\ttfamily value} is 1-\/9.


\begin{DoxyCode}{0}
\DoxyCodeLine{\{}
\DoxyCodeLine{  "{}type"{}: ret.types.REFERENCE,}
\DoxyCodeLine{  "{}value"{}: 1,}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_ret_README_autotoc_md24850}{}\doxysubsubsection{CHAR}\label{md_sfcode_node_modules_ret_README_autotoc_md24850}
Represents a single character token. {\ttfamily value} is the character code. This might seem a bit cluttering instead of concatenating characters together. But since repetition tokens only repeat the last token and not the last clause like the pipe, it\textquotesingle{}s simpler to do it this way.


\begin{DoxyCode}{0}
\DoxyCodeLine{\{}
\DoxyCodeLine{  "{}type"{}: ret.types.CHAR,}
\DoxyCodeLine{  "{}value"{}: 123,}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_ret_README_autotoc_md24851}{}\doxysubsection{Errors}\label{md_sfcode_node_modules_ret_README_autotoc_md24851}
ret.\+js will throw errors if given a string with an invalid regular expression. All possible errors are


\begin{DoxyItemize}
\item Invalid group. When a group with an immediate {\ttfamily ?} character is followed by an invalid character. It can only be followed by {\ttfamily !}, {\ttfamily =}, or {\ttfamily \+:}. Example\+: {\ttfamily /(?\+\_\+abc)/}
\item Nothing to repeat. Thrown when a repetitional token is used as the first token in the current clause, as in right in the beginning of the regexp or group, or right after a pipe. Example\+: {\ttfamily /foo$\vert$?bar/}, {\ttfamily /\{1,3\}foo$\vert$bar/}, {\ttfamily /foo(+bar)/}
\item Unmatched ). A group was not opened, but was closed. Example\+: {\ttfamily /hello)2u/}
\item Unterminated group. A group was not closed. Example\+: {\ttfamily /(1(23)4/}
\item Unterminated character class. A custom character set was not closed. Example\+: {\ttfamily /\mbox{[}abc/}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_ret_README_autotoc_md24852}{}\doxysection{Install}\label{md_sfcode_node_modules_ret_README_autotoc_md24852}
\begin{DoxyVerb}npm install ret
\end{DoxyVerb}
\hypertarget{md_sfcode_node_modules_ret_README_autotoc_md24853}{}\doxysection{Tests}\label{md_sfcode_node_modules_ret_README_autotoc_md24853}
Tests are written with \href{http://vowsjs.org/}{\texttt{ vows}}


\begin{DoxyCode}{0}
\DoxyCodeLine{npm test }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_ret_README_autotoc_md24854}{}\doxysection{License}\label{md_sfcode_node_modules_ret_README_autotoc_md24854}
MIT 