Adding a MatchFragment rule
Also reducing the amount of object cloning that is being done
This commit is contained in:
parent
7d84669536
commit
b364198030
@ -3,6 +3,7 @@ import parser from './javascript/grammar.peg';
|
|||||||
import Root from './javascript/root.js';
|
import Root from './javascript/root.js';
|
||||||
import Regexp from './javascript/regexp.js';
|
import Regexp from './javascript/regexp.js';
|
||||||
import Match from './javascript/match.js';
|
import Match from './javascript/match.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 Terminal from './javascript/terminal.js';
|
import Terminal from './javascript/terminal.js';
|
||||||
@ -10,6 +11,7 @@ import Terminal from './javascript/terminal.js';
|
|||||||
parser.Parser.Root = Root;
|
parser.Parser.Root = Root;
|
||||||
parser.Parser.Regexp = Regexp;
|
parser.Parser.Regexp = Regexp;
|
||||||
parser.Parser.Match = Match;
|
parser.Parser.Match = Match;
|
||||||
|
parser.Parser.MatchFragment = MatchFragment;
|
||||||
parser.Parser.Subexp = Subexp;
|
parser.Parser.Subexp = Subexp;
|
||||||
parser.Parser.Charset = Charset;
|
parser.Parser.Charset = Charset;
|
||||||
parser.Parser.Terminal = Terminal;
|
parser.Parser.Terminal = Terminal;
|
||||||
|
@ -2,8 +2,9 @@ grammar JavascriptRegexp
|
|||||||
root <- ( ( "/" regexp "/" _flags:[igm]* ) / regexp ""? ) <Root>
|
root <- ( ( "/" regexp "/" _flags:[igm]* ) / regexp ""? ) <Root>
|
||||||
regexp <- _match:match _alternates:( "|" match )* <Regexp>
|
regexp <- _match:match _alternates:( "|" match )* <Regexp>
|
||||||
match <- _anchor_start:anchor_start?
|
match <- _anchor_start:anchor_start?
|
||||||
_parts:( ( subexp / charset / terminal ) repeat? )*
|
_parts:match_fragment*
|
||||||
_anchor_end:anchor_end? <Match>
|
_anchor_end:anchor_end? <Match>
|
||||||
|
match_fragment <- ( subexp / charset / terminal ) repeat? <MatchFragment>
|
||||||
anchor_start <- "^"
|
anchor_start <- "^"
|
||||||
anchor_end <- "$"
|
anchor_end <- "$"
|
||||||
repeat <- ( repeat_any / repeat_required / repeat_optional / repeat_spec ) repeat_greedy?
|
repeat <- ( repeat_any / repeat_required / repeat_optional / repeat_spec ) repeat_greedy?
|
||||||
|
@ -17,7 +17,7 @@ export default _.extend({}, Base, {
|
|||||||
|
|
||||||
this.contents.parts = _.map(this.parts(), function(part) {
|
this.contents.parts = _.map(this.parts(), function(part) {
|
||||||
var content = container.group();
|
var content = container.group();
|
||||||
part.elements[0].render(content);
|
part.render(content);
|
||||||
return { content, part };
|
return { content, part };
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ export default _.extend({}, Base, {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_.each(this.contents.parts, function(thing) {
|
_.each(this.contents.parts, function(thing) {
|
||||||
thing.part.elements[0].position();
|
thing.part.position();
|
||||||
thing.content.transform(Snap.matrix()
|
thing.content.transform(Snap.matrix()
|
||||||
.translate(offset, 0));
|
.translate(offset, 0));
|
||||||
offset += thing.content.getBBox().width;
|
offset += thing.content.getBBox().width;
|
||||||
@ -62,6 +62,7 @@ export default _.extend({}, Base, {
|
|||||||
|
|
||||||
if (last) {
|
if (last) {
|
||||||
if (node.elements[0].type === 'terminal' && last.elements[0].type === 'terminal' && last.elements[1].textValue === '') {
|
if (node.elements[0].type === 'terminal' && last.elements[0].type === 'terminal' && last.elements[1].textValue === '') {
|
||||||
|
last = _.clone(last, true);
|
||||||
last.textValue += node.textValue;
|
last.textValue += node.textValue;
|
||||||
last.elements[0].textValue += node.elements[0].textValue;
|
last.elements[0].textValue += node.elements[0].textValue;
|
||||||
last.elements[1] = node.elements[1];
|
last.elements[1] = node.elements[1];
|
||||||
@ -71,7 +72,7 @@ export default _.extend({}, Base, {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result.push(_.clone(node, true));
|
result.push(node);
|
||||||
return result;
|
return result;
|
||||||
}, []);
|
}, []);
|
||||||
}
|
}
|
||||||
|
6
src/js/parser/javascript/match_fragment.js
Normal file
6
src/js/parser/javascript/match_fragment.js
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import _ from 'lodash';
|
||||||
|
import Base from './base.js';
|
||||||
|
|
||||||
|
export default _.extend({}, Base, {
|
||||||
|
type: 'match_fragment'
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user