123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- goog.provide('goog.dom.pattern.Sequence');
- goog.require('goog.dom.NodeType');
- goog.require('goog.dom.pattern');
- goog.require('goog.dom.pattern.AbstractPattern');
- goog.require('goog.dom.pattern.MatchType');
- goog.dom.pattern.Sequence = function(patterns, opt_ignoreWhitespace) {
-
- this.patterns = patterns;
-
- this.ignoreWhitespace_ = !!opt_ignoreWhitespace;
-
- this.currentPosition_ = 0;
- };
- goog.inherits(goog.dom.pattern.Sequence, goog.dom.pattern.AbstractPattern);
- goog.dom.pattern.Sequence.BREAKING_TEXTNODE_RE_ = /^\s*$/;
- goog.dom.pattern.Sequence.prototype.matchToken = function(token, type) {
-
- if (this.ignoreWhitespace_ && token.nodeType == goog.dom.NodeType.TEXT &&
- goog.dom.pattern.Sequence.BREAKING_TEXTNODE_RE_.test(token.nodeValue)) {
- return goog.dom.pattern.MatchType.MATCHING;
- }
- switch (this.patterns[this.currentPosition_].matchToken(token, type)) {
- case goog.dom.pattern.MatchType.MATCH:
-
- if (this.currentPosition_ == 0) {
- this.matchedNode = token;
- }
-
- this.currentPosition_++;
-
- if (this.currentPosition_ == this.patterns.length) {
- this.reset();
- return goog.dom.pattern.MatchType.MATCH;
- } else {
- return goog.dom.pattern.MatchType.MATCHING;
- }
- case goog.dom.pattern.MatchType.MATCHING:
-
- return goog.dom.pattern.MatchType.MATCHING;
- case goog.dom.pattern.MatchType.BACKTRACK_MATCH:
-
-
- this.currentPosition_++;
- if (this.currentPosition_ == this.patterns.length) {
- this.reset();
- return goog.dom.pattern.MatchType.BACKTRACK_MATCH;
- } else {
-
- return this.matchToken(token, type);
- }
- default:
- this.reset();
- return goog.dom.pattern.MatchType.NO_MATCH;
- }
- };
- goog.dom.pattern.Sequence.prototype.reset = function() {
- if (this.patterns[this.currentPosition_]) {
- this.patterns[this.currentPosition_].reset();
- }
- this.currentPosition_ = 0;
- };
|