basic language support for sublime and vscode
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
|
||||
fun 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.
|
||||
|
||||
fun copyList(list: List) {
|
||||
|
||||
+13
-11
@@ -11,14 +11,16 @@ fun isDigit(c: String) {
|
||||
and d <= 9;
|
||||
}
|
||||
|
||||
fun skipSpaces(context: Map) {
|
||||
ParsingContext = {str: String, cur: int};
|
||||
|
||||
fun skipSpaces(context: ParsingContext) {
|
||||
# Skip zero or more whitespace characters.
|
||||
while context.cur < count(context.str)
|
||||
and isSpace(context.str[context.cur]):
|
||||
context.cur = context.cur + 1;
|
||||
}
|
||||
|
||||
fun parseNull(context: Map) {
|
||||
fun parseNull(context: ParsingContext) {
|
||||
|
||||
assert(context.cur < count(context.str)
|
||||
and context.str[context.cur] == 'n');
|
||||
@@ -33,7 +35,7 @@ fun parseNull(context: Map) {
|
||||
return none;
|
||||
}
|
||||
|
||||
fun parseTrue(context: Map) {
|
||||
fun parseTrue(context: ParsingContext) {
|
||||
|
||||
assert(context.cur < count(context.str)
|
||||
and context.str[context.cur] == 't');
|
||||
@@ -48,7 +50,7 @@ fun parseTrue(context: Map) {
|
||||
return true;
|
||||
}
|
||||
|
||||
fun parseFalse(context: Map) {
|
||||
fun parseFalse(context: ParsingContext) {
|
||||
|
||||
assert(context.cur < count(context.str)
|
||||
and context.str[context.cur] == 'f');
|
||||
@@ -67,7 +69,7 @@ fun parseFalse(context: Map) {
|
||||
fun dummy() {}
|
||||
Func = type(dummy);
|
||||
|
||||
fun skip(context: Map, test_callback: Func) {
|
||||
fun skip(context: ParsingContext, test_callback: Func) {
|
||||
k = context.cur;
|
||||
while k < count(context.str)
|
||||
and test_callback(context.str[k]):
|
||||
@@ -75,7 +77,7 @@ fun skip(context: Map, test_callback: Func) {
|
||||
return k;
|
||||
}
|
||||
|
||||
fun parseInteger(context: Map) {
|
||||
fun parseInteger(context: ParsingContext) {
|
||||
assert(context.cur < count(context.str) and isDigit(context.str[context.cur]));
|
||||
|
||||
buffer = 0;
|
||||
@@ -91,7 +93,7 @@ fun parseInteger(context: Map) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
fun parseFloating(context: Map) {
|
||||
fun parseFloating(context: ParsingContext) {
|
||||
assert(context.cur < count(context.str)
|
||||
and isDigit(context.str[context.cur]));
|
||||
|
||||
@@ -125,7 +127,7 @@ fun parseFloating(context: Map) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
fun parseIntegerOrFloating(context: Map) {
|
||||
fun parseIntegerOrFloating(context: ParsingContext) {
|
||||
assert(context.cur < count(context.str)
|
||||
and isDigit(context.str[context.cur]));
|
||||
|
||||
@@ -141,7 +143,7 @@ fun parseIntegerOrFloating(context: Map) {
|
||||
return parseInteger(context);
|
||||
}
|
||||
|
||||
fun parseString(context: Map) {
|
||||
fun parseString(context: ParsingContext) {
|
||||
|
||||
assert(context.cur < count(context.str)
|
||||
and context.str[context.cur] == '"');
|
||||
@@ -164,7 +166,7 @@ fun parseString(context: Map) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
fun parseArray(context: Map) {
|
||||
fun parseArray(context: ParsingContext) {
|
||||
assert(context.cur < count(context.str)
|
||||
and context.str[context.cur] == '[');
|
||||
|
||||
@@ -210,7 +212,7 @@ fun parseArray(context: Map) {
|
||||
return list;
|
||||
}
|
||||
|
||||
fun parseValue(context: Map) {
|
||||
fun parseValue(context: ParsingContext) {
|
||||
|
||||
if context.cur == count(context.str):
|
||||
return none, "Source ended where a value was expected";
|
||||
|
||||
@@ -16,4 +16,4 @@
|
||||
|
||||
#define TYPENAME_NULLABLE "NullableType"
|
||||
#define TYPENAME_SUM "SumType"
|
||||
#define TYPENAME_ANY "Any"
|
||||
#define TYPENAME_ANY "AnyType"
|
||||
@@ -1925,7 +1925,7 @@ static _Bool parse_function_arguments(Context *ctx, int *argc_, Node **argv_)
|
||||
type = parse_expression(ctx, 0, 0);
|
||||
if(type == NULL)
|
||||
return 0;
|
||||
} else
|
||||
parameter } else
|
||||
type = NULL;
|
||||
|
||||
Node *defarg; // Default argument (or NULL if there isn't one)
|
||||
|
||||
Binary file not shown.
@@ -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": ";"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user