Skip to content

Commit

Permalink
feat: support #comments
Browse files Browse the repository at this point in the history
fixes #305
  • Loading branch information
kantord authored and jalbertsr committed Mar 8, 2019
1 parent dabf69f commit 3ff6a89
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/__tests__/whitespace.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,15 @@ const examples = [
`
]

const extendedExamples = [
...examples,
...examples.map((example: string): string => example.replace('//', '#'))
]

describe('whitespace tests', () => {
examples.forEach((example: string): void =>
extendedExamples.forEach((example: string) => {
it(`parses '${example.slice(0, 25)}'`, () => {
parse(example)
})
)
})
})
5 changes: 4 additions & 1 deletion src/parsers/crap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import P from 'parsimmon'

const NotNewline = P.regexp(/[^\n]*/)
const Comment = NotNewline.wrap(P.string('//'), P.string('\n'))
const Comment = NotNewline.wrap(
P.alt(P.string('//'), P.string('#')),
P.string('\n')
)
const Whitespace = P.regexp(/[ \n]*/)

export default Comment.sepBy(Whitespace).trim(Whitespace)

0 comments on commit 3ff6a89

Please sign in to comment.