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

Initial MessageFormat 2 #2272

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft

Initial MessageFormat 2 #2272

wants to merge 21 commits into from

Conversation

zbraniecki
Copy link
Member

This is an initial draft branch for MessageFormat component based on MF2.0 spec.

@jira-pull-request-webhook
Copy link

Notice: the branch changed across the force-push!

  • experimental/message/src/lib.rs is different

View Diff Across Force-Push

~ Your Friendly Jira-GitHub PR Checker Bot

Copy link

@eemeli eemeli left a comment

Choose a reason for hiding this comment

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

Didn't try to run the code, but noticed a few mismatches with the spec. If intending to fix them later, might be good to add comments about that to the code?


#[inline]
fn skip_ws(&mut self) {
while get_current_byte!(self) == Some(&b' ') {
Copy link

Choose a reason for hiding this comment

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

This should also account for the other valid whitespace chars:

WhiteSpace ::= #x9 | #xD | #xA | #x20

pub fn parse(mut self) -> ParserResult<ast::Message<S>> {
let mut declarations = SmallVec::new();

loop {
Copy link

Choose a reason for hiding this comment

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

It would probably be easier to skip whitespace before rather than after. Technically, I'm pretty sure that leading whitespace even at the very start is valid.

}
}

fn parse_declaration(&mut self) -> ParserResult<ast::Declaration<S>> {
Copy link

Choose a reason for hiding this comment

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

This should throw if a pattern or a select has already been parsed.

fn parse_declaration(&mut self) -> ParserResult<ast::Declaration<S>> {
assert_eq!(self.next(), Some(&b'e'));
assert_eq!(self.next(), Some(&b't'));
self.skip_ws();
Copy link

Choose a reason for hiding this comment

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

Whitespace should be mandatory here, so that let$foo is not allowed.

assert_eq!(self.next(), Some(&b'n'));
let mut key = SmallVec::new();

self.skip_ws();
Copy link

Choose a reason for hiding this comment

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

Whitespace should be mandatory here, so that whenfoo is not allowed.

self.skip_ws();

if self.next_if(b'*') {
key.push(ast::VariantKey::Asterisk);
Copy link

Choose a reason for hiding this comment

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

Whitespace should be mandatory here, so that when *foo is not allowed.

Also, it looks like parsing for when foo and when (foo) is missing?

Comment on lines +200 to +201
let options = SmallVec::new();
ast::Placeholder::Markup { name, options }
Copy link

Choose a reason for hiding this comment

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

As I've understood it, according to our blackboxing plan a MarkupStart with options should not throw?

fn parse_name(&mut self) -> ParserResult<S> {
let start = self.ptr;
while let Some(b) = get_current_byte!(self) {
if b.is_ascii_alphabetic() {
Copy link

Choose a reason for hiding this comment

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

}
}

fn parse_literal(&mut self) -> ParserResult<ast::Literal<S>> {
Copy link

Choose a reason for hiding this comment

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

This doesn't handle escapes for literals.

let mut start = self.ptr;
let mut body = SmallVec::new();
while let Some(b) = self.next() {
match b {
Copy link

Choose a reason for hiding this comment

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

This doesn't handle escapes in Text correctly.

@CLAassistant
Copy link

CLAassistant commented Sep 1, 2022

CLA assistant check
All committers have signed the CLA.

@waywardmonkeys
Copy link
Contributor

Is this something that someone else could (or should) take on and move forward?

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

4 participants