Skip to content

Commit

Permalink
1.更正错误jison版本生成的clearsilver.js,修复记法分析include时就出错的问题;\n2.自定义出错处理,可提示出错…
Browse files Browse the repository at this point in the history
…文件名,更方便调试
  • Loading branch information
penglei committed Mar 24, 2014
1 parent 07dd6af commit 92c661c
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 13 deletions.
26 changes: 25 additions & 1 deletion interpreter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ function insertArray(arr, item){
}
arr.push(item);
}

function parseError(str, hash, engine){
var filepath = this.yy.fileid == 1 ? this.yy.filename : engine._includeParentBase + '/' + this.yy.filename;
str = 'Parse error on line : ' + (hash.line + 1) + ', in file --> ' + filepath + '\n' + this.lexer.showPosition();
if (hash.expected) {
str += '\nExpecting ' + hash.expected.join(', ') + ', got \'' + hash.token + '\'';
} else {//XXX only lex error go here?
str += '\nUnrecognized text.\n'
}
throw new Error(str);
}


function Engine(csString){
this.result = "";
this._debugMode = false;
Expand All @@ -30,6 +43,12 @@ function Engine(csString){
this.csparser = new ClearSilverParser();

this.csparser.yy.filename = this._entryPathname = "[main]";
this.csparser.yy.parseError = function(){
var args = Array.prototype.slice.call(arguments);
args.push(self);
parseError.apply(this, args);
};

this._entryPathIsDefault = true;
this._includeParentBase = "$(root)";

Expand Down Expand Up @@ -65,6 +84,11 @@ Engine.prototype._lexInclude = function(includeName) {
//同一个文件只需要解析一次,语法树只允许读,每个地方不需要重新生成
//TODO 检查循环依赖
var csSubParser = new ClearSilverParser();
csSubParser.yy.parseError = function(){
var args = Array.prototype.slice.call(arguments);
args.push(self);
parseError.apply(this, args);
};
csSubParser.lexer.include = function(name){
self._lexInclude(name);
};
Expand Down Expand Up @@ -130,7 +154,7 @@ Engine.prototype.onRender = function(cb){
Engine.prototype.initEntrySource = function(csString, pathname){
if (pathname !== undefined) {
this._entryPathIsDefault = false;
this.csparser.yy.name = this._entryPathname = pathname + " [main]";
this.csparser.yy.filename = this._entryPathname = pathname + " [main]";
}
var fileid = this._saveSource(this._entryPathname, csString);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jencs",
"version": "0.1.3",
"version": "0.1.8",
"description": "clearsilver render engine, with a debugger",
"keywords": [
"clearsilver",
Expand Down
23 changes: 13 additions & 10 deletions parse/clearsilver.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/dev/aaa
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?cs include:"bbb"?>
4 changes: 4 additions & 0 deletions test/dev/bbb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@



<?cs bbb content?>
1 change: 0 additions & 1 deletion test/dev/test_include.cs
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<?cs include:"aaa"?>
<?cs include:"bbb"?>

0 comments on commit 92c661c

Please sign in to comment.