diff options
| author | Xavier Morel <xmo@openerp.com> | 2012-03-01 12:18:07 +0100 |
|---|---|---|
| committer | Xavier Morel <xmo@openerp.com> | 2012-03-01 12:18:07 +0100 |
| commit | 4a6776d7a11f6c2004358c614411bd662dca2ad6 (patch) | |
| tree | d5a7ffd27e3a2b15b5532d123e434ab20f29e221 /addons/web/static/lib/py.js | |
| parent | e1ef7c7d88c830024376307cb165b01105fb1b60 (diff) | |
[FIX] update py.js, fixes tokenization of expressions with trailing whitespace
bzr revid: xmo@openerp.com-20120301111807-f3lthxw4zkytk42f
Diffstat (limited to 'addons/web/static/lib/py.js')
| -rw-r--r-- | addons/web/static/lib/py.js/.hg_archival.txt | 4 | ||||
| -rw-r--r-- | addons/web/static/lib/py.js/lib/py.js | 39 | ||||
| -rw-r--r-- | addons/web/static/lib/py.js/test/parser.js | 5 | ||||
| -rw-r--r-- | addons/web/static/lib/py.js/test/test.js | 5 |
4 files changed, 31 insertions, 22 deletions
diff --git a/addons/web/static/lib/py.js/.hg_archival.txt b/addons/web/static/lib/py.js/.hg_archival.txt index d78693267b7..d10d8a6b1cc 100644 --- a/addons/web/static/lib/py.js/.hg_archival.txt +++ b/addons/web/static/lib/py.js/.hg_archival.txt @@ -1,5 +1,5 @@ repo: 076b192d0d8ab2b92d1dbcfa3da055382f30eaea -node: 0274b3792917c9eba7b096dc2e8f74a508ddaee6 +node: 7be96c381d9302b4aafaf5eb5381083b0731a9aa branch: default latesttag: 0.4 -latesttagdistance: 4 +latesttagdistance: 7 diff --git a/addons/web/static/lib/py.js/lib/py.js b/addons/web/static/lib/py.js/lib/py.js index 35607b5bdaf..ec6b9182543 100644 --- a/addons/web/static/lib/py.js/lib/py.js +++ b/addons/web/static/lib/py.js/lib/py.js @@ -1,9 +1,5 @@ var py = {}; (function (py) { - var NUMBER = /^\d$/, - NAME_FIRST = /^[a-zA-Z_]$/, - NAME = /^[a-zA-Z0-9_]$/; - var create = function (o, props) { function F() {} F.prototype = o; @@ -256,7 +252,7 @@ var py = {}; var Name = '[a-zA-Z_]\\w*'; - var DecNumber = '\\d+' + var DecNumber = '\\d+'; var IntNumber = DecNumber; var PointFloat = group('\\d+\\.\\d*', '\\.\\d+'); var FloatNumber = PointFloat; @@ -266,7 +262,7 @@ var py = {}; "//=?", "[+\\-*/%&|^=<>]=?", "~"); var Bracket = '[\\[\\]\\(\\)\\{\\}]'; var Special = '[:;.,`@]'; - var Funny = group(Operator, Bracket, Special) + var Funny = group(Operator, Bracket, Special); var ContStr = group("'[^']*'", '"[^"]*"'); @@ -280,8 +276,12 @@ var py = {}; while(pseudoprog.lastIndex < max) { var pseudomatch = pseudoprog.exec(s); if (!pseudomatch) { - throw new Error('Failed to tokenize ' + s - + ' at index ' + (end || 0) + // if match failed on trailing whitespace, end tokenizing + if (/^\s+$/.test(s.slice(end))) { + break; + } + throw new Error('Failed to tokenize <<' + s + + '>> at index ' + (end || 0) + '; parsed so far: ' + tokens); } @@ -325,7 +325,7 @@ var py = {}; tokens.push(create(symbols['(end)'])); return tokens; } - })() + })(); var token, next; function expression(rbp) { @@ -398,9 +398,9 @@ var py = {}; var res = constructor.apply(instance, arguments); // return result of constructor if any, otherwise instance return res || instance; - } + }; return constructor; - } + }; var hash_counter = 0; py.object = py.type(function object() {}, {}, { @@ -467,12 +467,12 @@ var py = {}; throw new Error(this.constructor.name + ' can not be converted to JSON'); } }); - NoneType = py.type(function NoneType() {}, py.object, { + var NoneType = py.type(function NoneType() {}, py.object, { __nonzero__: function () { return py.False; }, toJSON: function () { return null; } }); py.None = new NoneType(); - NotImplementedType = py.type(function NotImplementedType(){}); + var NotImplementedType = py.type(function NotImplementedType(){}); py.NotImplemented = new NotImplementedType(); var booleans_initialized = false; py.bool = py.type(function bool(value) { @@ -641,25 +641,26 @@ var py = {}; return expression(); }; var evaluate_operator = function (operator, a, b) { + var v; switch (operator) { - case '==': return a.__eq__(b) + case '==': return a.__eq__(b); case 'is': return a === b ? py.True : py.False; - case '!=': return a.__ne__(b) + case '!=': return a.__ne__(b); case 'is not': return a !== b ? py.True : py.False; case '<': - var v = a.__lt__(b); + v = a.__lt__(b); if (v !== py.NotImplemented) { return v; } return PY_ensurepy(a.constructor.name < b.constructor.name); case '<=': - var v = a.__le__(b); + v = a.__le__(b); if (v !== py.NotImplemented) { return v; } return PY_ensurepy(a.constructor.name <= b.constructor.name); case '>': - var v = a.__gt__(b); + v = a.__gt__(b); if (v !== py.NotImplemented) { return v; } return PY_ensurepy(a.constructor.name > b.constructor.name); case '>=': - var v = a.__ge__(b); + v = a.__ge__(b); if (v !== py.NotImplemented) { return v; } return PY_ensurepy(a.constructor.name >= b.constructor.name); case 'in': diff --git a/addons/web/static/lib/py.js/test/parser.js b/addons/web/static/lib/py.js/test/parser.js index 16f333f78ac..ca74d2bebc8 100644 --- a/addons/web/static/lib/py.js/test/parser.js +++ b/addons/web/static/lib/py.js/test/parser.js @@ -84,6 +84,11 @@ describe('Tokenizer', function () { expect(toks).to.have.tokens(1); expect(toks[0]).to.be.constant('False'); }); + it('does not fuck up on trailing spaces', function () { + var toks = py.tokenize('None '); + expect(toks).to.have.tokens(1); + expect(toks[0]).to.be.constant('None'); + }); }); describe('collections', function () { it('tokenizes opening and closing symbols', function () { diff --git a/addons/web/static/lib/py.js/test/test.js b/addons/web/static/lib/py.js/test/test.js index cd448e45d79..6c53bcfad85 100644 --- a/addons/web/static/lib/py.js/test/test.js +++ b/addons/web/static/lib/py.js/test/test.js @@ -134,7 +134,10 @@ describe('Comparisons', function () { expect(py.eval('date >= current', {date: '2010-06-08', current: '2010-06-05'})) .to.be(true); - + expect(py.eval('state == "cancel"', {state: 'cancel'})) + .to.be(true); + expect(py.eval('state == "cancel"', {state: 'open'})) + .to.be(false); }); }); describe('missing eq/neq', function () { |
