eignnx / affix-grammar

An affix-grammar format and sentence generator.
Mozilla Public License 2.0
0 stars 0 forks source link

uppercase operator. #11

Open eignnx opened 4 years ago

eignnx commented 4 years ago

create an OutToken which will capitalize the next character it sees.

Proposed Syntax

rule start = !my_sentence + "."

rule my_sentence = "once upon a time I died"

this example would generate the sentence:

Once upon a time I died.

Alternate Syntax

ranked in order of my personal preference

rule start = !my_sentence + "."
rule start = ^my_sentence + "."
rule start = `my_sentence + "."
rule start = :my_sentence + "."
rule start = /my_sentence + "."
rule start = [my_sentence] + "."
rule start = \my_sentence + "."
rule start = &my_sentence + "."

Implementation

  1. teach parser how to parse a ! character to some new Token variant

    #[derive(Debug, Clone, PartialEq)]
    pub enum Token {
    RuleRef(RuleRef),
    StrLit(IStr),
    DataVariable(DataVariable),
    DataVariant(DataVariant),
    Plus,
    Bang, // <---
    }
  2. add an enum variant to libaffix::gen::OutToken:

    #[derive(Clone, Hash, PartialEq, Eq, Debug)]
    enum OutToken {
    Sym(IStr),
    Plus, // For concatenation without space insertion.
    Upper, // For capitalizing the next character.
    }
  3. teach libaffix::gen::join_symbols how to capitalize the next character when it sees an OutToken::Upper variant.