From c80cdf1e94c1382a45cf8a49e852cc25ac787dd7 Mon Sep 17 00:00:00 2001 From: Joel Holdbrooks Date: Sun, 25 Aug 2013 11:01:32 -0700 Subject: [PATCH] Version bump to 0.1.3 --- README.md | 90 +++++++++++++++++++++++++++++++++++++++++++---------- project.clj | 2 +- 2 files changed, 74 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 06992f8..b450dd3 100644 --- a/README.md +++ b/README.md @@ -3,17 +3,19 @@ frak transforms collections of strings into regular expressions for matching those strings. The primary goal of this library is to generate regular expressions from a known set of inputs which avoid -backtracking as much as possible. +backtracking as much as possible. It is available as a [command line +utility](#command-line-usage) and for the [browser](#browser-usage) +as a JavaScript library. ## "Installation" Add frak as a dependency to your `project.clj` file. ```clojure -[frak "0.1.2"] +[frak "0.1.3"] ``` -## Usage +## Clojure(Script) usage ```clojure user> (require 'frak) @@ -22,27 +24,81 @@ user> (frak/pattern ["foo" "bar" "baz" "quux"]) #"(?:ba[rz]|foo|quux)" user> (frak/pattern ["Clojure" "Clojars" "ClojureScript"]) #"Cloj(?:ure(?:Script)?|ars)" +user> (frak/pattern ["skill" "skills" "skull" "skulls"]) +#"sk(?:[ui]lls?)" ``` -## How? +## Command line usage -A frak pattern is constructed from a trie of characters. As characters -are added to it, meta data is stored in it's branches containing -information such as which branches are terminal and a record of -characters which have "visited" the branch. +frak can be used from the command line with either Leiningen or NodeJS. -During the rendering process frak will prefer branch characters that -have "visited" the most. In the example above, you will notice the -`ba[rz]` branch takes precedence over `foo` even though `"foo"` was -the first to enter the trie. This is because the character `\b` has -frequented the branch more than `\f` and `\q`. The example below -illustrates this behavior on the second character of each input. +### With Leiningen -```clojure -user> (frak/pattern ["bit" "bat" "ban" "bot" "bar" "box"]) -#"b(?:a[tnr]|o[tx]|it)" +Use the `lein run` command: + +```shell +$ lein run -e foo bar baz quux +^(?:ba[rz]|foo|quux)$ +``` + +### With NodeJS + +Compile the NodeJS version + +```shell +$ lein do cljx once, cljsbuild once node +$ chmod +x bin/frak +$ bin/frak -e foo bar baz quux +^(?:ba[rz]|foo|quux)$ +``` + +## Browser usage + +To use frak as a standalone library in the browser with JavaScript +compile the browser version: + +```shell +$ lein do cljx once, cljsbuild once browser +$ mv ./target/js/frak.min.js ``` +Try it using this HTML: + +```html + + + + + +
Input: 
+
Output: 
+ + + + + +``` + +For even more fun try it with [AngularJS](http://angularjs.org/)! + +## How? + +A frak pattern is constructed from a trie of characters and a +renderer which processes it. As characters are added to the trie, data +information about as which branches are terminal are stored in it's +branches. + +During the rendering process frak analyzes each branch and attempts to +emit the most concise regular expression possible. Additional post +operations are applied after the rendering to improve the expression +where possible. + ## Why? [Here's](https://github.com/guns/vim-clojure-static/blob/249328ee659190babe2b14cd119f972b21b80538/syntax/clojure.vim#L91-L92) diff --git a/project.clj b/project.clj index 22fd846..78348e3 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject frak "0.1.2" +(defproject frak "0.1.3" :description "Transform collections of strings into regular expressions." :url "http://github.com/noprompt/frak" :license {:name "Eclipse Public License" -- 2.25.1