Skip to content

Commit

Permalink
Extend grammar JSON with meta.regExpFlags option
Browse files Browse the repository at this point in the history
  • Loading branch information
yuryleb committed Oct 4, 2017
1 parent 2991bc5 commit 044836a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,8 @@ module.exports = function(version, _options) {
// if both are the same we assume that there used to be an empty name, with the ref being filled in for it
// we only need to retain the ref then
name = '';
} else {
name = name.replace(' (' + step.ref + ')', '');
}
name = name.replace(' (' + step.ref + ')', '');

// In attempt to avoid using the highway name of a way,
// check and see if the step has a class which should signal
Expand Down Expand Up @@ -207,8 +206,9 @@ module.exports = function(version, _options) {
if (rules) {
// Pass original name to rules' regular expressions enclosed with spaces for simplier parsing
var n = ' ' + name + ' ';
var flags = grammars[language].meta.regExpFlags || '';
rules.forEach(function(rule) {
var re = new RegExp(rule[0]);
var re = new RegExp(rule[0], flags);
n = n.replace(re, rule[1]);
});

Expand Down
3 changes: 3 additions & 0 deletions languages/grammar/ru.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"meta": {
"regExpFlags": ""
},
"v5": {
"accusative": [
["^ (\\S+)ая [Аа]ллея ", " $1ую аллею "],
Expand Down
4 changes: 2 additions & 2 deletions languages/overrides/ru.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function iterate(values) {
};

module.exports = function(content) {
// Iterate all string values recursively
iterate(content);
// Iterate all content string values recursively
iterate(content.v5);
return content;
};
2 changes: 1 addition & 1 deletion test/grammar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ tape.test('verify grammar files structure', function(assert) {
var b = Array.isArray(e) && e.length === 2;
if (b) {
// all regular expressions from grammar should not match empty string
r = new RegExp(e[0]);
r = new RegExp(e[0], grammar.meta.regExpFlags);
b = ''.replace(r, e[1]) === '';
}

Expand Down

0 comments on commit 044836a

Please sign in to comment.