Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scheme: Improvements #2263

Merged
merged 6 commits into from Apr 7, 2020

Conversation

RunDevelopment
Copy link
Member

This makes some improvements to the Scheme language in an effort to fix the remaining TODOs in #1451.

@RunDevelopment RunDevelopment added this to the 1.20.0 milestone Mar 26, 2020
@mAAdhaTTah mAAdhaTTah removed this from the 1.20.0 milestone Apr 6, 2020
// <b.o.x. number> := <b.o.x. prefix>[+-]?<b.o.x. complex>
//
// <number> := <dec number>|<b.o.x. number>
pattern: /([\s()])(?:(?:#d(?:#[ei])?|#[ei](?:#d)?)?[+-]?(?:(?:\d*\.?\d+(?:[eE][+-]?\d+)?|\d+\/\d+)(?:[+-](?:\d*\.?\d+(?:[eE][+-]?\d+)?|\d+\/\d+)i)?|(?:\d*\.?\d+(?:[eE][+-]?\d+)?|\d+\/\d+)i)|(?:#[box](?:#[ei])?|#[ei](?:#[box])?)[+-]?(?:[\da-fA-F]+(?:\/[\da-fA-F]+)?(?:[+-][\da-fA-F]+(?:\/[\da-fA-F]+)?i)?|[\da-fA-F]+(?:\/[\da-fA-F]+)?i))(?=[\s()]|$)/,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love this documentation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I don't.
It explains the pattern by showing its simpler components, yes, but how do you know that the pattern is actually what's written there? I actually manually "generated" the pattern by substituting the rules myself, so I can tell you it's a pain... especially if you change something...

I'd rather have the pattern generated from a BNF.
We could implement a BNF-like syntax with #2190 and a syntax like this:

bnf({
	// Decimal numbers
	'dec real'    : /\d*\.?\d+(?:[eE][+-]?\d+)?|\d+\/\d+/.source,
	'dec complex' : /<dec real>(?:[+-]<dec real>i)?|<dec real>i/.source,
	'dec prefix'  : /(?:#d(?:#[ei])?|#[ei](?:#d)?)?/.source,
	'dec number'  : /<dec prefix>[+-]?<complex>/.source,
	
	// Binary, octal, and hexadecimal numbers
	'box real'    : /[\da-fA-F]+(?:\/[\da-fA-F]+)?/.source,
	'box complex' : /<box real>(?:[+-]<box real>i)?|<box real>i/.source,
	'box prefix'  : /#[box](?:#[ei])?|#[ei](?:#[box])?/.source,
	'box number'  : /<box prefix>[+-]?<box complex>/.source,

	'out'         : /<dec number>|<box number>/.source,
}); // returns a RegExp

But this has a whole range of problems associated with it one of them being that minification basically impossible.

@RunDevelopment RunDevelopment merged commit 9a49f78 into PrismJS:master Apr 7, 2020
@RunDevelopment RunDevelopment deleted the scheme-improvements-3 branch April 7, 2020 18:32
quentinvernot pushed a commit to TankerHQ/prismjs that referenced this pull request Sep 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants