Skip to content

Commit

Permalink
refactor: implicitly return Parser instances (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bikossor authored Aug 7, 2022
1 parent 801575e commit 411f97c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
5 changes: 2 additions & 3 deletions src/combinators/optional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { updateParserResult } from "../ParserState";
* @returns
* @see https://rudus.pages.dev/docs/api/combinators/optional
*/
export const optional = (parser: Parser): Parser => {
return new Parser(currentState => {
export const optional = (parser: Parser): Parser =>
new Parser(currentState => {
// Try to transform the current state with the given parser.
const nextState = parser.transformState(currentState);

Expand All @@ -18,4 +18,3 @@ export const optional = (parser: Parser): Parser => {
// If the given parser can match return the transformed state.
return nextState;
});
};
5 changes: 2 additions & 3 deletions src/parsers/failure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import { updateParserError } from "../ParserState";
* @param errorMessage
* @returns
*/
export const failure = (errorMessage: string) => {
return new Parser(state => {
export const failure = (errorMessage: string) =>
new Parser(state => {
if (state.isError) return state;
return updateParserError(state, errorMessage);
});
};
5 changes: 2 additions & 3 deletions src/parsers/lazy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { Parser } from "../Parser";
* @returns
* @see https://rudus.pages.dev/docs/api/parsers/lazy
*/
export const lazy = (parserThunk: () => Parser): Parser => {
return new Parser(state => {
export const lazy = (parserThunk: () => Parser): Parser =>
new Parser(state => {
return parserThunk().transformState(state);
});
};

0 comments on commit 411f97c

Please sign in to comment.