basic language support for sublime and vscode

This commit is contained in:
cozis
2022-12-06 17:42:37 +01:00
parent 8f2723c3aa
commit a327aa1cf7
9 changed files with 131 additions and 16 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
fun dummy() {} fun dummy() {}
Func = type(dummy); Func = type(dummy);
NFunc = type(print); # The function type is not a build-in at the moment, NFunc = type(print); # The function type is not a built-in at the moment,
# but we can define it manually. # but we can define it manually.
fun copyList(list: List) { fun copyList(list: List) {
+1 -1
View File
@@ -8,7 +8,7 @@ fun newCircularQueue(T: Type = int, max: int = 3) {
if max <= 0: if max <= 0:
error("Maximum queue size must be positive"); error("Maximum queue size must be positive");
list = []; list = [];
i = 0; i = 0;
while i < max: { while i < max: {
+13 -11
View File
@@ -11,14 +11,16 @@ fun isDigit(c: String) {
and d <= 9; and d <= 9;
} }
fun skipSpaces(context: Map) { ParsingContext = {str: String, cur: int};
fun skipSpaces(context: ParsingContext) {
# Skip zero or more whitespace characters. # Skip zero or more whitespace characters.
while context.cur < count(context.str) while context.cur < count(context.str)
and isSpace(context.str[context.cur]): and isSpace(context.str[context.cur]):
context.cur = context.cur + 1; context.cur = context.cur + 1;
} }
fun parseNull(context: Map) { fun parseNull(context: ParsingContext) {
assert(context.cur < count(context.str) assert(context.cur < count(context.str)
and context.str[context.cur] == 'n'); and context.str[context.cur] == 'n');
@@ -33,7 +35,7 @@ fun parseNull(context: Map) {
return none; return none;
} }
fun parseTrue(context: Map) { fun parseTrue(context: ParsingContext) {
assert(context.cur < count(context.str) assert(context.cur < count(context.str)
and context.str[context.cur] == 't'); and context.str[context.cur] == 't');
@@ -48,7 +50,7 @@ fun parseTrue(context: Map) {
return true; return true;
} }
fun parseFalse(context: Map) { fun parseFalse(context: ParsingContext) {
assert(context.cur < count(context.str) assert(context.cur < count(context.str)
and context.str[context.cur] == 'f'); and context.str[context.cur] == 'f');
@@ -67,7 +69,7 @@ fun parseFalse(context: Map) {
fun dummy() {} fun dummy() {}
Func = type(dummy); Func = type(dummy);
fun skip(context: Map, test_callback: Func) { fun skip(context: ParsingContext, test_callback: Func) {
k = context.cur; k = context.cur;
while k < count(context.str) while k < count(context.str)
and test_callback(context.str[k]): and test_callback(context.str[k]):
@@ -75,7 +77,7 @@ fun skip(context: Map, test_callback: Func) {
return k; return k;
} }
fun parseInteger(context: Map) { fun parseInteger(context: ParsingContext) {
assert(context.cur < count(context.str) and isDigit(context.str[context.cur])); assert(context.cur < count(context.str) and isDigit(context.str[context.cur]));
buffer = 0; buffer = 0;
@@ -91,7 +93,7 @@ fun parseInteger(context: Map) {
return buffer; return buffer;
} }
fun parseFloating(context: Map) { fun parseFloating(context: ParsingContext) {
assert(context.cur < count(context.str) assert(context.cur < count(context.str)
and isDigit(context.str[context.cur])); and isDigit(context.str[context.cur]));
@@ -125,7 +127,7 @@ fun parseFloating(context: Map) {
return buffer; return buffer;
} }
fun parseIntegerOrFloating(context: Map) { fun parseIntegerOrFloating(context: ParsingContext) {
assert(context.cur < count(context.str) assert(context.cur < count(context.str)
and isDigit(context.str[context.cur])); and isDigit(context.str[context.cur]));
@@ -141,7 +143,7 @@ fun parseIntegerOrFloating(context: Map) {
return parseInteger(context); return parseInteger(context);
} }
fun parseString(context: Map) { fun parseString(context: ParsingContext) {
assert(context.cur < count(context.str) assert(context.cur < count(context.str)
and context.str[context.cur] == '"'); and context.str[context.cur] == '"');
@@ -164,7 +166,7 @@ fun parseString(context: Map) {
return buffer; return buffer;
} }
fun parseArray(context: Map) { fun parseArray(context: ParsingContext) {
assert(context.cur < count(context.str) assert(context.cur < count(context.str)
and context.str[context.cur] == '['); and context.str[context.cur] == '[');
@@ -210,7 +212,7 @@ fun parseArray(context: Map) {
return list; return list;
} }
fun parseValue(context: Map) { fun parseValue(context: ParsingContext) {
if context.cur == count(context.str): if context.cur == count(context.str):
return none, "Source ended where a value was expected"; return none, "Source ended where a value was expected";
+1 -1
View File
@@ -1,6 +1,6 @@
# This script reads the contents of the specified # This script reads the contents of the specified
# folder, and then prints all of the containd files. # folder, and then prints all of the containd files.
dirname = '.'; dirname = '.';
dir = files.openDir(dirname); dir = files.openDir(dirname);
+1 -1
View File
@@ -16,4 +16,4 @@
#define TYPENAME_NULLABLE "NullableType" #define TYPENAME_NULLABLE "NullableType"
#define TYPENAME_SUM "SumType" #define TYPENAME_SUM "SumType"
#define TYPENAME_ANY "Any" #define TYPENAME_ANY "AnyType"
+1 -1
View File
@@ -1925,7 +1925,7 @@ static _Bool parse_function_arguments(Context *ctx, int *argc_, Node **argv_)
type = parse_expression(ctx, 0, 0); type = parse_expression(ctx, 0, 0);
if(type == NULL) if(type == NULL)
return 0; return 0;
} else parameter } else
type = NULL; type = NULL;
Node *defarg; // Default argument (or NULL if there isn't one) Node *defarg; // Default argument (or NULL if there isn't one)
Binary file not shown.
+24
View File
@@ -0,0 +1,24 @@
{
"name": "Noja",
"version": "0.0.1",
"engines": {
"vscode": ">=0.9.0-pre.1"
},
"publisher": "Francesco Cozzuto",
"contributes": {
"languages": [
{
"id": "Noja",
"aliases": ["Noja", "noja"],
"extensions": [".noja", ".nj"]
}
],
"grammars": [
{
"language": "Noja",
"scopeName": "source.noja",
"path": "./syntaxes/noja.tmLanguage.json"
}
]
}
}
@@ -0,0 +1,89 @@
{
"scopeName": "source.noja",
"fileTypes": ["noja"],
"patterns" : [
{
"name" : "keyword.control.noja",
"match": "\\b(return|if|else|while|do|break|continue)\\b"
},
{
"match": "\\b(fun)\\b[ \\t\\n]*([a-zA-Z_][a-zA-Z0-9_]*)?\\b",
"captures": {
"1": {"name": "keyword.control.noja"},
"2": {"name": "entity.name.function"}
}
},
{
"name": "keyword.operator.word.noja",
"match": "\\b(and|or|not)\\b"
},
{
"name": "keyword.operator.noja",
"match": "(\\+|-|\\*|\\/|=|==|!=|\\>|\\<|\\>=|\\<=|\\|)"
},
{
"name": "constant.language.noja",
"match": "\\b(none|any|true|false)\\b"
},
{
"name" : "string.quoted.double.noja",
"begin": "\"",
"end" : "\"",
"patterns": [
{
"name" : "constant.character.escape.noja",
"match": "\\."
}
]
},
{
"name" : "string.quoted.single.noja",
"begin": "'",
"end" : "'",
"patterns": [
{
"name" : "constant.character.escape.noja",
"match": "\\."
}
]
},
{
"name": "constant.numeric.float.noja",
"match": "[0-9]+\\.[0-9]+"
},
{
"name": "constant.numeric.integer.noja",
"match": "[0-9]+"
},
{
"name": "storage.type.noja",
"match": "\\b(int|float|bool|[_A-Z][A-Za-z0-9_]*)\\b"
},
{
"match": "\\b([a-zA-Z_][a-zA-Z0-9_]*)[ \\t\\n]*\\(",
"captures": {
"1": {"name": "variable.function.noja"}
}
},
{
"name": "variable.other.noja",
"match": "\\b[a-zA-Z_][a-zA-Z0-9_]*\\b"
},
{
"name": "comment.line.number-sign",
"match": "#.*$"
},
{
"name": "punctuation.separator.noja",
"match": "(,|:)"
},
{
"name": "punctuation.accessor.dot.noja",
"match": "\\."
},
{
"name": "punctuation.terminator.noja",
"match": ";"
}
]
}