首次提交: OnebotCatalog 项目代码与文档(含 NX 按需生成服务二期、后台、一键启动)
This commit is contained in:
20
sample-data/tools/parse-check.ps1
Normal file
20
sample-data/tools/parse-check.ps1
Normal file
@@ -0,0 +1,20 @@
|
||||
# 用真实解析器定位 .ps1 语法错误, 并打印出错行上下文
|
||||
param([string]$File = (Join-Path $PSScriptRoot 'gen-step.ps1'))
|
||||
$tokens = $null
|
||||
$errors = $null
|
||||
[System.Management.Automation.Language.Parser]::ParseFile($File, [ref]$tokens, [ref]$errors) | Out-Null
|
||||
$lines = [System.IO.File]::ReadAllLines($File)
|
||||
Write-Output ("总行数: " + $lines.Count)
|
||||
if ($errors.Count -eq 0) {
|
||||
Write-Output "语法 OK"
|
||||
} else {
|
||||
foreach ($e in $errors) {
|
||||
$ln = $e.Extent.StartLineNumber
|
||||
Write-Output ("--- 错误 行{0} 列{1}: {2}" -f $ln, $e.Extent.StartColumnNumber, $e.Message)
|
||||
for ($i = $ln - 3; $i -le ($ln + 1); $i++) {
|
||||
if ($i -ge 1 -and $i -le $lines.Count) {
|
||||
Write-Output ("{0,4} | {1}" -f $i, $lines[$i - 1])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user