Skip to content

Commit

Permalink
Fixed:#9 build script
Browse files Browse the repository at this point in the history
  • Loading branch information
CJex committed Nov 30, 2014
1 parent a619068 commit b807a31
Show file tree
Hide file tree
Showing 5 changed files with 496 additions and 5 deletions.
50 changes: 46 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,62 @@ Regulex

JavaScript Regular Expression Parser & Visualizer.

Visualizer : http://jex.im/regulex/
Online : http://jex.im/regulex/

###Features:
- Written in pure JavaScript. No backend needed.
- You can embed the graph in you own site through html iframe element.
- Detailed error message. In most cases it can point out the precise syntax error position.
- No support for octal escape. Yes it is a feature. ECMAScript strict mode doesn't support octal escape in string,but many browsers still support octal escape in regex. I make things easier. In regulex, DecimalEscape will always be treated as back reference. If the back reference is invalid, e.g. `/\1/``/(\1)/``/(a)\2/`,or DecimalEscape appears in charset(because in this case it can't be explained as back reference, e.g. `/(ab)[\1]/`. Regulex will always throw an error.
- No support for octal escape. Yes it is a feature. ECMAScript strict mode doesn't support octal escape in string,but many browsers still support octal escape in regex. I make things easier. In regulex, DecimalEscape will always be treated as back reference. If the back reference is invalid, e.g. `/\1/``/(\1)/``/(a)\2/`,or DecimalEscape appears in charset(because in this case it can't be explained as back reference, e.g. `/(ab)[\1]/`, Regulex will always throw an error.

### Build

This command will generate `dest/regulex.js` file.
```bash
npm install requirejs -g
r.js -o build-config.js
```


### API

API:
#### Parse to AST
```javascript
var parse = require('regulex/parse');
var parse = require('regulex').parse;
var re = /var\s+([a-zA-Z_]\w*);/ ;
console.log(parse(re));
```

#### Visualize
```javascript
var parse = require('regulex').parse;
var visualize = require('regulex').visualize;
var Raphael = require('regulex').Raphael;
var re = /var\s+([a-zA-Z_]\w*);/;
var paper = Raphael('yourSvgContainer',0,0);
try {
visualize(parse(re.source),getRegexFlags(re),paper);
} catch(e) {
if (e instanceof parse.RegexSyntaxError) {
logError(re,e);
} else throw e;
}

function logError(re,err) {
var msg=["Error:"+err.message,""];
if (typeof err.lastIndex==='number') {
msg.push(re);
msg.push(new Array(err.lastIndex).join('-')+"^");
}
console.log(msg.join("\n"));
}


function getRegexFlags(re) {
var flags='';
flags+=re.ignoreCase?'i':'';
flags+=re.global?'g':'';
flags+=re.multiline?'m':'';
return flags;
}
```
8 changes: 8 additions & 0 deletions build-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
({
baseUrl: 'src/',
mainConfigFile: 'src/regulex.js',
out: 'dest/regulex.js',
optimize: 'uglify2',
wrap: false,
include: ['libs/almond','regulex']
})
3 changes: 2 additions & 1 deletion src/Kit.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ function log() {
if (isBrowser) {
Function.prototype.apply.apply(console.log,[console,a]);
} else {//Assume it is Node.js
var util=require('util');
var s='util';
var util=require(s); // skip require.js
a.forEach(function (x) {
console.log(util.inspect(x,{
showHidden:false,customInspect:true,
Expand Down
Loading

0 comments on commit b807a31

Please sign in to comment.