コード例 #1
0
        /// <inheritdoc />
        public override IEnumerable <TokenPair> Tokenize(TokenInfo token, ParserOptions options)
        {
            var trim = token.Token;

            if (trim.StartsWith(TagOpen, StringComparison.OrdinalIgnoreCase))
            {
                yield return(new TokenPair(TagOpen.Trim(), token.TokenizerContext.CurrentLocation, ExpressionParser.ParseExpression(trim.Remove(0, OpenTag.Length).Trim(), token.TokenizerContext)));
            }
            if (string.Equals(trim, TagClose, StringComparison.OrdinalIgnoreCase))
            {
                yield return(new TokenPair(TagClose, trim, token.TokenizerContext.CurrentLocation));
            }
        }
コード例 #2
0
        /// <inheritdoc />
        public override IEnumerable <TokenPair> Tokenize(TokenInfo token, ParserOptions options)
        {
            var trim = token.Token;

            if (trim.StartsWith(TagOpen))
            {
                yield return(new TokenPair(TagOpen.Trim(),
                                           token.TokenizerContext.CurrentLocation, ExpressionParser.ParseExpression(trim.Remove(0, OpenTag.Length).Trim(), token.TokenizerContext)));
            }
            if (trim == TagClose)
            {
                yield return(new TokenPair(TagClose, trim, token.TokenizerContext.CurrentLocation));
            }
        }
コード例 #3
0
        public void TestTagNesting()
        {
            //Non-nested tags are possible, even with the same type, by using capitalization.
            var data = "a<speed=2>b<SPEED=4>c</speed>d</SPEED>efg";
            var cfg  = SpeechSettings.Default with {
                opsPerSecond    = 1,
                opsPerChar      = (s, i) => 1,
                opsPerRollEvent = 1,
                rollEvent       = null
            };

            var s1 = new Speech(data, cfg);

            ListEq(s1.TextUnits, new TextUnit[] {
                new TextUnit.String("a"),
                new TextUnit.OpenTag("speed", "2"),
                new TextUnit.String("b"),
                new TextUnit.OpenTag("SPEED", "4"),
                new TextUnit.String("c"),
                new TextUnit.CloseTag("speed"),
                new TextUnit.String("d"),
                new TextUnit.CloseTag("SPEED"),
                new TextUnit.String("efg"),
            });
            var t1 = new TagOpen("speed", new SpeechTag.Speed(2));
            var t2 = new TagOpen("SPEED", new SpeechTag.Speed(4));

            ListEq(s1.Fragments, new SpeechFragment[] {
                new Char('a'),
                new Wait(1),
                t1,
                new Char('b'),
                new Wait(0.5f),
                t2,
                new Char('c'),
                new Wait(0.125f),
                new TagClose(t1),
                new Char('d'),
                new Wait(0.25f),
                new TagClose(t2),
                new Char('e'),
                new Wait(1),
                new Char('f'),
                new Wait(1),
                new Char('g'),
                new Wait(1),
            });

            //The parser will prefer to match a closing tag to the last opened tag.
            data = "a<speed=2>b<speed=4>c</speed>d</speed>efg";
            var t3 = new TagOpen("speed", new SpeechTag.Speed(4));

            ListEq(new Speech(data, cfg).Fragments, new SpeechFragment[] {
                new Char('a'),
                new Wait(1),
                t1,
                new Char('b'),
                new Wait(0.5f),
                t3,
                new Char('c'),
                new Wait(0.125f),
                new TagClose(t3),
                new Char('d'),
                new Wait(0.5f),
                new TagClose(t1),
                new Char('e'),
                new Wait(1),
                new Char('f'),
                new Wait(1),
                new Char('g'),
                new Wait(1),
            });
        }
    }
コード例 #4
0
ファイル: Speech.cs プロジェクト: Bagoum/suzunoya
 public TagClose(TagOpen opener)
 {
     this.opener = opener;
 }