diff --git a/src/js/parser/javascript.js b/src/js/parser/javascript.js index c84a58b..1ca0c4a 100644 --- a/src/js/parser/javascript.js +++ b/src/js/parser/javascript.js @@ -6,7 +6,9 @@ import Match from './javascript/match.js'; import MatchFragment from './javascript/match_fragment.js'; import Subexp from './javascript/subexp.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 RepeatAny from './javascript/repeat_any.js'; import RepeatOptional from './javascript/repeat_optional.js'; @@ -19,7 +21,9 @@ parser.Parser.Match = Match; parser.Parser.MatchFragment = MatchFragment; parser.Parser.Subexp = Subexp; 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.RepeatAny = RepeatAny; parser.Parser.RepeatOptional = RepeatOptional; diff --git a/src/js/parser/javascript/any_character.js b/src/js/parser/javascript/any_character.js new file mode 100644 index 0000000..bf8df15 --- /dev/null +++ b/src/js/parser/javascript/any_character.js @@ -0,0 +1,6 @@ +import _ from 'lodash'; +import Base from './base.js'; + +export default _.extend({}, Base, { + type: 'any_character' +}); diff --git a/src/js/parser/javascript/base.js b/src/js/parser/javascript/base.js index 66c5b99..2218009 100644 --- a/src/js/parser/javascript/base.js +++ b/src/js/parser/javascript/base.js @@ -32,6 +32,8 @@ export default { }, render() { + console.log(this); + this.container.addClass('placeholder'); this.label = this.render_label(this.container, this.textValue); diff --git a/src/js/parser/javascript/terminal.js b/src/js/parser/javascript/escape.js similarity index 83% rename from src/js/parser/javascript/terminal.js rename to src/js/parser/javascript/escape.js index a9024a2..d4e0980 100644 --- a/src/js/parser/javascript/terminal.js +++ b/src/js/parser/javascript/escape.js @@ -2,5 +2,5 @@ import _ from 'lodash'; import Base from './base.js'; export default _.extend({}, Base, { - type: 'terminal' + type: 'escape' }); diff --git a/src/js/parser/javascript/grammar.peg b/src/js/parser/javascript/grammar.peg index f35c4ed..eabde42 100644 --- a/src/js/parser/javascript/grammar.peg +++ b/src/js/parser/javascript/grammar.peg @@ -39,10 +39,11 @@ grammar JavascriptRegexp / octal_esc / hex_esc / unicode_esc - / null_esc - / literal_esc ) - charset_literal <- [^\\\]] - terminal <- any_character / escape / literal + / null_esc ) + charset_literal <- [^\\\]] / ( "\\" . ) + terminal <- any_character + / escape + / literal any_character <- "." escape <- ( word_boundary_esc / non_word_boundary_esc @@ -62,9 +63,8 @@ grammar JavascriptRegexp / octal_esc / hex_esc / unicode_esc - / null_esc - / literal_esc ) - literal <- [^|\\/.\[\(\)?+*$^] + / null_esc ) + literal <- ( ""? literal:[^|\\/.\[\(\)?+*$^] ) / ( "\\" literal:. ) back_reference <- "\\" [1-9] 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] unicode_esc <- "\\u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] null_esc <- "\\0" - literal_esc <- "\\" . diff --git a/src/js/parser/javascript/literal.js b/src/js/parser/javascript/literal.js new file mode 100644 index 0000000..f4540aa --- /dev/null +++ b/src/js/parser/javascript/literal.js @@ -0,0 +1,6 @@ +import _ from 'lodash'; +import Base from './base.js'; + +export default _.extend({}, Base, { + type: 'literal' +}); diff --git a/src/js/parser/javascript/match.js b/src/js/parser/javascript/match.js index aa7e67b..8d0d329 100644 --- a/src/js/parser/javascript/match.js +++ b/src/js/parser/javascript/match.js @@ -70,10 +70,11 @@ export default _.extend({}, Base, { var last = result.pop(); 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.textValue += node.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]; node = last; } else {