diff --git a/grammars.yml b/grammars.yml index 13979f0c14..c1d548e846 100644 --- a/grammars.yml +++ b/grammars.yml @@ -120,6 +120,8 @@ vendor/grammars/Slash.tmbundle: vendor/grammars/Stata.tmbundle: - source.mata - source.stata +vendor/grammars/strata-grammar: +- source.strata vendor/grammars/Stylus: - source.stylus vendor/grammars/Sublime-Coq: diff --git a/lib/linguist/heuristics.yml b/lib/linguist/heuristics.yml index 17d6802916..b409e7dfe9 100644 --- a/lib/linguist/heuristics.yml +++ b/lib/linguist/heuristics.yml @@ -125,6 +125,15 @@ disambiguations: named_pattern: vba - language: Visual Basic 6.0 named_pattern: vb-module +- extensions: [".str"] + rules: + - language: Strata + pattern: >- + (?x) + \\b (func) \\b | + \\b import \\s+ \\w+ \\s+ from \\s+ | + (std|package):: \\w+ | + => - extensions: ['.bb'] rules: - language: BlitzBasic diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 7ea73879c5..e29eca650a 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -7496,6 +7496,14 @@ Stata: tm_scope: source.stata ace_mode: text language_id: 358 +Strata: + type: programming + color: "#4B0082" + extensions: + - ".str" + tm_scope: source.strata + ace_mode: text + language_id: 744998756 StringTemplate: type: markup color: "#3fb34f" diff --git a/samples/Strata/algorithms.str b/samples/Strata/algorithms.str new file mode 100644 index 0000000000..5c22656de6 --- /dev/null +++ b/samples/Strata/algorithms.str @@ -0,0 +1,95 @@ +// Examples: Common Algorithms +// Demonstrates: practical algorithm implementations + +import io from str +import math from str + +io.print("=== Fibonacci Sequence ===") +var a: int = 0 +var b: int = 1 + +for (var i: int = 0; i < 10; var i: int = i + 1) { + io.print(a) + let temp: int = a + b + var a: int = b + var b: int = temp +} + +io.print("=== Prime Number Check ===") + +func isPrime(n: int) => bool { + if (n <= 1) { + return false + } + + if (n == 2) { + return true + } + + if (n % 2 == 0) { + return false + } + + var i: int = 3 + while (i * i <= n) { + if (n % i == 0) { + return false + } + var i: int = i + 2 + } + + return true +} + +io.print("Primes up to 30:") +for (var num: int = 2; num <= 30; var num: int = num + 1) { + if (isPrime(num)) { + io.print(num) + } +} + +io.print("=== Sum of Digits ===") + +func sumDigits(n: int) => int { + var sum: int = 0 + var num: int = n + + while (num > 0) { + var digit: int = num % 10 + var sum: int = sum + digit + var num: int = num / 10 + } + + return sum +} + +io.print(sumDigits(12345)) +io.print(sumDigits(999)) + +io.print("=== GCD (Greatest Common Divisor) ===") + +func gcd(a: int, b: int) => int { + while (b != 0) { + let temp: int = b + var b: int = a % b + var a: int = temp + } + return a +} + +io.print(gcd(48, 18)) +io.print(gcd(100, 75)) + +io.print("=== Linear Search ===") + +func contains(target: int) => bool { + for (var i: int = 1; i <= 10; var i: int = i + 1) { + if (i == target) { + return true + } + } + return false +} + +io.print(contains(5)) +io.print(contains(15)) diff --git a/samples/Strata/functions.str b/samples/Strata/functions.str new file mode 100644 index 0000000000..9d6ec6487c --- /dev/null +++ b/samples/Strata/functions.str @@ -0,0 +1,66 @@ +// Examples: Function Declarations +// Demonstrates: func with type annotations and return types + +import io from str + +// Simple function - no parameters +func greet() => string { + return "Hello, Strata!" +} + +io.print("=== Greeting ===") +io.print(greet()) + +// Function with parameters +func add(a: int, b: int) => int { + return a + b +} + +io.print("=== Addition ===") +let result: int = add(10, 20) +io.print(result) + +// Function with multiple parameters +func multiply(x: int, y: int) => int { + return x * y +} + +io.print("=== Multiplication ===") +io.print(multiply(6, 7)) + +// Function with boolean return +func isEven(n: int) => bool { + return n % 2 == 0 +} + +io.print("=== Is Even Check ===") +io.print(isEven(4)) +io.print(isEven(7)) + +// Function with float +func average(a: float, b: float) => float { + return (a + b) / 2 +} + +io.print("=== Average ===") +io.print(average(10.5, 20.5)) + +// Function that uses loops +func factorial(n: int) => int { + var result: int = 1 + for (var i: int = 1; i <= n; var i: int = i + 1) { + var result: int = result * i + } + return result +} + +io.print("=== Factorial ===") +io.print(factorial(5)) + +// Function that doesn't return a value +func printNumber(n: int) => any { + io.print(n) +} + +io.print("=== Print via Function ===") +printNumber(42) diff --git a/vendor/grammars/strata-grammar/strata.tmLanguage.json b/vendor/grammars/strata-grammar/strata.tmLanguage.json new file mode 100644 index 0000000000..6c050b6817 --- /dev/null +++ b/vendor/grammars/strata-grammar/strata.tmLanguage.json @@ -0,0 +1,46 @@ +{ + "scopeName": "source.strata", + "name": "Strata", + "patterns": [ + { "include": "#keywords" }, + { "include": "#modules" }, + { "include": "#functions" }, + { "include": "#strings" }, + { "include": "#numbers" }, + { "include": "#comments" } + ], + "repository": { + "keywords": { + "patterns": [ + { "name": "keyword.control.strata", "match": "\\b(func|create|type|set|var|import|from)\\b" } + ] + }, + "modules": { + "patterns": [ + { "name": "support.other.module.strata", "match": "\\b(str\\.io|str\\.math|str\\.util|str\\.time|str\\.lang|str\\.net|str\\.sql|str\\.xml|str\\.rmi|str\\.security|str\\.text)\\b" } + ] + }, + "functions": { + "patterns": [ + { "name": "support.function.strata", "match": "\\b(io\\.print|math\\.sqrt|math\\.pow|math\\.random|util\\.randomInt|time\\.now)\\b" } + ] + }, + "strings": { + "patterns": [ + { "name": "string.quoted.single.strata", "match": "'[^']*'" }, + { "name": "string.quoted.double.strata", "match": "\"[^\"]*\"" } + ] + }, + "numbers": { + "patterns": [ + { "name": "constant.numeric.strata", "match": "\\b\\d+\\b" } + ] + }, + "comments": { + "patterns": [ + { "name": "comment.line.double-slash.strata", "match": "//.*$" }, + { "name": "comment.block.strata", "begin": "/\\*", "end": "\\*/" } + ] + } + } +}