Skip to content

Commit d957ac7

Browse files
committed
typings: address #494 - Typescript MatchResult object incomplete
1 parent e1b8225 commit d957ac7

2 files changed

Lines changed: 44 additions & 10 deletions

File tree

packages/ohm-js/index.d.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ export interface Matcher {
165165
* Result of Grammar#match
166166
*/
167167
export interface MatchResult {
168+
matcher: Matcher;
169+
input: string;
170+
168171
/**
169172
* True iff match succeeded
170173
*/
@@ -192,6 +195,19 @@ export interface FailedMatchResult extends MatchResult {
192195
*/
193196
shortMessage: string;
194197

198+
/**
199+
* Returns the position at which the error should be reported. This is used
200+
* to construct `message` and `shortMessage`.
201+
*/
202+
getRightmostFailurePosition(): number;
203+
204+
/**
205+
* Return a string summarizing the expected contents of the input stream
206+
* at the rightmost failure position. This is used to construct `message`
207+
* and `shortMessage`.
208+
*/
209+
getExpectedText(): string;
210+
195211
/**
196212
* If this MatchResult is a failure, returns an Interval indicating
197213
* the position of the rightmost failure.

packages/ohm-js/scripts/data/index.d.ts.template

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ export interface Matcher {
164164
* Result of Grammar#match
165165
*/
166166
export interface MatchResult {
167+
matcher: Matcher;
168+
input: string;
169+
170+
167171
/**
168172
* True iff match succeeded
169173
*/
@@ -180,22 +184,36 @@ export interface SucceededMatchResult extends MatchResult {
180184

181185
export interface FailedMatchResult extends MatchResult {
182186
/**
183-
* If match failed contains an error message indicating where and
184-
* why the match failed. This message is suitable for end users of a
185-
* language (i.e., people who do not have access to the grammar source).
186-
*/
187+
* If match failed contains an error message indicating where and
188+
* why the match failed. This message is suitable for end users of a
189+
* language (i.e., people who do not have access to the grammar source).
190+
*/
187191
message: string;
188192

189193
/**
190-
* If match failed contains an abbreviated version of this.message that
191-
* does not include an excerpt from the invalid input.
192-
*/
194+
* If match failed contains an abbreviated version of this.message that
195+
* does not include an excerpt from the invalid input.
196+
*/
193197
shortMessage: string;
194198

195199
/**
196-
* If this MatchResult is a failure, returns an Interval indicating
197-
* the position of the rightmost failure.
198-
*/
200+
* Returns the position at which the error should be reported. This is used
201+
* to construct `message` and `shortMessage`.
202+
*/
203+
getRightmostFailurePosition(): number;
204+
205+
/**
206+
* Return a string summarizing the expected contents of the input stream
207+
* at the rightmost failure position. This is used to construct `message`
208+
* and `shortMessage`.
209+
*/
210+
getExpectedText(): string;
211+
212+
213+
/**
214+
* If this MatchResult is a failure, returns an Interval indicating
215+
* the position of the rightmost failure.
216+
*/
199217
getInterval(): Interval;
200218
}
201219

0 commit comments

Comments
 (0)