Adding ordinal values to escapes
Work still needs to be done to get control characters correct, and ordinals will need to be added for literals as well. This is in preparation for reporting incorrectly ordered charset ranges
This commit is contained in:
parent
33bbd11af6
commit
101b457260
@ -5,30 +5,27 @@ import Snap from 'snapsvg';
|
|||||||
describe('parser/javascript/charset_escape.js', function() {
|
describe('parser/javascript/charset_escape.js', function() {
|
||||||
|
|
||||||
_.forIn({
|
_.forIn({
|
||||||
'\\b': 'backspace',
|
'\\b': { label: 'backspace', ordinal: 0x08 },
|
||||||
'\\d': 'digit',
|
'\\d': { label: 'digit', ordinal: -1 },
|
||||||
'\\D': 'non-digit',
|
'\\D': { label: 'non-digit', ordinal: -1 },
|
||||||
'\\f': 'form feed',
|
'\\f': { label: 'form feed', ordinal: 0x0c },
|
||||||
'\\n': 'line feed',
|
'\\n': { label: 'line feed', ordinal: 0x0a },
|
||||||
'\\r': 'carriage return',
|
'\\r': { label: 'carriage return', ordinal: 0x0d },
|
||||||
'\\s': 'white space',
|
'\\s': { label: 'white space', ordinal: -1 },
|
||||||
'\\S': 'non-white space',
|
'\\S': { label: 'non-white space', ordinal: -1 },
|
||||||
'\\t': 'tab',
|
'\\t': { label: 'tab', ordinal: 0x09 },
|
||||||
'\\v': 'vertical tab',
|
'\\v': { label: 'vertical tab', ordinal: 0x0b },
|
||||||
'\\w': 'word',
|
'\\w': { label: 'word', ordinal: -1 },
|
||||||
'\\W': 'non-word',
|
'\\W': { label: 'non-word', ordinal: -1 },
|
||||||
'\\0': 'null',
|
'\\0': { label: 'null', ordinal: 0 },
|
||||||
'\\012': 'octal: 12',
|
'\\012': { label: 'octal: 12', ordinal: 10 },
|
||||||
'\\cx': 'ctrl-x',
|
'\\cx': { label: 'ctrl-x', ordinal: -1 },
|
||||||
'\\xab': '0xAB',
|
'\\xab': { label: '0xAB', ordinal: 0xab },
|
||||||
'\\uabcd': 'U+ABCD'
|
'\\uabcd': { label: 'U+ABCD', ordinal: 0xabcd }
|
||||||
}, (label, str) => {
|
}, (content, str) => {
|
||||||
it(`parses "${str}" as a CharsetEscape`, function() {
|
it(`parses "${str}" as a CharsetEscape`, function() {
|
||||||
var parser = new javascript.Parser(str);
|
var parser = new javascript.Parser(str);
|
||||||
expect(parser.__consume__charset_terminal()).toEqual(jasmine.objectContaining({
|
expect(parser.__consume__charset_terminal()).toEqual(jasmine.objectContaining(content));
|
||||||
type: 'charset-escape',
|
|
||||||
label
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -5,40 +5,37 @@ import Snap from 'snapsvg';
|
|||||||
describe('parser/javascript/escape.js', function() {
|
describe('parser/javascript/escape.js', function() {
|
||||||
|
|
||||||
_.forIn({
|
_.forIn({
|
||||||
'\\b': 'word boundary',
|
'\\b': { label: 'word boundary', ordinal: -1 },
|
||||||
'\\B': 'non-word boundary',
|
'\\B': { label: 'non-word boundary', ordinal: -1 },
|
||||||
'\\d': 'digit',
|
'\\d': { label: 'digit', ordinal: -1 },
|
||||||
'\\D': 'non-digit',
|
'\\D': { label: 'non-digit', ordinal: -1 },
|
||||||
'\\f': 'form feed',
|
'\\f': { label: 'form feed', ordinal: 0x0c },
|
||||||
'\\n': 'line feed',
|
'\\n': { label: 'line feed', ordinal: 0x0a },
|
||||||
'\\r': 'carriage return',
|
'\\r': { label: 'carriage return', ordinal: 0x0d },
|
||||||
'\\s': 'white space',
|
'\\s': { label: 'white space', ordinal: -1 },
|
||||||
'\\S': 'non-white space',
|
'\\S': { label: 'non-white space', ordinal: -1 },
|
||||||
'\\t': 'tab',
|
'\\t': { label: 'tab', ordinal: 0x09 },
|
||||||
'\\v': 'vertical tab',
|
'\\v': { label: 'vertical tab', ordinal: 0x0b },
|
||||||
'\\w': 'word',
|
'\\w': { label: 'word', ordinal: -1 },
|
||||||
'\\W': 'non-word',
|
'\\W': { label: 'non-word', ordinal: -1 },
|
||||||
'\\0': 'null',
|
'\\0': { label: 'null', ordinal: 0 },
|
||||||
'\\1': 'Back reference (group = 1)',
|
'\\1': { label: 'Back reference (group = 1)', ordinal: -1 },
|
||||||
'\\2': 'Back reference (group = 2)',
|
'\\2': { label: 'Back reference (group = 2)', ordinal: -1 },
|
||||||
'\\3': 'Back reference (group = 3)',
|
'\\3': { label: 'Back reference (group = 3)', ordinal: -1 },
|
||||||
'\\4': 'Back reference (group = 4)',
|
'\\4': { label: 'Back reference (group = 4)', ordinal: -1 },
|
||||||
'\\5': 'Back reference (group = 5)',
|
'\\5': { label: 'Back reference (group = 5)', ordinal: -1 },
|
||||||
'\\6': 'Back reference (group = 6)',
|
'\\6': { label: 'Back reference (group = 6)', ordinal: -1 },
|
||||||
'\\7': 'Back reference (group = 7)',
|
'\\7': { label: 'Back reference (group = 7)', ordinal: -1 },
|
||||||
'\\8': 'Back reference (group = 8)',
|
'\\8': { label: 'Back reference (group = 8)', ordinal: -1 },
|
||||||
'\\9': 'Back reference (group = 9)',
|
'\\9': { label: 'Back reference (group = 9)', ordinal: -1 },
|
||||||
'\\012': 'octal: 12',
|
'\\012': { label: 'octal: 12', ordinal: 10 },
|
||||||
'\\cx': 'ctrl-x',
|
'\\cx': { label: 'ctrl-x', ordinal: -1 },
|
||||||
'\\xab': '0xAB',
|
'\\xab': { label: '0xAB', ordinal: 0xab },
|
||||||
'\\uabcd': 'U+ABCD'
|
'\\uabcd': { label: 'U+ABCD', ordinal: 0xabcd }
|
||||||
}, (label, str) => {
|
}, (content, str) => {
|
||||||
it(`parses "${str}" as an Escape`, function() {
|
it(`parses "${str}" as an Escape`, function() {
|
||||||
var parser = new javascript.Parser(str);
|
var parser = new javascript.Parser(str);
|
||||||
expect(parser.__consume__terminal()).toEqual(jasmine.objectContaining({
|
expect(parser.__consume__terminal()).toEqual(jasmine.objectContaining(content));
|
||||||
type: 'escape',
|
|
||||||
label
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -4,5 +4,5 @@ import Escape from './escape.js';
|
|||||||
export default _.extend({}, Escape, {
|
export default _.extend({}, Escape, {
|
||||||
type: 'charset-escape',
|
type: 'charset-escape',
|
||||||
|
|
||||||
b: 'backspace'
|
b: ['backspace', 0x08]
|
||||||
});
|
});
|
||||||
|
@ -16,46 +16,46 @@ export default {
|
|||||||
setup() {
|
setup() {
|
||||||
this.code = this.properties.esc.properties.code.textValue;
|
this.code = this.properties.esc.properties.code.textValue;
|
||||||
this.arg = this.properties.esc.properties.arg.textValue;
|
this.arg = this.properties.esc.properties.arg.textValue;
|
||||||
this.label = _.result(this, this.code);
|
[this.label, this.ordinal] = _.result(this, this.code);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Escape code mappings
|
// Escape code mappings
|
||||||
b: 'word boundary',
|
b: ['word boundary', -1],
|
||||||
B: 'non-word boundary',
|
B: ['non-word boundary', -1],
|
||||||
d: 'digit',
|
d: ['digit', -1],
|
||||||
D: 'non-digit',
|
D: ['non-digit', -1],
|
||||||
f: 'form feed',
|
f: ['form feed', 0x0c],
|
||||||
n: 'line feed',
|
n: ['line feed', 0x0a],
|
||||||
r: 'carriage return',
|
r: ['carriage return', 0x0d],
|
||||||
s: 'white space',
|
s: ['white space', -1],
|
||||||
S: 'non-white space',
|
S: ['non-white space', -1],
|
||||||
t: 'tab',
|
t: ['tab', 0x09],
|
||||||
v: 'vertical tab',
|
v: ['vertical tab', 0x0b],
|
||||||
w: 'word',
|
w: ['word', -1],
|
||||||
W: 'non-word',
|
W: ['non-word', -1],
|
||||||
1: 'Back reference (group = 1)',
|
1: ['Back reference (group = 1)', -1],
|
||||||
2: 'Back reference (group = 2)',
|
2: ['Back reference (group = 2)', -1],
|
||||||
3: 'Back reference (group = 3)',
|
3: ['Back reference (group = 3)', -1],
|
||||||
4: 'Back reference (group = 4)',
|
4: ['Back reference (group = 4)', -1],
|
||||||
5: 'Back reference (group = 5)',
|
5: ['Back reference (group = 5)', -1],
|
||||||
6: 'Back reference (group = 6)',
|
6: ['Back reference (group = 6)', -1],
|
||||||
7: 'Back reference (group = 7)',
|
7: ['Back reference (group = 7)', -1],
|
||||||
8: 'Back reference (group = 8)',
|
8: ['Back reference (group = 8)', -1],
|
||||||
9: 'Back reference (group = 9)',
|
9: ['Back reference (group = 9)', -1],
|
||||||
0() {
|
0() {
|
||||||
if (this.arg) {
|
if (this.arg) {
|
||||||
return `octal: ${this.arg}`;
|
return [`octal: ${this.arg}`, parseInt(this.arg, 8)];
|
||||||
} else {
|
} else {
|
||||||
return 'null';
|
return ['null', 0];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
c() {
|
c() {
|
||||||
return `ctrl-${this.arg}`;
|
return [`ctrl-${this.arg}`, -1];
|
||||||
},
|
},
|
||||||
x() {
|
x() {
|
||||||
return `0x${this.arg.toUpperCase()}`;
|
return [`0x${this.arg.toUpperCase()}`, parseInt(this.arg, 16)];
|
||||||
},
|
},
|
||||||
u() {
|
u() {
|
||||||
return `U+${this.arg.toUpperCase()}`;
|
return [`U+${this.arg.toUpperCase()}`, parseInt(this.arg, 16)];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user