feat: add managed types, source classes and scoped native calls
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
[syntax.rs](syntax.rs) 覆盖 UTF-8 token 范围、中文/日文名称、数字原文、负号、字符串转义与错误、算术优先级和结合性、成员/调用链、函数与绑定、上下文名称、完整输入、非法/未支持语法以及 CRLF 和 EOF 诊断位置。
|
||||
|
||||
[ast.rs](ast.rs) 覆盖根模式、声明/语句结构、生成 Visitor 与错误退出、Spanned 位置、带 schema 的 JSON 往返及错误输入;同时核对编辑器产物标识,并验证裸名称赋值的独立节点、Unicode 范围、JSON 往返和不支持的赋值目标。
|
||||
[ast.rs](ast.rs) 覆盖根模式、声明/语句结构、生成 Visitor 与错误退出、Spanned 位置、带 schema 的 JSON 往返及错误输入;同时核对编辑器产物标识,并验证裸名称赋值的独立节点、Unicode 范围、JSON 往返和属性赋值目标和不支持的调用结果赋值目标。
|
||||
|
||||
[lexical.rs](lexical.rs) 专门覆盖字符 PEG 迁移后的原文位置换算、首个错误及详细诊断、Unicode 非法转义、未闭合字符串、注释/除法/成员/数字/字符串边界和空输入/尾随注释。
|
||||
|
||||
|
||||
@@ -4,6 +4,35 @@ use frontend::ast::{
|
||||
};
|
||||
use frontend::{EndorReader, ParseMode, Span, parse_ast, parse_source_ast};
|
||||
|
||||
#[test]
|
||||
fn function_bodies_accept_method_statements_and_optional_trailing_return() {
|
||||
let root = parse_ast(
|
||||
"function click(): Unit { title.setText(\"changed\") card.setColor(\"#FFEEDD\") }",
|
||||
ParseMode::Module,
|
||||
)
|
||||
.unwrap();
|
||||
let AstRoot::Module(program) = root else {
|
||||
panic!("expected module")
|
||||
};
|
||||
let function = program.functions().next().unwrap();
|
||||
assert_eq!(function.body.statements.len(), 2);
|
||||
assert!(
|
||||
function
|
||||
.body
|
||||
.statements
|
||||
.iter()
|
||||
.all(|s| matches!(s.kind, StmtKind::Expression(_)))
|
||||
);
|
||||
assert!(parse_ast("function empty(): Unit {}", ParseMode::Module).is_ok());
|
||||
assert!(
|
||||
parse_ast(
|
||||
"function invalid(): Unit { return value other() }",
|
||||
ParseMode::Module
|
||||
)
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_modes_produce_distinct_roots_and_preserve_source_diagnostics() {
|
||||
let source = "function echo(value: String): String { let copy = value return copy }";
|
||||
@@ -198,5 +227,13 @@ fn bare_assignment_has_its_own_ast_and_unicode_source_ranges() {
|
||||
let json = document.to_json().unwrap();
|
||||
assert_eq!(AstDocument::from_json(&json).unwrap(), document);
|
||||
assert!(parse_ast("value = 1 = 2", ParseMode::Interactive).is_err());
|
||||
assert!(parse_ast("object.field = 1", ParseMode::Interactive).is_err());
|
||||
let member = parse_ast("object.field = 1", ParseMode::Interactive).unwrap();
|
||||
let AstRoot::Interactive(member) = member else {
|
||||
panic!("interactive")
|
||||
};
|
||||
assert!(matches!(
|
||||
&member.statements[0].kind,
|
||||
StmtKind::MemberAssignment(_)
|
||||
));
|
||||
assert!(parse_ast("object() = 1", ParseMode::Interactive).is_err());
|
||||
}
|
||||
|
||||
@@ -4,7 +4,9 @@ use frontend::ast::{
|
||||
use frontend::{DiagnosticKind, Span, TokenKind, lex, parse, parse_expression};
|
||||
|
||||
fn function(program: &Program, index: usize) -> &Function {
|
||||
let DeclKind::Function(function) = &program.declarations[index].kind;
|
||||
let DeclKind::Function(function) = &program.declarations[index].kind else {
|
||||
panic!("expected function")
|
||||
};
|
||||
function
|
||||
}
|
||||
|
||||
@@ -258,14 +260,11 @@ fn parser_requires_complete_input_and_rejects_unimplemented_or_malformed_syntax(
|
||||
"// empty",
|
||||
"let x = 1",
|
||||
"use atelier:shop.data",
|
||||
"class Product {}",
|
||||
"agent Worker {}",
|
||||
"function f() { return 1 }",
|
||||
"function f(x): Number { return x }",
|
||||
"function f(x: Number,): Number { return x }",
|
||||
"function f(): Number {}",
|
||||
"function f(): Number { return 1 let x = 2 }",
|
||||
"function f(): Number { let x = 1 }",
|
||||
"function f(): Number { return 1 } extra",
|
||||
"function f(): Number { function g(): Number { return 1 } return 2 }",
|
||||
] {
|
||||
|
||||
Reference in New Issue
Block a user