Removing Terminal type and replacing with Literal, Escape, and AnyChar

This is to eventually simplify the combining of Literals together (and
to actually make it work correctly, since terminals should not have been
merged)
This commit is contained in:
Jeff Avallone 2014-12-06 16:03:58 -05:00
parent 41c11ad5d4
commit f5d1e734f1
7 changed files with 30 additions and 12 deletions

View File

@ -6,7 +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 Terminal from './javascript/terminal.js'; import Literal from './javascript/literal.js';
import Escape from './javascript/escape.js';
import AnyCharacter from './javascript/any_character.js';
import Repeat from './javascript/repeat.js'; import Repeat from './javascript/repeat.js';
import RepeatAny from './javascript/repeat_any.js'; import RepeatAny from './javascript/repeat_any.js';
import RepeatOptional from './javascript/repeat_optional.js'; import RepeatOptional from './javascript/repeat_optional.js';
@ -19,7 +21,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.Terminal = Terminal; parser.Parser.Literal = Literal;
parser.Parser.Escape = Escape;
parser.Parser.AnyCharacter = AnyCharacter;
parser.Parser.Repeat = Repeat; parser.Parser.Repeat = Repeat;
parser.Parser.RepeatAny = RepeatAny; parser.Parser.RepeatAny = RepeatAny;
parser.Parser.RepeatOptional = RepeatOptional; parser.Parser.RepeatOptional = RepeatOptional;

View File

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

View File

@ -32,6 +32,8 @@ export default {
}, },
render() { render() {
console.log(this);
this.container.addClass('placeholder'); this.container.addClass('placeholder');
this.label = this.render_label(this.container, this.textValue); this.label = this.render_label(this.container, this.textValue);

View File

@ -2,5 +2,5 @@ import _ from 'lodash';
import Base from './base.js'; import Base from './base.js';
export default _.extend({}, Base, { export default _.extend({}, Base, {
type: 'terminal' type: 'escape'
}); });

View File

@ -39,10 +39,11 @@ grammar JavascriptRegexp
/ octal_esc / octal_esc
/ hex_esc / hex_esc
/ unicode_esc / unicode_esc
/ null_esc / null_esc )
/ literal_esc ) charset_literal <- [^\\\]] / ( "\\" . )
charset_literal <- [^\\\]] terminal <- any_character <AnyCharacter>
terminal <- any_character / escape / literal <Terminal> / escape <Escape>
/ literal <Literal>
any_character <- "." any_character <- "."
escape <- ( word_boundary_esc escape <- ( word_boundary_esc
/ non_word_boundary_esc / non_word_boundary_esc
@ -62,9 +63,8 @@ grammar JavascriptRegexp
/ octal_esc / octal_esc
/ hex_esc / hex_esc
/ unicode_esc / unicode_esc
/ null_esc / null_esc )
/ literal_esc ) literal <- ( ""? literal:[^|\\/.\[\(\)?+*$^] ) / ( "\\" literal:. )
literal <- [^|\\/.\[\(\)?+*$^]
back_reference <- "\\" [1-9] back_reference <- "\\" [1-9]
word_boundary_esc <- "\\b" word_boundary_esc <- "\\b"
non_word_boundary_esc <- "\\B" non_word_boundary_esc <- "\\B"
@ -85,4 +85,3 @@ grammar JavascriptRegexp
hex_esc <- "\\x" [0-9a-fA-F] [0-9a-fA-F] hex_esc <- "\\x" [0-9a-fA-F] [0-9a-fA-F]
unicode_esc <- "\\u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] unicode_esc <- "\\u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F]
null_esc <- "\\0" null_esc <- "\\0"
literal_esc <- "\\" .

View File

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

View File

@ -70,10 +70,11 @@ export default _.extend({}, Base, {
var last = result.pop(); var last = result.pop();
if (last) { if (last) {
if (node.elements[0].type === 'terminal' && node.elements[1].textValue === '' && last.elements[0].type === 'terminal' && last.elements[1].textValue === '') { if (node.elements[0].type === 'literal' && node.elements[1].textValue === '' && last.elements[0].type === 'literal' && last.elements[1].textValue === '') {
last = _.clone(last, true); 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[0].literal.textValue += node.elements[0].literal.textValue;
last.elements[1] = node.elements[1]; last.elements[1] = node.elements[1];
node = last; node = last;
} else { } else {