Add server-side builtins, import system, and http_serve for Neuron Code rewrite
- Import resolution: resolve_imports() pre-processes import statements by reading and concatenating referenced .el files before compilation - http_serve builtin: tiny_http-based server on configurable port; POST /axon/message stores request in __request__ state, invokes handle_request entry point via sub-interpreter, reads __response__ state for reply - New builtins: blake3_hash, uuid_new, fs_list_recursive, fs_mkdir, fs_exists, path_join, path_parent, str_trim, str_contains, str_replace, str_starts_with, str_ends_with, str_last_index_of, json_get, json_array_push, json_array_len, now_millis, http_get, http_post, int_to_str - Catch-all arms in el-types and el-compiler for new AST variants (Import, ProtocolDef, ImplDef, Closure, Try, MapLiteral, TypeExpr::Result, TypeExpr::Map) - Parser: decorators field on FnDef, import/protocol/impl parsing
This commit is contained in:
@@ -191,12 +191,11 @@ impl<'src> Lexer<'src> {
|
||||
if self.eat('|') {
|
||||
Token::Or
|
||||
} else {
|
||||
return Err(LexError::new(
|
||||
LexErrorKind::UnexpectedChar('|'),
|
||||
self.span_from(start),
|
||||
));
|
||||
Token::Pipe
|
||||
}
|
||||
}
|
||||
'@' => Token::At,
|
||||
'?' => Token::QuestionMark,
|
||||
':' => {
|
||||
if self.eat(':') {
|
||||
Token::ColonColon
|
||||
@@ -351,6 +350,11 @@ fn keyword_or_ident(s: String) -> Token {
|
||||
"seed" => Token::Seed,
|
||||
"assert" => Token::Assert,
|
||||
"target" => Token::Target,
|
||||
"protocol" => Token::Protocol,
|
||||
"impl" => Token::Impl,
|
||||
"import" => Token::Import,
|
||||
"from" => Token::From,
|
||||
"as" => Token::As,
|
||||
"true" => Token::BoolLiteral(true),
|
||||
"false" => Token::BoolLiteral(false),
|
||||
_ => Token::Ident(s),
|
||||
@@ -486,9 +490,10 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_unexpected_char_error() {
|
||||
let result = tokenize("@");
|
||||
assert!(result.is_err());
|
||||
fn test_at_token() {
|
||||
let tokens = toks("@public");
|
||||
assert_eq!(tokens[0], Token::At);
|
||||
assert_eq!(tokens[1], Token::Ident("public".into()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -525,6 +530,31 @@ let msg: String = greet("Will")
|
||||
assert_eq!(tokens[2], Token::Ident("Active".into()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_new_keywords() {
|
||||
let tokens = toks("protocol impl import from as");
|
||||
assert_eq!(tokens[0], Token::Protocol);
|
||||
assert_eq!(tokens[1], Token::Impl);
|
||||
assert_eq!(tokens[2], Token::Import);
|
||||
assert_eq!(tokens[3], Token::From);
|
||||
assert_eq!(tokens[4], Token::As);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pipe_token() {
|
||||
let tokens = toks("|x: Int|");
|
||||
assert_eq!(tokens[0], Token::Pipe);
|
||||
assert_eq!(tokens[1], Token::Ident("x".into()));
|
||||
assert_eq!(tokens[4], Token::Pipe);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_question_mark_token() {
|
||||
let tokens = toks("x?");
|
||||
assert_eq!(tokens[0], Token::Ident("x".into()));
|
||||
assert_eq!(tokens[1], Token::QuestionMark);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ident_with_underscore() {
|
||||
let tokens = toks("my_var _private __double");
|
||||
|
||||
@@ -81,6 +81,16 @@ pub enum Token {
|
||||
Assert,
|
||||
/// `target` — test target annotation (`target: e2e`)
|
||||
Target,
|
||||
/// `protocol` — protocol definition
|
||||
Protocol,
|
||||
/// `impl` — protocol implementation block
|
||||
Impl,
|
||||
/// `import` — import statement
|
||||
Import,
|
||||
/// `from` — `from package import { ... }`
|
||||
From,
|
||||
/// `as` — alias in import (`import X as Y`)
|
||||
As,
|
||||
/// `true` / `false`
|
||||
BoolLiteral(bool),
|
||||
|
||||
@@ -151,6 +161,14 @@ pub enum Token {
|
||||
/// `;`
|
||||
Semicolon,
|
||||
|
||||
// ── New single-char tokens ────────────────────────────────────────────────
|
||||
/// `@` — decorator prefix
|
||||
At,
|
||||
/// `|` — closure param delimiter (single pipe, not `||`)
|
||||
Pipe,
|
||||
/// `?` — used both for Optional types and the Try operator
|
||||
QuestionMark,
|
||||
|
||||
// ── Special ───────────────────────────────────────────────────────────────
|
||||
Eof,
|
||||
}
|
||||
@@ -175,6 +193,14 @@ impl std::fmt::Display for Token {
|
||||
Token::Seed => write!(f, "seed"),
|
||||
Token::Assert => write!(f, "assert"),
|
||||
Token::Target => write!(f, "target"),
|
||||
Token::Protocol => write!(f, "protocol"),
|
||||
Token::Impl => write!(f, "impl"),
|
||||
Token::Import => write!(f, "import"),
|
||||
Token::From => write!(f, "from"),
|
||||
Token::As => write!(f, "as"),
|
||||
Token::At => write!(f, "@"),
|
||||
Token::Pipe => write!(f, "|"),
|
||||
Token::QuestionMark => write!(f, "?"),
|
||||
Token::BoolLiteral(b) => write!(f, "{b}"),
|
||||
Token::IntLiteral(n) => write!(f, "{n}"),
|
||||
Token::FloatLiteral(n) => write!(f, "{n}"),
|
||||
|
||||
Reference in New Issue
Block a user