Skip to content

Commit

Permalink
Version 0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
santoshrajan committed Jun 18, 2012
1 parent e273eef commit c3d5cba
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,20 @@ Decrements an integer.

Adds up all the strings.

(var title "TITLE")
(var title "My Home Page")
(console.log
(str
"<!DOCTYPE html>\n"
"<html>\n"
"<head>\n"
" <title>" title "</title>\n"
"</head>\n"
"<body>\n"
"Hello World\n"
"</body>\n"
"</html>\n"))
(str "<!DOCTYPE html>
<html>
<head>
<title>" title "</title>
</head>
<body class=\"test\">
Hello World
</body>
</html>"))

In LispyScript double quoted strings are multiline strings. As you can see above they span multiple lines.
If you need a double quote inside the string, escape it with \".

### (if <condition> <true expression> <false expression>)

Expand Down
16 changes: 15 additions & 1 deletion lib/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ templates["try"] = _.template("(function () {try {\n<%= trypart %><%= indent %>}
templates["if"] = _.template("<%= condition %> ?\n<%= indent %><%= trueexpr %> : <%= falseexpr %>");
templates["get"] = _.template("<%= list %>[<%= key %>]");
templates["operator"] = _.template("(<%= loperand %> <%= operator %> <%= roperand %>)");
templates["str"] = _.template("[<%= elems %>].join('')");

var parse = function(code, filename) {
code = "(" + code + ")";
Expand Down Expand Up @@ -64,12 +65,19 @@ var parse = function(code, filename) {
}
if (isComment) continue;
if (c == '"') {
if (isString && token[token.length - 1] === "\\") {
token += c;
continue;
}
isString = !isString;
token += c;
continue;
}
if (isString) {
token += c;
if (c === "\n")
token += "\\n";
else
token += c;
continue;
}
if (c == "'") {
Expand Down Expand Up @@ -323,6 +331,12 @@ keywords["get"] = function(arr) {
return templates["get"]({key: arr[1], list: arr[2]});
};

keywords["str"] = function(arr) {
if (arr.length < 2) throw handleError(0, arr._line, arr._filename);
handleSubExpressions(arr);
return templates["str"]({elems: arr.slice(1).join(",")});
};

keywords["macro"] = function(arr) {
if (arr.length != 4) throw handleError(0, arr._line, arr._filename);
macros[arr[1]] = {template: arr[2], code: arr[3]};
Expand Down
6 changes: 3 additions & 3 deletions src/macros.ls
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
(macro unless (cond rest...)
(when (! ~cond) (do ~rest...)))

(macro str (rest...)
((function ()
((.join (Array.prototype.slice.call arguments)) "")) ~rest...))
#(macro str (rest...)
# ((function ()
# ((.join (Array.prototype.slice.call arguments)) "")) ~rest...))

(macro each (rest...)
(Array.prototype.forEach.call ~rest...))
Expand Down

0 comments on commit c3d5cba

Please sign in to comment.