diff --git a/examples/algorithms/bubble_sort.noja b/examples/algorithms/bubble_sort.noja index b324d1c..8dd635c 100644 --- a/examples/algorithms/bubble_sort.noja +++ b/examples/algorithms/bubble_sort.noja @@ -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) { diff --git a/examples/data_structures/queue.noja b/examples/data_structures/queue.noja index af43928..4206400 100644 --- a/examples/data_structures/queue.noja +++ b/examples/data_structures/queue.noja @@ -8,7 +8,7 @@ fun newCircularQueue(T: Type = int, max: int = 3) { if max <= 0: error("Maximum queue size must be positive"); - + list = []; i = 0; while i < max: { diff --git a/examples/json/json.noja b/examples/json/json.noja index 5455676..45d4059 100644 --- a/examples/json/json.noja +++ b/examples/json/json.noja @@ -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"; diff --git a/examples/list_files.noja b/examples/list_files.noja index ab065c3..080eeda 100644 --- a/examples/list_files.noja +++ b/examples/list_files.noja @@ -1,6 +1,6 @@ # This script reads the contents of the specified # folder, and then prints all of the containd files. - + dirname = '.'; dir = files.openDir(dirname); diff --git a/src/lib/common/defs.h b/src/lib/common/defs.h index bb726f7..87be196 100644 --- a/src/lib/common/defs.h +++ b/src/lib/common/defs.h @@ -16,4 +16,4 @@ #define TYPENAME_NULLABLE "NullableType" #define TYPENAME_SUM "SumType" -#define TYPENAME_ANY "Any" \ No newline at end of file +#define TYPENAME_ANY "AnyType" \ No newline at end of file diff --git a/src/lib/compiler/parse.c b/src/lib/compiler/parse.c index 1607f3f..2ba80b4 100644 --- a/src/lib/compiler/parse.c +++ b/src/lib/compiler/parse.c @@ -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) diff --git a/support/sublime/noja.sublime-package b/support/sublime/noja.sublime-package new file mode 100644 index 0000000..5fa5fb6 Binary files /dev/null and b/support/sublime/noja.sublime-package differ diff --git a/support/vscode/noja/package.json b/support/vscode/noja/package.json new file mode 100644 index 0000000..90d6961 --- /dev/null +++ b/support/vscode/noja/package.json @@ -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" + } + ] + } +} \ No newline at end of file diff --git a/support/vscode/noja/syntaxes/noja.tmLanguage.json b/support/vscode/noja/syntaxes/noja.tmLanguage.json new file mode 100644 index 0000000..80bf761 --- /dev/null +++ b/support/vscode/noja/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": ";" + } + ] +} \ No newline at end of file