Beispiel #1
0
        public void ProvidesConvenienceSubclassForDefiningKeywords()
        {
            var foo = new KeywordTokenKind("foo");

            foo.Name.ShouldBe("foo");

            foo.TryMatch(new InputText("bar"), out Token token).ShouldBeFalse();
            token.ShouldBeNull();

            foo.TryMatch(new InputText("foo"), out token).ShouldBeTrue();
            token.ShouldBe(foo, "foo", 1, 1);

            foo.TryMatch(new InputText("foo bar"), out token).ShouldBeTrue();
            token.ShouldBe(foo, "foo", 1, 1);

            foo.TryMatch(new InputText("foobar"), out token).ShouldBeFalse();
            token.ShouldBeNull();

            Func <TokenKind> notJustLetters = () => new KeywordTokenKind(" oops ");

            notJustLetters.ShouldThrow <ArgumentException>("Keywords may only contain letters.\r\nParameter name: keyword");
        }
Beispiel #2
0
 public KeywordToken(KeywordTokenKind kind, SourceSpan location) : base(location)
 {
     Kind = kind;
 }