Start merging tokens.
This commit is contained in:
parent
41c82627f9
commit
0f93b3098f
1 changed files with 42 additions and 0 deletions
|
|
@ -275,6 +275,47 @@ var rules = {
|
||||||
'variable': VARIABLE_PROP
|
'variable': VARIABLE_PROP
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merges tokens from start inclusive to end exclusive.
|
||||||
|
* @param {Array.<cvoxAce.Token>} Tokens to be merged.
|
||||||
|
* @param {number} start Start index inclusive.
|
||||||
|
* @param {number} end End index exclusive.
|
||||||
|
* @return {cvoxAce.Token} Merged token.
|
||||||
|
*/
|
||||||
|
var mergeTokens = function(tokens, start, end) {
|
||||||
|
/* Different type of token found! Merge all previous like tokens. */
|
||||||
|
var newToken = {};
|
||||||
|
newToken.value = '';
|
||||||
|
newToken.type = tokens[start].type;
|
||||||
|
for (var j = start; j < end; j++) {
|
||||||
|
newToken.value += tokens[j].value;
|
||||||
|
}
|
||||||
|
return newToken;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merges tokens that use the same speech properties.
|
||||||
|
* @param {Array.<cvoxAce.Token>} tokens Tokens to be merged.
|
||||||
|
* @return {Array.<cvoxAce.Token>} Merged tokens.
|
||||||
|
*/
|
||||||
|
var mergeLikeTokens = function(tokens) {
|
||||||
|
if (tokens.length <= 1) {
|
||||||
|
return tokens;
|
||||||
|
}
|
||||||
|
var newTokens = [];
|
||||||
|
var lastLikeIndex = 0;
|
||||||
|
for (var i = 1; i < tokens.length; i++) {
|
||||||
|
var lastLikeToken = tokens[lastLikeIndex];
|
||||||
|
var currToken = tokens[i];
|
||||||
|
if (getTokenProp(lastLikeToken) !== getTokenProp(currToken)) {
|
||||||
|
newTokens.push(mergeTokens(tokens, lastLikeIndex, i));
|
||||||
|
lastLikeIndex = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newTokens.push(mergeTokens(tokens, lastLikeIndex, tokens.length));
|
||||||
|
return newTokens;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Speak the line with syntax properties.
|
* Speak the line with syntax properties.
|
||||||
* @param {number} row Row to speak.
|
* @param {number} row Row to speak.
|
||||||
|
|
@ -285,6 +326,7 @@ var speakLine = function(row, queue) {
|
||||||
if (tokens.length === 0) {
|
if (tokens.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
tokens = mergeLikeTokens(tokens);
|
||||||
var firstToken = tokens[0];
|
var firstToken = tokens[0];
|
||||||
/* Filter out first token. */
|
/* Filter out first token. */
|
||||||
tokens = tokens.filter(function(token) {
|
tokens = tokens.filter(function(token) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue