Created
August 10, 2020 18:42
-
-
Save kirjavascript/ac3ac85be6958640a58fb7925a500f53 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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