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

Add newline support by using a regex to parse blockText #22702

Merged
merged 6 commits into from May 30, 2018

Conversation

balderdash
Copy link
Contributor

No description provided.

@balderdash balderdash requested a review from joshlory May 25, 2018 22:50
@balderdash balderdash changed the base branch from assignment-block to staging May 29, 2018 21:52
* either a real named input like '{VALUE}', a newline, or if it matched a
* trailing label, nothing.
*/
const LABELED_INPUTS_REGEX = /.*?({[^}]*}|\n|$)/gm;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the .*? non-greedy match needed at the beginning?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That matches the label for the input. If it's greedy, it will just consume everything between the beginning of the string and the last input.

It might be clearer to use [^{}]* to match the label, I could go either way.

const inputs = tokens.map(token => {
const parts = token.match(LABELED_INPUT_PARTS_REGEX);
const label = parts[1];
const inputName = parts[3];
Copy link
Contributor

Choose a reason for hiding this comment

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

Not at all blocking, but this makes me wish we had the Babel plugin for named capture groups.

*/
const LABELED_INPUT_PARTS_REGEX = /(.*?)({([^}]*)}|\n|$)/m;

const findInputConfig = (args, inputName) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe clearer as findAndRemoveInputConfig? Not clear initially that this method mutates the args array.

Please add a JSDoc.

@balderdash balderdash merged commit 509b6a5 into staging May 30, 2018
@balderdash balderdash deleted the regex-block-text branch May 31, 2018 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants