Skip to content

Commit

Permalink
Test typescript types using tsd.
Browse files Browse the repository at this point in the history
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
hildjj committed May 27, 2021
1 parent d611345 commit 9d7681b
Show file tree
Hide file tree
Showing 10 changed files with 2,839 additions and 10,029 deletions.
2 changes: 1 addition & 1 deletion docs/js/benchmark-bundle.min.js

Large diffs are not rendered by default.

42 changes: 2 additions & 40 deletions docs/js/test-bundle.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/vendor/peggy/peggy.min.js

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions examples/fizzbuzz.peggy
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]*
16 changes: 16 additions & 0 deletions jest.config.js
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",
}
};
4 changes: 2 additions & 2 deletions lib/peg.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ declare namespace ast {
ignoreCase: boolean;
}

/** Matches any UTF-16 character in the input, but doesn't match the empty string. */
/** Matches any UTF-16 code unit in the input, but doesn't match the empty string. */
interface Any extends Node<"any"> {}
}

Expand Down Expand Up @@ -342,7 +342,7 @@ export namespace parser {
| OtherExpectation;

/** Thrown if the grammar contains a syntax error. */
class SyntaxError implements Error {
class SyntaxError extends Error {
/** Location where error was originated. */
location: LocationRange;
/**
Expand Down
Loading

0 comments on commit 9d7681b

Please sign in to comment.