예제 #1
0
        public void SymbolTest()
        {
            var sym = from s in Tok.Symbol("***")
                      select s;

            var res = sym.Parse("***   ");

            Assert.True(!res.IsFaulted);
        }
예제 #2
0
        public GenTokenParser(LanguageDef def)
        {
            Identifier    = Tok.Id.Identifier(def);
            reserved      = def.ReservedNames.ToDictionary(name => name, name => Tok.Id.Reserved(name, def) as Parser <ReservedToken>);
            Operator      = Tok.Ops.Operator(def);
            reservedOp    = def.ReservedOpNames.ToDictionary(name => name, name => Tok.Ops.ReservedOp(name, def) as Parser <ReservedOpToken>);
            CharLiteral   = Tok.Chars.CharLiteral();
            StringLiteral = Tok.Strings.StringLiteral();
            Natural       = Tok.Numbers.Natural();
            Integer       = Tok.Numbers.Integer();

            // floating = Tok.Numbers.Floating(); TODO
            // naturalOrFloat = Tok.Numbers.NaturalOrFloating(); TODO

            WhiteSpace  = Tok.WhiteSpace(def);
            Decimal     = Tok.Numbers.Decimal();
            Hexadecimal = Tok.Numbers.Hexadecimal();
            Octal       = Tok.Numbers.Octal();
            Symbol      = (string name) => Tok.Symbol(name);
            Lexeme      = (Parser <A> p) => Tok.Lexeme(p);

            Parens   = (Parser <A> p) => Tok.Bracketing.Parens(p);
            Braces   = (Parser <A> p) => Tok.Bracketing.Braces(p);
            Angles   = (Parser <A> p) => Tok.Bracketing.Angles(p);
            Brackets = (Parser <A> p) => Tok.Bracketing.Brackets(p);

            Semi      = Tok.Symbol(";");
            Comma     = Tok.Symbol(",");
            Colon     = Tok.Symbol(":");
            Dot       = Tok.Symbol(".");
            CommaSep  = (Parser <A> p) => Prim.SepBy(p, Comma);
            SemiSep   = (Parser <A> p) => Prim.SepBy(p, Semi);
            CommaSep1 = (Parser <A> p) => Prim.SepBy1(p, Comma);
            SemiSep1  = (Parser <A> p) => Prim.SepBy1(p, Semi);

            Reserved   = name => reserved[name];
            ReservedOp = name => reservedOp[name];
        }
예제 #3
0
 public Brackets(Parser <A> betweenParser)
     :
     base(inp => Prim.Between(Tok.Symbol("["), Tok.Symbol("]"), betweenParser)
          .Parse(inp))
 {
 }
예제 #4
0
 public Angles(Parser <A> betweenParser)
     :
     base(inp => Prim.Between(Tok.Symbol("<"), Tok.Symbol(">"), betweenParser)
          .Parse(inp))
 {
 }
예제 #5
0
 public Braces(Parser <A> betweenParser)
     :
     base(inp => Prim.Between(Tok.Symbol("{"), Tok.Symbol("}"), betweenParser)
          .Parse(inp))
 {
 }
예제 #6
0
 public Parens(Parser <A> betweenParser)
     :
     base(inp => Prim.Between(Tok.Symbol("("), Tok.Symbol(")"), betweenParser)
          .Parse(inp))
 {
 }