Adding code to render charsets

This commit is contained in:
Jeff Avallone 2014-12-07 17:38:24 -05:00
parent 9cc23183be
commit fadfaee440
8 changed files with 103 additions and 6 deletions

View File

@ -60,6 +60,10 @@
fill: #dae9e5; fill: #dae9e5;
} }
.charset .charset-box {
fill: #cbcbba;
}
.placeholder text { .placeholder text {
fill: #fff; fill: #fff;
font-weight: bold; font-weight: bold;

View File

@ -6,6 +6,9 @@ import Match from './javascript/match.js';
import MatchFragment from './javascript/match_fragment.js'; import MatchFragment from './javascript/match_fragment.js';
import Subexp from './javascript/subexp.js'; import Subexp from './javascript/subexp.js';
import Charset from './javascript/charset.js'; import Charset from './javascript/charset.js';
import CharsetLiteral from './javascript/charset_literal.js';
import CharsetEscape from './javascript/charset_escape.js';
import CharsetRange from './javascript/charset_range.js';
import Literal from './javascript/literal.js'; import Literal from './javascript/literal.js';
import Escape from './javascript/escape.js'; import Escape from './javascript/escape.js';
import AnyCharacter from './javascript/any_character.js'; import AnyCharacter from './javascript/any_character.js';
@ -21,6 +24,9 @@ parser.Parser.Match = Match;
parser.Parser.MatchFragment = MatchFragment; parser.Parser.MatchFragment = MatchFragment;
parser.Parser.Subexp = Subexp; parser.Parser.Subexp = Subexp;
parser.Parser.Charset = Charset; parser.Parser.Charset = Charset;
parser.Parser.CharsetLiteral = CharsetLiteral;
parser.Parser.CharsetEscape = CharsetEscape;
parser.Parser.CharsetRange = CharsetRange;
parser.Parser.Literal = Literal; parser.Parser.Literal = Literal;
parser.Parser.Escape = Escape; parser.Parser.Escape = Escape;
parser.Parser.AnyCharacter = AnyCharacter; parser.Parser.AnyCharacter = AnyCharacter;

View File

@ -2,5 +2,69 @@ import _ from 'lodash';
import Base from './base.js'; import Base from './base.js';
export default _.extend({}, Base, { export default _.extend({}, Base, {
type: 'charset' type: 'charset',
render() {
this.container.addClass('charset');
this.label = this.container.text()
.attr({
text: this.invert() ? 'None of:' : 'One of:'
})
.transform(Snap.matrix()
.translate(0, 0));
this.box = this.container.rect()
.addClass('charset-box')
.attr({
rx: 3,
ry: 3
});
this.partContainer = this.container.group();
_.each(this.parts.elements, ((part) => {
part.container = this.partContainer.group();
part.render();
}).bind(this));
},
position() {
var box, offset = 0;
_.each(this.parts.elements, ((part) => {
var box;
part.position();
part.container.transform(Snap.matrix()
.translate(0, offset));
box = part.container.getBBox();
offset += box.height + 5;
}).bind(this));
box = this.partContainer.getBBox();
_.each(this.parts.elements, ((part) => {
var partBox = part.container.getBBox();
part.container.transform(Snap.matrix()
.add(part.container.transform().localMatrix)
.translate(box.cx - partBox.cx, 0));
}).bind(this));
this.box.attr({
width: box.width + 10,
height: box.height + 10
});
this.partContainer.transform(Snap.matrix()
.translate(5, 5));
},
invert() {
return this._invert.textValue !== '';
}
}); });

View File

@ -0,0 +1,10 @@
import _ from 'lodash';
import Escape from './escape.js';
export default _.extend({}, Escape, {
type: 'charset_escape',
codeMap: _.extend({}, Escape.codeMap, {
b: 'backspace'
})
});

View File

@ -0,0 +1,6 @@
import _ from 'lodash';
import Literal from './literal.js';
export default _.extend({}, Literal, {
type: 'literal'
});

View File

@ -0,0 +1,6 @@
import _ from 'lodash';
import Base from './base.js';
export default _.extend({}, Base, {
type: 'charset_range'
});

View File

@ -20,15 +20,16 @@ grammar JavascriptRegexp
subexp_no_capture <- "?:" subexp_no_capture <- "?:"
subexp_positive_lookahead <- "?=" subexp_positive_lookahead <- "?="
subexp_negative_lookahead <- "?!" subexp_negative_lookahead <- "?!"
charset <- "[" "^"? ( charset_range / charset_terminal )* "]" <Charset> charset <- "[" _invert:"^"? parts:( charset_range / charset_terminal )* "]" <Charset>
charset_range <- charset_terminal "-" charset_terminal charset_range <- first:charset_terminal "-" last:charset_terminal <CharsetRange>
charset_terminal <- charset_escape / charset_literal charset_terminal <- charset_escape <CharsetEscape>
/ charset_literal <CharsetLiteral>
charset_escape <- "\\" esc:( charset_escape <- "\\" esc:(
code:[bdDfnrsStvwW] arg:""? code:[bdDfnrsStvwW] arg:""?
/ code:"0" arg:[0-7]+ / code:"0" arg:[0-7]+
/ code:"x" arg:( [0-9a-fA-F] [0-9a-fA-F] ) / code:"x" arg:( [0-9a-fA-F] [0-9a-fA-F] )
/ code:"u" arg:( [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] ) ) / code:"u" arg:( [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] ) )
charset_literal <- [^\\\]] / ( "\\" . ) charset_literal <- ( ""? literal:[^\\\]] ) / ( "\\" literal:. )
terminal <- any_character <AnyCharacter> terminal <- any_character <AnyCharacter>
/ escape <Escape> / escape <Escape>
/ literal <Literal> / literal <Literal>

View File

@ -44,6 +44,6 @@ export default _.extend({}, Base, {
.translate(0, 0)); .translate(0, 0));
} }
this.render_bbox(this.container, this.container.getBBox()); //this.render_bbox(this.container, this.container.getBBox());
} }
}); });