feat: support bare name assignments in interactive and function scopes
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 往返及错误输入;同时核对编辑器产物标识。
|
||||
[ast.rs](ast.rs) 覆盖根模式、声明/语句结构、生成 Visitor 与错误退出、Spanned 位置、带 schema 的 JSON 往返及错误输入;同时核对编辑器产物标识,并验证裸名称赋值的独立节点、Unicode 范围、JSON 往返和不支持的赋值目标。
|
||||
|
||||
[lexical.rs](lexical.rs) 专门覆盖字符 PEG 迁移后的原文位置换算、首个错误及详细诊断、Unicode 非法转义、未闭合字符串、注释/除法/成员/数字/字符串边界和空输入/尾随注释。
|
||||
|
||||
|
||||
@@ -179,3 +179,24 @@ fn json_interfaces_reject_unknown_fields_schema_changes_and_invalid_ranges() {
|
||||
Err(AstError::InvalidSpan(_))
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bare_assignment_has_its_own_ast_and_unicode_source_ranges() {
|
||||
let source = "标题 = ui.text(\"你好\")";
|
||||
let root = parse_ast(source, ParseMode::Interactive).unwrap();
|
||||
let AstRoot::Interactive(input) = &root else {
|
||||
panic!("interactive input")
|
||||
};
|
||||
let StmtKind::Assignment(assignment) = &input.statements[0].kind else {
|
||||
panic!("assignment")
|
||||
};
|
||||
assert_eq!(assignment.name.text, "标题");
|
||||
assert_eq!(assignment.name.source_text(source), Some("标题"));
|
||||
assert_eq!(assignment.source_text(source), Some(source));
|
||||
let document = AstDocument::new(root).unwrap();
|
||||
document.validate_source(source).unwrap();
|
||||
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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user