Skip to content

Instantly share code, notes, and snippets.

@kirjavascript
Created August 10, 2020 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirjavascript/ac3ac85be6958640a58fb7925a500f53 to your computer and use it in GitHub Desktop.
Save kirjavascript/ac3ac85be6958640a58fb7925a500f53 to your computer and use it in GitHub Desktop.
const whitespaceSymbol = Symbol('whitespace');
const whitespace = rawWhitespace.map(() => whitespaceSymbol);
const param = (param) => composeParsers([param, whitespace]);
// const
const sexpr = (fn) => {
const [head, ...tail] = fn();
const params = sequenceOf([head, ...tail.map(param)]);
return (
composeParsers([
takeLeft(params) (sequenceOf([optionalWhitespace, char(')')])),
sequenceOf([char('('), optionalWhitespace]),
])
);
};
const comment = sequenceOf([
char(';'),
regex(/^.*$/m)
]).map((comment) => ({ type: 'comment', comment: comment.join('') }));
const info = sexpr(() => [ str('info') ]).map(() => ({ type: 'info' }));
const number = choice([
sequenceOf([
char('#'),
digits,
]).map(([, digits]) => +digits),
sequenceOf([
str('#$'),
regex(/^[A-F0-9]+/i),
]).map(([, hex]) => +`0x${hex}`),
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment