Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e9e5fa2
commit fface03
Showing
10 changed files
with
179 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
program ::= %w* def+ ; | ||
w ::= comment | " " | "\t" | "\n" | "\r\n" ; | ||
comment ::= "#" !"\n"* "\n" ; | ||
|
||
name ::= letter ( letter | digit | "_" )* ; | ||
letter ::= "a"->"z" | "A"->"Z" ; | ||
digit ::= "0"->"9" ; | ||
hex ::= "0"->"9" | "a"->"f" | "A"->"F" ; | ||
|
||
constant ::= %"\"" frag* %"\"" ; | ||
frag ::= escape | byte | !"\""+ ; | ||
escape ::= %"\\" !"" ; | ||
byte ::= %"x" ...(hex hex) ; | ||
|
||
def ::= ...name %(w+ "::=" w*) expr %(w* ";" w*) ; | ||
|
||
expr ::= expr_arg %w* ( ...expr_infix? %w* expr_arg %w* )* ; | ||
expr_arg ::= expr_prefix ( constant | expr_brackets | ...name ) ...expr_suffix? ; | ||
expr_prefix ::= ..."%"? ..."..."? ..."!"? ; | ||
expr_infix ::= "->" | "|" ; | ||
expr_suffix ::= "*" | "?" | "+" ; | ||
expr_brackets ::= %( "(" w* ) expr %( w* ")" ) ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,111 @@ | ||
import { execSync } from "child_process"; | ||
import * as path from "path"; | ||
import { execSync } from "node:child_process"; | ||
import { pathToFileURL } from "node:url"; | ||
import path from "node:path"; | ||
import chalk from "chalk"; | ||
import fs from "node:fs"; | ||
|
||
const cwd = path.dirname(process.argv[1]); | ||
let tests = { | ||
"BNF compilations": ['node ../bin/cli.js ./bnfs/', { cwd }], | ||
"LOLcode": ['node ./lolcode.js', { cwd }], | ||
"Double Parse": ['node double-parse.js', { cwd }], | ||
// "Uniview Parse": ['node ./uv/index.js', { cwd }], | ||
}; | ||
import * as Shared from "./bnfs/shared.js"; | ||
|
||
let failed = false; | ||
const cwd = path.dirname(process.argv[1]); | ||
|
||
for (let key in tests) { | ||
let test = tests[key]; | ||
console.log(key); | ||
|
||
test[1].stdio = [null, null, null]; | ||
|
||
let res; | ||
function CompileBNFs(){ | ||
console.log("Compiling BNFs"); | ||
try { | ||
res = execSync(test[0], test[1]); | ||
console.log(" Passed\n"); | ||
execSync("node ../bin/cli.js ./bnfs/", { cwd }) | ||
} catch (e) { | ||
console.error(" "+ | ||
e.stderr | ||
.toString() | ||
.replace(/\n+/g, " \n") | ||
); | ||
|
||
console.log(' Failed\n'); | ||
failed = true; | ||
console.error(e.stderr); | ||
console.error("Failed to compile BNFs"); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
async function SampleTests() { | ||
const syntaxes = fs.readdirSync(`${cwd}/bnfs`) | ||
.filter(x => x.endsWith(".bnf")) | ||
.map(x => x.slice(0, -4)); | ||
|
||
|
||
console.log("Automated Sample Tests"); | ||
let failure = false; | ||
for (const lang of syntaxes) { | ||
console.log(" ", lang); | ||
const dir = `${cwd}/samples/${lang}`; | ||
if (!fs.existsSync(dir)) continue; | ||
|
||
const files = fs.readdirSync(dir); | ||
if (files.length === 0) continue; | ||
|
||
const syntaxURL = pathToFileURL(`${cwd}/bnfs/${lang}.js`); | ||
const Parser = await import(syntaxURL); | ||
|
||
if (!Parser.Parse_Program) { | ||
continue; | ||
} | ||
|
||
for (const file of files) { | ||
const data = fs.readFileSync(`${dir}/${file}`, "utf8"); | ||
try { | ||
const syntax = Parser.Parse_Program(data, false); | ||
if (syntax instanceof Shared.ParseError) throw syntax; | ||
if (syntax.isPartial) throw new Error("Partial Match"); | ||
|
||
console.log(` ${chalk.green("PASS")} ${file}`); | ||
} catch (e) { | ||
console.log(` ${chalk.red("FAIL")} ${file}`); | ||
failure = true; | ||
} | ||
} | ||
} | ||
|
||
if (failure) process.exit(1); | ||
} | ||
|
||
|
||
process.exit(failed ? 1 : 0); | ||
|
||
|
||
|
||
function ManualTests () { | ||
let tests = { | ||
// "Double Parse": ['node double-parse.js', { cwd }], | ||
// "Uniview Parse": ['node ./uv/index.js', { cwd }], | ||
}; | ||
|
||
let failed = false; | ||
|
||
for (let key in tests) { | ||
let test = tests[key]; | ||
console.log(key); | ||
|
||
test[1].stdio = [null, null, null]; | ||
|
||
let res; | ||
try { | ||
res = execSync(test[0], test[1]); | ||
console.log(" Passed\n"); | ||
} catch (e) { | ||
console.error(" "+ | ||
e.stderr | ||
.toString() | ||
.replace(/\n+/g, " \n") | ||
); | ||
|
||
console.log(' Failed\n'); | ||
failed = true; | ||
} | ||
} | ||
|
||
process.exit(failed ? 1 : 0); | ||
} | ||
|
||
|
||
async function Main() { | ||
CompileBNFs(); | ||
await SampleTests(); | ||
ManualTests(); | ||
} | ||
Main(); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
program ::= %w* def+ ; | ||
w ::= comment | " " | "\t" | "\n" | "\r\n" ; | ||
comment ::= "#" !"\n"* "\n" ; | ||
|
||
name ::= letter ( letter | digit | "_" )* ; | ||
letter ::= "a"->"z" | "A"->"Z" ; | ||
digit ::= "0"->"9" ; | ||
hex ::= "0"->"9" | "a"->"f" | "A"->"F" ; | ||
|
||
constant ::= %"\"" frag* %"\"" ; | ||
frag ::= escape | byte | !"\""+ ; | ||
escape ::= %"\\" !"" ; | ||
byte ::= %"x" ...(hex hex) ; | ||
|
||
def ::= ...name %(w+ "::=" w*) expr %(w* ";" w*) ; | ||
|
||
expr ::= expr_arg %w* ( ...expr_infix? %w* expr_arg %w* )* ; | ||
expr_arg ::= expr_prefix ( constant | expr_brackets | ...name ) ...expr_suffix? ; | ||
expr_prefix ::= ..."%"? ..."..."? ..."!"? ; | ||
expr_infix ::= "->" | "|" ; | ||
expr_suffix ::= "*" | "?" | "+" ; | ||
expr_brackets ::= %( "(" w* ) expr %( w* ")" ) ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
HAI | ||
VISIBLE "U SEE THIS" | ||
BTW VISIBLE "U SEE NOTHING" | ||
OBTW | ||
VISIBLE "U SEE NOTHIN" | ||
VISIBLE "U STIL SEE NOTHIN" | ||
TLDR | ||
VISIBLE "U SEE THIS" | ||
KTHXBYE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
HAI | ||
I HAZ A n | ||
KTHXBYE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
HAI | ||
VISIBLE "HAI WORLD!" | ||
KTHXBYE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
HAI | ||
GIMMEH number | ||
I HAZ A even ITZ MOD OF number AN 2 | ||
O RLY? even | ||
YA RLY | ||
VISIBLE "ITZ EVEN" | ||
NO WAI | ||
VISIBLE "NOZ EVEN" | ||
OIC | ||
KTHXBYE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
HAI | ||
I HAZ A number ITZ 3 | ||
KTHXBYE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
HAI | ||
GIMMEH number | ||
IM IN YR loop WILE WIN | ||
number R SUM OF number AN 1 | ||
VISIBLE number | ||
IM OUTTA YR loop | ||
KTHXBYE |