-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcheck-abnf.ps1
61 lines (46 loc) · 1.95 KB
/
check-abnf.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<#
.SYNOPSIS
Unit test for OData ABNF grammar
.DESCRIPTION
This script compiles the three OData ABNF files into a parser using https://github.com/ldthomas/apg-js
It then executes all tests in the three testcase files using the generated parser
Prerequisites
- PowerShell (https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell)
- Node.js (https://nodejs.org/)
In the root folder of this project run
- npm install
#>
param (
[switch]$watch = $false
)
$Grammar = "lib/grammar.js"
function CompileAndCheck {
if (!(Test-Path $Grammar) -or ($Null -eq (Get-Content $Grammar)) -or
(get-item $Grammar).LastWriteTime -lt (get-item "abnf/odata-abnf-construction-rules.txt").LastWriteTime -or
(get-item $Grammar).LastWriteTime -lt (get-item "abnf/odata-aggregation-abnf.txt").LastWriteTime -or
(get-item $Grammar).LastWriteTime -lt (get-item "abnf/odata-temporal-abnf.txt").LastWriteTime ) {
node node_modules/apg-js/bin/apg.sh -i "abnf/odata-abnf-construction-rules.txt,abnf/odata-aggregation-abnf.txt,abnf/odata-temporal-abnf.txt" -o lib/grammar.js | Select-String -Pattern "^line no:", "^ORIGINAL GRAMMAR", "^Annotated Input Grammar", "^$" -NotMatch
if ($Null -eq (Get-Content $Grammar) ) { return }
Write-Output " "
}
# run tests
node lib/checkAbnf.js
}
CompileAndCheck
if ($watch) {
$PathToMonitor = Resolve-Path "$pwd"
$WaitMessage = "Waiting for changes (press ^C to stop)..."
$FileSystemWatcher = New-Object System.IO.FileSystemWatcher
$FileSystemWatcher.Path = $PathToMonitor
$FileSystemWatcher.IncludeSubdirectories = $true
Write-Output $WaitMessage
while ($true) {
$Change = $FileSystemWatcher.WaitForChanged('All', 1000)
if ($Change.TimedOut -eq $false) {
Write-Output " "
CompileAndCheck
Write-Output $WaitMessage
}
}
}
exit $LASTEXITCODE