Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b1e3555

Browse files
1.1.0
1 parent a4a0108 commit b1e3555

File tree

25 files changed

+325
-8
lines changed

25 files changed

+325
-8
lines changed

‎1.1.0/ast/syntax.json‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@
99
"type": "WHITESPACE",
1010
"parser": null
1111
},
12+
{
13+
"type": "IMPORT",
14+
"parser": "./syntax/imports"
15+
},
16+
{
17+
"type": "CLASS",
18+
"parser": "./syntax/class"
19+
},
20+
{
21+
"type": "CLASS_INSTANCE",
22+
"parser": "./syntax/class"
23+
},
1224
{
1325
"type": "FUNCTION",
1426
"parser": "./syntax/fun"

‎1.1.0/ast/syntax/class.js‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const { log, err, warn, info, json, success } = require('../../helpers/logger');
2+
3+
module.exports = (peek, consume, peekBack, recall, nextLine, parse) => {
4+
console.log(peek());
5+
if (peek().type == "CLASS") {
6+
// Class creation
7+
consume();
8+
if (peek().type != "ID")
9+
err(`Expected 'ID' but got '${consume().type}'`);
10+
let className = consume().value;
11+
console.log(peek());
12+
if (peek().type != "BRACE_OPEN")
13+
err(`Expected '{' but got '${consume().type}'`);
14+
consume();
15+
let code = [];
16+
do {
17+
let parsed = parse(peek());
18+
if (parsed)
19+
code.push(parsed);
20+
} while (peek().type != "BRACE_CLOSE");
21+
consume();
22+
return {
23+
type: 'CLASS',
24+
name: className,
25+
code: code
26+
};
27+
} else {
28+
// New class instance
29+
consume();
30+
if (peek().type != "ID")
31+
err(`Expected 'ID' but got '${consume().type}'`);
32+
let initializer = parse(peek());
33+
console.log(peek());
34+
return {
35+
type: 'CLASS_INSTANCE',
36+
name: initializer.function,
37+
args: initializer.args
38+
};
39+
}
40+
}

‎1.1.0/ast/syntax/fun.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@ module.exports = (peek, consume, peekBack, recall, nextLine, parse) => {
2727
if (peek().type != "TYPE")
2828
err(`Expected type but got '${peek().type}'`);
2929
arg.type = consume().value;
30+
31+
if ((peek()||{type:null}).type == "ASSIGN") {
32+
consume();
33+
arg.default = parse(peek());
34+
}
35+
3036
fun.args.push(arg);
37+
if ((peek()||{type:null}).type == "COMMA")
38+
consume();
3139
} while (peek().type != "PAREN_CLOSE");
3240
}
3341
consume();

‎1.1.0/ast/syntax/imports.js‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const { log, err, warn, info, json, success } = require('../../helpers/logger');
2+
const { resolve } = require('path');
3+
const fs = require('fs');
4+
5+
module.exports = (peek, consume, peekBack, recall, nextLine, parse) => {
6+
consume();
7+
let path = peek().value.substr(1, peek().value.length - 2);
8+
if (!path.includes('.saur')) {
9+
// It's a built-in library:
10+
path = resolve(__dirname, '../../lib/', path + '.saur');
11+
if (!fs.existsSync(path)) {
12+
err(`The library '${peek().value}' cannot be found. Did you mean to reference a local '.saur' file?`);
13+
}
14+
}
15+
consume();
16+
return {
17+
type: "IMPORT",
18+
path: path
19+
}
20+
}

‎1.1.0/ast/syntax/repeat.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ module.exports = (peek, consume, peekBack, recall, nextLine, parse) => {
3131
consume();
3232
} while ((peek()||{type:null}).type == "NEWLINE");
3333
consume();
34+
do {
35+
consume();
36+
} while ((peek()||{type:null}).type == "NEWLINE");
3437

3538
// We can iterate an array by using `with`. This is the equivalent to doing `for (let item in array)`
3639
if ((peek()||{type:null}).type == "REPEAT_WITH") {

‎1.1.0/helpers/logger.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ function timestamp() {
55
let date = new Date();
66
return '['.gray + ((date.getHours() % 12) + ':' + date.getMinutes() + ':' + date.getSeconds()).magenta + ']'.gray;
77
}*/
8-
prefix = "[".gray + "saur".magenta + "]".gray;
8+
prefix = "[" + "saur".gray + "]";
99

1010
module.exports = {
1111
setPrefix: function(str, intensity) {
1212
let colored = intensity == 0 ? str.yellow : intensity == 1 ? str.green : str.green.bold;
13-
prefix = "[".gray + colored + "]".gray;
13+
prefix = "[" + str.gray + "]";
1414
},
1515
log: function(msg) {
1616
console.log(prefix, msg);

‎1.1.0/lexer/rules.json‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,30 @@
99
"match": "^(\n|\\;)",
1010
"type": "NEWLINE"
1111
},
12+
{
13+
"match": "^\\/\\/.*",
14+
"type": "COMMENT"
15+
},
1216
{
1317
"match": "^\\s+",
1418
"type": "WHITESPACE"
1519
},
20+
{
21+
"match": "^\\@import",
22+
"type": "IMPORT"
23+
},
24+
{
25+
"match": "^class",
26+
"type": "CLASS"
27+
},
28+
{
29+
"match": "^new",
30+
"type": "CLASS_INSTANCE"
31+
},
32+
{
33+
"match": "^loop",
34+
"type": "MAIN_LOOP"
35+
},
1636
{
1737
"match": "^fun",
1838
"type": "FUNCTION"

‎1.1.0/lib/browser.saur‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@import "./browser/page.saur"
2+
@import "./browser/storage.saur"
3+
4+
@export Page
5+
6+
storage: Storage = new Storage()
7+
@export storage

‎1.1.0/lib/browser/http.saur‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fun HttpGET(url: String, callback: Any) {
2+
request: Any = new XMLHttpRequest();
3+
request.addEventListener("load", callback)
4+
request.open("GET", url)
5+
request.send()
6+
}

‎1.1.0/lib/browser/page.saur‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Page {
2+
// The HTML code
3+
html: String
4+
5+
// Template is an array of tuples (a dictionary of sort)
6+
// It looks like this:
7+
// [["title", "Hello World"], ["description", "This is an example app"]]
8+
// This will look for any {{title}} and {{description}} tags in the HTML and replace it
9+
fun render(template: Any, soFar: String = "", i: Int = 0) > String {
10+
if (i < template.length) {
11+
replaced: String = html.replace(template[i][0], tempalte[i][1])
12+
return render(template, replaced, i + 1)
13+
}
14+
}
15+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /