Skip to content

Commit

Permalink
feat(parsers/any): add any parser
Browse files Browse the repository at this point in the history
  • Loading branch information
norskeld committed Jul 4, 2022
1 parent 00166ae commit bfb9620
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/parsers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './parsers/any'
export * from './parsers/defer'
export * from './parsers/eof'
export * from './parsers/eol'
Expand Down
24 changes: 24 additions & 0 deletions src/parsers/any.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { type Parser } from '../state'

export function any(): Parser<string> {
return {
parse(input, pos) {
if (input.length === pos) {
return {
isOk: false,
pos,
expected: 'reached the end of input'
}
}

const nextPos = pos + 1
const value = input.substring(pos, nextPos)

return {
isOk: true,
pos: nextPos,
value
}
}
}
}

0 comments on commit bfb9620

Please sign in to comment.