@@ -0,0 +1,176 @@
(function () {

$data.Class.define('$data.oDataParser.ASCII', null, null, {}, {
NULL: { value: "\u0000" },
HTAB: { value: 9 },
LF: { value: 10 },
VTAB: { value: 11 },
CR: { value: 13 },
SPC: { value: 32 },
DOLLAR: { value: 36 }, // $
AMP: { value: 38 }, // &
APOS: { value: 39 }, // '
LPAREN: { value: 40 }, // (
RPAREN: { value: 41 }, // )
PLUS: { value: 43 }, // +
COMMA: { value: 44 }, // },
MINUS: { value: 45 }, // -
DOT: { value: 46 }, // .
SLASH: { value: 47 }, // /
ZERO: { value: 48 }, // 0
NINE: { value: 57 }, // 9
COLON: { value: 58 }, // :
A: { value: 65 },
Z: { value: 90 },
UNDERSCORE: { value: 95 }, // _
a: { value: 97 },
z: { value: 122 }
});

$data.Class.define('$data.oDataParser.CharType', null, null, {}, {
EOF: { value: 0 }, WSP: { value: 1 }, CTRLCHAR: { value: 2 }, CHAR: { value: 3 }, DIGITS: { value: 4 }, ALPHA: { value: 5 }
});

$data.Class.define('$data.oDataParser.TokenType', null, null, {}, {
EOF: { value: 0 }, WSP: { value: 1 }, CTRLCHAR: { value: 2 }, CHAR: { value: 3 }, DIGITS: { value: 4 }, WORD: { value: 5 }, STRING: { value: 6 }
});

var ASCII = $data.oDataParser.ASCII;
var CharType = $data.oDataParser.CharType;
var TokenType = $data.oDataParser.TokenType;


$data.Class.define('$data.oDataParser.RequestToken', null, null, {
constructor: function () {
this.tokenType = TokenType.EOF;
this.value = "";
this.line = -1;
this.column = -1;
},
toString: function () {
if (this.tokenType == TokenType.DIGITS || this.tokenType == TokenType.WORD || this.tokenType == TokenType.STRING)
return this.value;
else if (this.tokenType == TokenType.CTRLCHAR || this.tokenType == TokenType.CHAR || this.tokenType == TokenType.WSP)
return String.fromCharCode(this.value);
return "[EOF]";
}
});

$data.Class.define('$data.oDataParser.RequestLexer', null, null, {
constructor: function (src) {
this.src = src;
this.srcLength = src.length;
this.srcIndex = 0;
this.token = null;
this.currentChar = ASCII.NULL;
this.currentCharType = CharType.EOF;
this.line = 0;
this.column = -1;
this.nextChar();
this.nextToken();
},
nextChar: function () {
if (this.srcIndex >= this.srcLength) {
this.currentChar = '\0';
this.currentCharType = CharType.EOF;
this.column++;
return false;
}
if (this.currentChar == ASCII.CR) {
this.line++;
this.column = -1;
}
this.currentChar = this.src.charCodeAt(this.srcIndex++);
this.column++;
this.currentCharType = this.getCharType(this.currentChar);
return true;
},
getCharType: function (c) {
if (c == ASCII.NULL) return CharType.EOF;
if (c == ASCII.HTAB) return CharType.WSP;
if (c < ASCII.SPC) return CharType.CTRLCHAR;
if (c == ASCII.SPC) return CharType.WSP;
if (c < ASCII.ZERO) return CharType.CHAR;
if (c <= ASCII.NINE) return CharType.DIGIT;
if (c < ASCII.A) return CharType.CHAR;
if (c <= ASCII.Z) return CharType.ALPHA;
if (c < ASCII.a) return CharType.CHAR;
if (c <= ASCII.z) return CharType.ALPHA;
return c;
},
nextToken: function () {
/*
whitespace:
SPC HTAB VTAB CR LF
char:
'-!$%&()*,./:;?@[]_{}~+= ; ????
digit:
0 1 2 3 4 5 6 7 8 9
word:
add all ...
string:
' char | whitespace | digit | alpha '
*/
this.skipWhiteSpaces();
var token = new $data.oDataParser.RequestToken();
this.token = token;
token.line = this.line;
token.column = this.column;
switch (this.currentCharType) {
case CharType.EOF: token.tokenType = TokenType.EOF; token.value = this.currentChar; return;
case CharType.WSP: token.tokenType = TokenType.WSP; token.value = this.currentChar; this.nextChar(); return;
case CharType.CTRLCHAR: token.tokenType = TokenType.CTRLCHAR; token.value = this.currentChar; this.nextChar(); return;
case CharType.CHAR:
var startIndex = this.srcIndex;
if (this.currentChar == ASCII.APOS && this.readTo("'")) {
token.tokenType = TokenType.STRING;
var length = this.srcIndex - startIndex - 1;
token.value = this.src.substr(startIndex, this.srcIndex - startIndex - 1);
this.column += length + 1;
}
else {
token.tokenType = TokenType.CHAR;
token.value = this.currentChar;
}
this.nextChar();
return;
case CharType.DIGIT: this.scanDigits(token); return;
case CharType.ALPHA: this.scanWord(token); return;
default:
throw "Unknown CharType: " + this.currentCharType;
}
},
readTo: function (str) {
if (this.srcIndex == this.srcLength - 1)
return false;
var p = this.src.indexOf(str, this.srcIndex + 1);
if (p < 0)
return false;
this.srcIndex = p + 1;
return true;
},
skipWhiteSpaces: function () {
while (this.currentCharType == CharType.WSP && this.nextChar()) { }
},
scanDigits: function (token) {
var startIndex = this.srcIndex - 1;
var length = 0;
token.tokenType = TokenType.DIGITS;
while (this.currentCharType == CharType.DIGIT) {
this.nextChar();
length++;
}
token.value = this.src.substr(startIndex, length);
},
scanWord: function (token) {
var startIndex = this.srcIndex - 1;
var length = 0;
while (this.currentCharType == CharType.ALPHA) {
this.nextChar();
length++;
}
token.tokenType = TokenType.WORD;
token.value = this.src.substr(startIndex, length);
}
});
})();

Large diffs are not rendered by default.

@@ -1,7 +1,7 @@
$(document).ready(function () {
module("Current tests");
test("Select: Name, Age, City", 1, function () {
var req = new ODataQueryRequest(); var p = new ODataRequestParser(); p.req = req;
var req = new $data.oDataParser.QueryRequest(); var p = new $data.oDataParser.RequestParser(); p.req = req;
req.select = "Name, Age, City";
p.parseSelectExpr();
var current = JSON.stringify(p.req.select);
@@ -22,7 +22,7 @@ $(document).ready(function () {
equal(current, expected);
});
test("Select: Name, Age add 20, City", 1, function () {
var req = new ODataQueryRequest(); var p = new ODataRequestParser(); p.req = req;
var req = new $data.oDataParser.QueryRequest(); var p = new $data.oDataParser.RequestParser(); p.req = req;
req.select = "Name, Age add 20, City";
p.parseSelectExpr();
var current = JSON.stringify(p.req.select);
@@ -47,7 +47,7 @@ $(document).ready(function () {
equal(current, expected);
});
test("Select: Title, concat(Author/FirstName, Author/LastName)", 1, function () {
var req = new ODataQueryRequest(); var p = new ODataRequestParser(); p.req = req;
var req = new $data.oDataParser.QueryRequest(); var p = new $data.oDataParser.RequestParser(); p.req = req;
req.select = "Title, concat(Author/FirstName, Author/LastName)";
p.parseSelectExpr();
var current = JSON.stringify(p.req.select);
@@ -79,7 +79,7 @@ $(document).ready(function () {

/*
test("Lambda syntax: Products/any()", 1, function () {
var src = new ODataQueryRequest(); var p = new ODataRequestParser(); p.req = src;
var src = new $data.oDataParser.QueryRequest(); var p = new $data.oDataParser.RequestParser(); p.req = src;
src.filter = "Products/any()";
p.parseFilterExpr();
var current = JSON.stringify(p.req.filter);

This file was deleted.

This file was deleted.

@@ -1,16 +1,19 @@
$(document).ready(function () {
module("ODataRequestParser Lexer tests");
var ASCII = $data.oDataParser.ASCII;
var CharType = $data.oDataParser.CharType;
var TokenType = $data.oDataParser.TokenType;

test("NextChar: empty source", 2, function () {
var src = "";
var l = new ODataRequestLexer(src);
var l = new $data.oDataParser.RequestLexer(src);
l.nextChar();
equal(l.currentChar, ASCII.NULL);
equal(l.currentCharType, CharType.EOF);
});
test("NextChar: character classes", 36, function () {
var src = ". aAzZ 09\r\n.asdf42";
var l = new ODataRequestLexer(src);
var l = new $data.oDataParser.RequestLexer(src);
equal(l.currentChar, ASCII.SPC, "1"); equal(l.currentCharType, CharType.WSP, "2");
l.nextChar(); equal(l.currentChar, ASCII.a, "3"); equal(l.currentCharType, CharType.ALPHA, "4");
l.nextChar(); equal(l.currentChar, ASCII.A, "5"); equal(l.currentCharType, CharType.ALPHA, "6");
@@ -32,42 +35,42 @@ $(document).ready(function () {
});
test("OneToken: word", 2, function () {
var src = "asdf";
var l = new ODataRequestLexer(src);
var l = new $data.oDataParser.RequestLexer(src);
var t=l.token;
equal(t.tokenType, TokenType.WORD);
equal(t.value, "asdf");
});
test("OneToken: word and spaces", 2, function () {
var src = " asdf ";
var l = new ODataRequestLexer(src);
var l = new $data.oDataParser.RequestLexer(src);
var t=l.token;
equal(t.tokenType, TokenType.WORD);
equal(t.value, "asdf");
});
test("OneToken: digits", 2, function () {
var src = "42";
var l = new ODataRequestLexer(src);
var l = new $data.oDataParser.RequestLexer(src);
var t=l.token;
equal(t.tokenType, TokenType.DIGITS);
equal(t.value, "42");
});
test("OneToken: lot of digits", 2, function () {
var src = "1234567890123456789012345678901234567890";
var l = new ODataRequestLexer(src);
var l = new $data.oDataParser.RequestLexer(src);
var t=l.token;
equal(t.tokenType, TokenType.DIGITS);
equal(t.value, "1234567890123456789012345678901234567890");
});
test("OneToken: string", 2, function () {
var src = " 'asdf' ";
var l = new ODataRequestLexer(src);
var l = new $data.oDataParser.RequestLexer(src);
var t=l.token;
equal(t.tokenType, TokenType.STRING);
equal(t.value, "asdf");
});
test("Next token", 10, function () {
var src = "x asdf 'yxcv' qwer 12 ";
var l = new ODataRequestLexer(src);
var l = new $data.oDataParser.RequestLexer(src);
var t;
l.nextToken();t=l.token; equal(t.tokenType, TokenType.WORD, "1"); equal(t.value, "asdf", "2");
l.nextToken();t=l.token; equal(t.tokenType, TokenType.STRING, "3"); equal(t.value, "yxcv", "4");
@@ -78,7 +81,7 @@ $(document).ready(function () {
test("Column info 1", 6, function () {
// 012345678
var src = "x asdf ";
var l = new ODataRequestLexer(src);
var l = new $data.oDataParser.RequestLexer(src);
var t;
l.nextToken();t=l.token; equal(t.tokenType, TokenType.WORD, "t1"); equal(t.value, "asdf", "v1"); equal(t.column, 2, "c1");
l.nextToken();t=l.token; equal(t.tokenType, TokenType.EOF, "t2"); equal(t.value, "\u0000", "v2"); equal(t.column, 8, "c2");
@@ -87,7 +90,7 @@ $(document).ready(function () {
// 0 1 2
// 0123456789012345678901
var src = "x asdf 'yxcv' qwer 12 ";
var l = new ODataRequestLexer(src);
var l = new $data.oDataParser.RequestLexer(src);
var t;
l.nextToken();t=l.token; equal(t.tokenType, TokenType.WORD, "t1"); equal(t.value, "asdf", "v1"); equal(t.column, 2, "c1");
l.nextToken();t=l.token; equal(t.tokenType, TokenType.STRING, "t2"); equal(t.value, "yxcv", "v2"); equal(t.column, 7, "c2");

Large diffs are not rendered by default.

@@ -169,15 +169,15 @@
<!--************************************************************************************-->
<script src="../NewsReaderContext.js" type="text/javascript"></script>

<script type="text/javascript" src="gyeby.orp.builder.js"></script>
<script type="text/javascript" src="gyeby.orp.lexer.js"></script>
<script type="text/javascript" src="gyeby.orp.parser.js"></script>
<!--**********************************UNIT TESTS****************************************-->
<script type="text/javascript" src="ODataEntityExpressionBuilder.js"></script>
<script type="text/javascript" src="ExpressionBuilder.js"></script>
<script type="text/javascript" src="RequestLexer.js"></script>
<script type="text/javascript" src="RequestParser.js"></script>

<script type="text/javascript" src="gyeby.orp.currenttest.js"></script>
<script type="text/javascript" src="gyeby.orp.lexertests.js"></script>
<script type="text/javascript" src="gyeby.orp.parsertests.js"></script>
<script type="text/javascript" src="EntityExpressionBuilder.js"></script>
<!--**********************************UNIT TESTS****************************************-->
<script type="text/javascript" src="currentTests.js"></script>
<script type="text/javascript" src="lexerTests.js"></script>
<script type="text/javascript" src="parserTests.js"></script>
<script type="text/javascript">
function builderTest(name, queryable, context, isCount) {
test(name, 2, function () {
@@ -200,22 +200,22 @@

obj.entitySetName = queryParts[0].split('/')[1];
obj.count = queryParts[0].indexOf('$count') > 0;
var builder = new $data.oDataParser.ODataEntityExpressionBuilder(context);
var builder = new $data.oDataParser.EntityExpressionBuilder(context);
var expression = builder.buildExpression(obj);

equal(expression.getType(), q.expression.getType(), name + 'expression frame failed');
equal(JSON.stringify(expression.source), JSON.stringify(q.expression.source), name + ' builder test failed');
});
}
/*

var c = new $news.Types.NewsContext({ name: 'oData' });
var date = new Date();

module('ODataEntityExpressionBuilder');
module('EntityExpressionBuilder');
builderTest('field compare int', c.Articles.filter(function (it) { return it.Id <= 500; }), c);
builderTest('field compare int', c.Articles.filter(function (it) { return it.Id <= 500; }), c, true);
builderTest('field compare string / $count', c.Articles.filter(function (it) { return it.Title == 'Article1'; }), c);
//builderTest('ODataEntityExpressionBuilder field multipleFilter', c.Articles.filter(function (it) { return it.Title == 'Article1'; }).filter(function (it) { return it.Body.contains('Body1'); }), c);
//builderTest('field multipleFilter', c.Articles.filter(function (it) { return it.Title == 'Article1'; }).filter(function (it) { return it.Body.contains('Body1'); }), c);
builderTest('field contains', c.Articles.filter(function (it) { return it.Author.LoginName.contains('almafa'); }), c);
builderTest('field contains / $count', c.Articles.filter(function (it) { return it.Author.LoginName.contains('almafa'); }), c, true);
builderTest('field compare complex', c.Articles.filter(function (it) { return it.Author.LoginName.contains('almafa') && it.CreateDate > '2001/05/05' && it.Id <= 500; }), c);
@@ -230,7 +230,7 @@
builderTest('take', c.Articles.take(6), c);
builderTest('field compare, order by, skip, take', c.Articles.filter(function (it) { return it.Author.LoginName.contains('almafa') && it.CreateDate > '2001/05/05' && it.Id <= 500; }).orderBy('it.Title').skip(10).take(5), c);
//builderTest('map', c.Articles.map(function (it) { return { a: it.Title, b: it.Body }; }), c);
*/

</script>
</head>
<body>