Comparing version 0.0.48 to 0.0.49
@@ -39,2 +39,7 @@ const RazorError = require('./RazorError'); | ||
characterExpectedAfter(ch, line, pos, after) { | ||
var message = `'${ch}' character is expected after '${after}' at line ${line + 1} pos ${pos + 1}.`; | ||
return RazorError.new({ message, info: this.info, line, pos, capture: this.characterExpected }); | ||
} | ||
expressionMissingEnd(expr, ch, line, pos) { | ||
@@ -41,0 +46,0 @@ var message = `The explicit expression "${expr}" is missing a closing character "${ch}" at line ${line + 1} pos ${pos + 1}.`; |
@@ -894,3 +894,3 @@ 'use strict'; | ||
let op = block.text.trim(); | ||
if (op !== 'function' && op !== 'class') | ||
if (!['function', 'class', 'try'].some(e => e == op)) | ||
break; // [Code 63]: <span>@year is a leap year.</span> | ||
@@ -905,3 +905,3 @@ } | ||
let op = block.text.trim(); | ||
if (op === "do") { | ||
if (['do', 'try'].some(e => e == op)) { | ||
operatorName = op; | ||
@@ -989,2 +989,3 @@ checkForBlockCode = true; | ||
trackFirstLine = (ch !== '\n'); | ||
if (trackFirstLine) | ||
@@ -1002,10 +1003,14 @@ firstLine += ch; | ||
if (waitOperator === waitAcc) { | ||
operatorName = waitOperator; | ||
waitOperator = null; | ||
if (waitAcc === "while") | ||
if (["while", "catch"].some(e => waitAcc === e)) | ||
operatorExpectScope = '('; | ||
else if (["else", "finally"].some(e => waitAcc === e)) | ||
operatorExpectScope = '{'; | ||
} | ||
} | ||
else { | ||
this.stepBack(blocks, waitAcc.length - 1); | ||
stop = true; | ||
waitOperator = null; // outer html (end of code block) | ||
this.stepBack(blocks, waitAcc.length - 1); // [Code 66] | ||
break; | ||
@@ -1019,3 +1024,2 @@ } | ||
this.stepBack(blocks, waitAcc.length); | ||
stop = true; | ||
break; | ||
@@ -1036,4 +1040,4 @@ } | ||
if (operatorExpectScope && !Char.isWhiteSpace(ch) && ch !== operatorExpectScope) | ||
throw this.er.characterExpected(operatorExpectScope, this.lineNum, this.linePos()); | ||
if (operatorExpectScope && !Char.isWhiteSpace(ch) && ch !== operatorExpectScope) | ||
throw this.er.characterExpectedAfter(operatorExpectScope, this.lineNum, this.linePos(), operatorName); // [Code 58, Code 66.1, Code 67.1] | ||
@@ -1052,4 +1056,4 @@ let pos = startScopes.indexOf(ch); | ||
if (operatorExpectScope == ch){ | ||
firstScope = wait; | ||
if (operatorExpectScope == ch) { | ||
//firstScope = wait; | ||
operatorExpectScope = null; | ||
@@ -1062,18 +1066,28 @@ } | ||
wait = waits.pop(); // collasping scope.. | ||
if (!wait && ch === firstScope) { // the last & closing scope.. | ||
switch (operatorName) { | ||
case "if": | ||
waitOperator = "else"; | ||
firstScope = null; | ||
break; | ||
case "do": | ||
waitOperator = "while"; | ||
//firstScope = null; Don't do this for 'while' - it shouldn't expect the '{' char after that. | ||
break; | ||
default: | ||
waitOperator = null; | ||
if (!wait && (operatorName !== "if" || ch === firstScope)) { | ||
if (ch === '}') { // the last & closing scope..) | ||
switch (operatorName) { | ||
case "try": | ||
waitOperator = "catch"; | ||
break; | ||
case "catch": | ||
waitOperator = "finally"; | ||
break; | ||
case "if": | ||
waitOperator = "else"; | ||
//firstScope = null; | ||
break; | ||
case "do": | ||
waitOperator = "while"; | ||
//firstScope = null; Don't do this for 'while' - it shouldn't expect the '{' char after that. | ||
break; | ||
default: | ||
waitOperator = null; | ||
} | ||
operatorName = null; | ||
} | ||
stop = !waitOperator; | ||
waitAcc = ''; | ||
stop = !(waitOperator || operatorName); | ||
skipCh = (ch === '}') && !hasOperator;// skip the outer {} of the code-block | ||
operatorName = null; | ||
} | ||
@@ -1102,2 +1116,5 @@ } | ||
} | ||
else if (!Char.isWhiteSpace(ch)) { | ||
break; | ||
} | ||
} | ||
@@ -1140,5 +1157,5 @@ | ||
if (operatorExpectScope) | ||
throw this.er.characterExpected(operatorExpectScope, this.lineNum, this.linePos()); | ||
throw this.er.characterExpectedAfter(operatorExpectScope, this.lineNum, this.linePos(), operatorName); // [Code 55] | ||
if (waitOperator === "while") | ||
if (waitOperator === "while") // all others are optional | ||
throw this.er.wordExpected(waitOperator, this.lineNum, this.linePos() - waitAcc.length); // [Code 60] | ||
@@ -1145,0 +1162,0 @@ |
{ | ||
"name": "raz", | ||
"description": "Razor-like syntax for templating views in NodeJS Express framework by mixing HTML with JavaScript.", | ||
"version": "0.0.48", | ||
"version": "0.0.49", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Sergey", |
@@ -459,5 +459,4 @@ (function () { | ||
} | ||
else | ||
`, | ||
error: "'{' character is expected at line 8 pos 5" | ||
else `, | ||
error: `'{' character is expected after 'else' at line 8 pos 6.` | ||
}, | ||
@@ -514,3 +513,3 @@ { | ||
`, | ||
error: `'(' character is expected at line 8 pos 8.` | ||
error: `'(' character is expected after 'while' at line 8 pos 8.` | ||
}, | ||
@@ -581,3 +580,3 @@ { | ||
} | ||
else{ | ||
else { | ||
<span>@year is not a leap year.</span> | ||
@@ -610,2 +609,52 @@ } | ||
error: "Unexpected token <" | ||
}, | ||
{ | ||
name: "Code 66", | ||
template: ` | ||
@try { | ||
throw new Error("Test exception."); | ||
} | ||
catch (ex) { | ||
<p>The exception message: @ex.message</p> | ||
} | ||
<br/>`, | ||
expected: "\n <p>The exception message: Test exception.</p>\n<br/>" | ||
}, | ||
{ | ||
name: "Code 66.1", | ||
template: ` | ||
@try { | ||
throw new Error("Test exception."); | ||
} | ||
catch | ||
<br/>`, | ||
error: `'(' character is expected after 'catch' at line 6 pos 1.` | ||
}, | ||
{ | ||
name: "Code 67", | ||
template: ` | ||
@try { | ||
throw new Error("try exception"); | ||
} | ||
catch (ex) { | ||
<p>The exception message: @ex.message</p> | ||
} | ||
finally { | ||
<p>finally</p> | ||
} | ||
<br/>`, | ||
expected: "\n <p>The exception message: try exception</p>\n <p>finally</p>\n<br/>" | ||
}, | ||
{ | ||
name: "Code 67.1", | ||
template: ` | ||
@try { | ||
throw new Error("try exception"); | ||
} | ||
catch (ex) { | ||
<p>The exception message: @ex.message</p> | ||
} | ||
finally | ||
<br/>`, | ||
error: `'{' character is expected after 'finally' at line 9 pos 1.` | ||
} | ||
@@ -612,0 +661,0 @@ ]; |
196734
4095