-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This does not yet have full coverage over all of the types in peg.d.ts; I want to see if this approach seems viable to the typescript experts.
- Loading branch information
Showing
10 changed files
with
2,839 additions
and
10,029 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
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,44 @@ | ||
/* | ||
This grammar aims to have one of every Peggy syntax. | ||
It parses the output of a fizz-buzz (https://en.wikipedia.org/wiki/Fizz_buzz) | ||
program (plus a few extensions) for correctness. | ||
*/ | ||
{{ | ||
const NUMS = [3, 5]; | ||
}} | ||
{ | ||
let currentNumber = (options.start == null) ? 1 : options.start|0; | ||
} | ||
|
||
top = c:count* { return c.filter(fb => fb) } | ||
|
||
count | ||
= end_comment "\n" { return } | ||
/ comment "\n" { return } | ||
/ comment? fb:line (comment / end_comment)? "\n" { | ||
currentNumber++; | ||
return fb; | ||
} | ||
|
||
comment "comment" | ||
= _ "/*" (!"*/" .)* "*/" _ | ||
|
||
end_comment | ||
= _ "//" [^\n]+ | ||
|
||
line | ||
= @n:number &{ return (n === currentNumber) && NUMS.every(d => n % d) } | ||
/ fizzbuzz | ||
/ fizz | ||
/ buzz | ||
|
||
fizzbuzz = f:fizz _ b:buzz { return f + b } | ||
fizz = @"fizz"i !{ return currentNumber % 3 } | ||
buzz = @"buzz"i !{ return currentNumber % 5 } | ||
|
||
// Arbitrary requirement needing & | ||
number "number without trailing comment" | ||
= "0x" n:$[0-9a-f]i+ &"\n" { return parseInt(n, 16) } | ||
/ n:$[0-9]+ &"\n" { return parseInt(n, 10) } | ||
|
||
_ = $[ \t]* |
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,16 @@ | ||
"use strict"; | ||
|
||
module.exports = { | ||
"collectCoverage": true, | ||
"coverageReporters": ["lcov"], | ||
"roots": [ | ||
"<rootDir>/test" | ||
], | ||
"testMatch": [ | ||
"**/*.spec.js", | ||
"**/*.test-d.ts" | ||
], | ||
"transform": { | ||
"^.+\\.ts$": "ts-jest", | ||
} | ||
}; |
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
Oops, something went wrong.