speechmarkdown / speechmarkdown-js

Speech Markdown grammar, parser, and formatters for use with JavaScript.
MIT License
76 stars 16 forks source link

Grammar - date not parsing slashes correctly #4

Closed rmtuckerphx closed 5 years ago

rmtuckerphx commented 5 years ago

Various tests in date-standard.spec.ts are commented out. Need to fix grammar to accept values with slashes. See SpeechMarkdownGrammar.ts

Fleker commented 5 years ago

I see this is using myna for parsing. I'm not too familiar, but I did begin work on this.

Right now here's my status:

I've replaced

this.textModifier = m.seq('(', this.plainText, ')', this.modifier).ast;

with

this.textModifier = m.seq('(', m.choice(this.plainText, m.hyphen).oneOrMore, ')', this.modifier).ast;

This gets me a lot closer, for (10-19-2016)[date:"mdy"] from 10<emphasis level="reduced">19</emphasis>2016date:"mdy" to <say-as interpret-as="date" format="mdy">2016</say-as>

I'll keep at it, although I am a bit puzzled right now and may require some more reading.

rmtuckerphx commented 5 years ago

Nick, thanks for jumping in and helping on this! I really appreciate it.

Fleker commented 5 years ago

I'm at the point where I have date passing, but now emphasis-short-reduced is failing. I'm growing frustrated with the Myna library because it seems to have some illogical behavior where modifying unrelated variables in the SpeechGrammar get tests to pass/fail.

If the Grammar looks like this:

// Plain text
    this.specialCharSet = '[]()*~`@#\\_!+';
    this.specialCharSetHyphen = '[]()*~`@#\\_!+-';
    this.ws = m.char(' \t').oneOrMore;
    this.optWs = this.ws.opt;
    this.wsOrNewLine = this.ws.or(m.newLine);
    this.nonSpecialChar = m.notChar(this.specialCharSet).unless(m.newLine);
    this.nonSpecialCharHyphen = m.notChar(this.specialCharSetHyphen).unless(m.newLine);
    // this.specialChar = m.char(this.specialCharSet).ast;
    this.quoteChar = m.notChar('"');
    this.plainText = m.choice(m.digits, m.letters, this.ws, this.nonSpecialChar).oneOrMore.ast;
    this.plainTextHyphen = m.choice(m.digits, m.letters, this.ws).oneOrMore.ast;

    // ...

    // Emphasis
    this.shortEmphasisModerate = m.seq('+', this.plainText , '+').ast;
    this.shortEmphasisStrong = m.seq('++', this.plainText , '++').ast;
    this.shortEmphasisNone = m.seq('~', this.plainText , '~').ast;
    this.shortEmphasisReduced = m.seq('-', this.plainTextHyphen , '-').ast;
    this.emphasis = m.choice(this.shortEmphasisModerate, this.shortEmphasisStrong, this.shortEmphasisNone, this.shortEmphasisReduced);

the test fails.

If I just add a hyphen to this.specialCharSet, which is not even being used in the reduced emphasis container:

// Plain text
    this.specialCharSet = '[]()*~`@#\\_!+-';
    this.specialCharSetHyphen = '[]()*~`@#\\_!+-';
    this.ws = m.char(' \t').oneOrMore;
    this.optWs = this.ws.opt;
    this.wsOrNewLine = this.ws.or(m.newLine);
    this.nonSpecialChar = m.notChar(this.specialCharSet).unless(m.newLine);
    this.nonSpecialCharHyphen = m.notChar(this.specialCharSetHyphen).unless(m.newLine);
    // this.specialChar = m.char(this.specialCharSet).ast;
    this.quoteChar = m.notChar('"');
    this.plainText = m.choice(m.digits, m.letters, this.ws, this.nonSpecialChar).oneOrMore.ast;
    this.plainTextHyphen = m.choice(m.digits, m.letters, this.ws).oneOrMore.ast;

    // ...

    // Emphasis
    this.shortEmphasisModerate = m.seq('+', this.plainText , '+').ast;
    this.shortEmphasisStrong = m.seq('++', this.plainText , '++').ast;
    this.shortEmphasisNone = m.seq('~', this.plainText , '~').ast;
    this.shortEmphasisReduced = m.seq('-', this.plainTextHyphen , '-').ast;
    this.emphasis = m.choice(this.shortEmphasisModerate, this.shortEmphasisStrong, this.shortEmphasisNone, this.shortEmphasisReduced);

the test passes.

I cannot figure out why.

rmtuckerphx commented 5 years ago

@Fleker I added a discussion to the VoiceFirst Slack #speechmarkdown channel when you get a chance to look at it.