Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

PCS V4 语法与消歧

用 plugin、line、note、noise 或 block 声明类型。类型内放字段和方法,方法内可以使用条件分支、循环和返回语句。

plugin Counter {
    int count = 0;
    void OnStart(RunEvent e) {
        foreach (n in Main.GetNotes()) {
            count = count + 1;
        }
    }
}
写法规则
foreach (n in xs)等价于 foreach (var n in xs)。需要显式元素类型时写 foreach (Note n in xs)。
foreach (int in in xs)编译错误。小写独立单词 in 是保留关键字;index 可以作名称。
bool IsPositive(int x) => x > 0;表达式方法将表达式作为返回值,末尾有分号。
a ?? b仅当左值为空时才求右侧。零、空字符串和 false 都是有效值。
#request Permission.File位于文件头,独占一行,无分号。具体授权范围见谱面文件权限。

当条件分支嵌套时,else 就近绑定。需要明确外层分支时使用花括号。区间比较写为 lo < x && x < hi。字符串和注释中的 #request 不声明权限。

需要在编译时裁掉整段源码、给多个脚本排序或显式委托下一处理者时,见条件编译、加载顺序与覆写。