regexper-static/src/js/parser/javascript/escape.js

62 lines
1.5 KiB
JavaScript
Raw Normal View History

import _ from 'lodash';
export default {
type: 'escape',
_render() {
2014-12-20 02:49:11 +00:00
return this.renderLabel(this.label)
.tap(label => {
2014-12-13 18:42:55 +00:00
label.select('rect').attr({
rx: 3,
ry: 3
});
2014-12-11 00:23:14 +00:00
});
2014-12-09 22:43:05 +00:00
},
setup() {
this.code = this.properties.esc.properties.code.textValue;
this.arg = this.properties.esc.properties.arg.textValue;
[this.label, this.ordinal] = _.result(this, this.code);
},
2014-12-09 22:43:05 +00:00
// Escape code mappings
b: ['word boundary', -1],
B: ['non-word boundary', -1],
d: ['digit', -1],
D: ['non-digit', -1],
f: ['form feed', 0x0c],
n: ['line feed', 0x0a],
r: ['carriage return', 0x0d],
s: ['white space', -1],
S: ['non-white space', -1],
t: ['tab', 0x09],
v: ['vertical tab', 0x0b],
w: ['word', -1],
W: ['non-word', -1],
1: ['Back reference (group = 1)', -1],
2: ['Back reference (group = 2)', -1],
3: ['Back reference (group = 3)', -1],
4: ['Back reference (group = 4)', -1],
5: ['Back reference (group = 5)', -1],
6: ['Back reference (group = 6)', -1],
7: ['Back reference (group = 7)', -1],
8: ['Back reference (group = 8)', -1],
9: ['Back reference (group = 9)', -1],
2014-12-09 22:43:05 +00:00
0() {
if (this.arg) {
return [`octal: ${this.arg}`, parseInt(this.arg, 8)];
2014-12-09 22:43:05 +00:00
} else {
return ['null', 0];
2014-12-09 22:43:05 +00:00
}
},
c() {
return [`ctrl-${this.arg.toUpperCase()}`, this.arg.toUpperCase().charCodeAt(0) - 64];
2014-12-09 22:43:05 +00:00
},
x() {
return [`0x${this.arg.toUpperCase()}`, parseInt(this.arg, 16)];
2014-12-09 22:43:05 +00:00
},
u() {
return [`U+${this.arg.toUpperCase()}`, parseInt(this.arg, 16)];
}
};