HydraScript: From College Project to Static-Typed JSON Parsing CGI Tool
A C# developer created HydraScript, a programming language blending JavaScript syntax with static typing. The project evolved from a student thesis into an open-source tool supporting CGI scripting for deploying web services in Docker.
From Student Project to Open-Source Powerhouse
HydraScript started as a thesis titled "Extended JavaScript Subset" at Bauman Moscow State Technical University's IU-9 department. Over four years of part-time development, it grew into a full-featured open-source project with GitHub Actions CI/CD, semantic versioning, and automated releases. Interpreter binaries are built for Windows (x64), macOS (arm64), and Linux (x64) using Native AOT, eliminating runtime dependencies.
Core project goals:
- Partial JavaScript implementation with objects and structural static typing—no
constructor,class, orinterfacekeywords needed. - Public reverse-engineering of modern static analysis techniques.
- Demystifying compiler tech through open-source code.
- Collecting clear implementations of standard compiler challenges.
Static Analysis: The Killer Feature
HydraScript's type system catches issues at compile time that other languages only spot at runtime.
Catching Uninitialized Variable Access
The interpreter tracks initialization order to prevent runtime crashes. Here's problematic TypeScript/JavaScript code:
let x = f()
function f() {
console.log(x) // Error: x referenced before assignment
return 5
}
HydraScript flags this at compile time.
Smart Default Values
Unlike C#, where uninitialized locals cause compile errors, HydraScript auto-assigns defaults based on inferred types:
let x: number
>>> x // 0
let xArr: number[]
>>> xArr // []
let s: string
>>> ~s // 0 (string length)
Separate Namepaces for Symbols
The language uses three symbol types: VariableSymbol, TypeSymbol, and FunctionSymbol. Names only need to be unique within their type, enabling flexible reuse:
type x = number
let x:x
function x(x:x) {
>>>x
x = x + 1
}
x(x)
CGI Support for Web Development
To make HydraScript practical for backend work, it now supports CGI scripting. This required:
- String manipulation API
- Stdout output
- Environment variable reading
- Shebang comment support
Docker Deployment Setup
Docker image config based on Apache httpd with the HydraScript interpreter:
FROM mcr.microsoft.com/dotnet/sdk:10.0-alpine as sdk-build
RUN dotnet tool update -g hydrascript
ENV PATH="/root/.dotnet/tools:${PATH}"
FROM httpd:2.4-alpine
COPY --from=sdk-build /root/.dotnet/tools/ /usr/bin
RUN apk add dotnet10-runtime
Sample CGI Script: Parsing Query Strings to JSON
This script turns URL params into structured JSON, showcasing real-world use:
#!/usr/bin/hydrascript
type QueryStringParseResultItem = {
name: string;
value: string;
}
type QueryStringParseResult = {
result: QueryStringParseResultItem[];
}
type QueryStringParser = {
input: string;
}
function parse(parser: QueryStringParser): QueryStringParseResult {
const qsLen = ~parser.input
let i = 0
let items: QueryStringParseResultItem[]
let currentName: string, currentValue: string
let isName = true
while (i < qsLen) {
const currentChar = parser.input[i]
if (currentChar == "&" || i == qsLen - 1) {
let addittion = i == qsLen - 1 && currentChar != "&" ? currentChar : ""
items = items ++ [{name: currentName; value: currentValue + addittion;}]
currentName = ""
currentValue = ""
isName = true
} else if (currentChar == "=") {
isName = false
} else {
if (isName) {
currentName = currentName + currentChar
} else {
currentValue = currentValue + currentChar
}
}
i = i + 1
}
return {
result: items;
}
}
let parser: QueryStringParser = {
input: $QUERY_STRING;
}
>>> "Content-Type: application/json\n\n"
>>> parser.parse()
For a=1&b=bla&c=false, it outputs:
{
"result": [
{"name": "a", "value": "1"},
{"name": "b", "value": "bla"},
{"name": "c", "value": "false"}
]
}
Key Takeaways
• HydraScript blends JavaScript syntax with static typing—no classes or constructors required.
• Its static analysis prevents common bugs like uninitialized variable access.
• CGI scripting enables web development with easy Docker deployment.
• Fully open-source with CI/CD, semantic versioning, and cross-platform builds.
— Editorial Team
No comments yet.