Example #1
0
 public JavaStyle()
 {
     CommentStart    = "/*";
     CommentEnd      = "*/";
     CommentLine     = "//";
     NestedComments  = true;
     IdentStart      = Prim.Letter();
     IdentLetter     = Prim.LetterOrDigit().Or(Prim.Character('_').Or(Prim.Character('\'')));
     ReservedOpNames = new string[0];
     ReservedNames   = new string[0];
     CaseSensitive   = true;
 }
Example #2
0
 public HaskellStyle()
 {
     CommentStart    = "{-";
     CommentEnd      = "-}";
     CommentLine     = "--";
     NestedComments  = true;
     IdentStart      = Prim.Letter();
     IdentLetter     = Prim.LetterOrDigit().Or(Prim.Character('_').Or(Prim.Character('\'')));
     OpStart         = OpLetter = Prim.OneOf(":!#$%&*+./<=>?@\\^|-~");
     ReservedOpNames = new string[0];
     ReservedNames   = new string[0];
     CaseSensitive   = true;
 }
Example #3
0
        public void BuildMLParser()
        {
            var ws = Prim.WhiteSpace();// | New.Return(new ParserChar(' '));

            Id = from w in ws
                 from c in Prim.Letter()
                 from cs in Prim.Many(Prim.LetterOrDigit())
                 select c.Cons(cs);

            Ident = from s in Id
                    where s.IsNotEqualTo("let") && s.IsNotEqualTo("in")
                    select s;

            LetId = from s in Id
                    where s.IsEqualTo("let")
                    select s;

            InId = from s in Id
                   where s.IsEqualTo("in")
                   select s;

            Term1 = (from x in Ident
                     select new VarTerm(x) as Term)
                    | (from u1 in Lang.WsChr('(')
                       from t in Term
                       from u2 in Lang.WsChr(')')
                       select t);

            Term = (from u1 in Lang.WsChr('\\')
                    from x in Ident
                    from u2 in Lang.WsChr('.')
                    from t in Term
                    select new LambdaTerm(x, t) as Term)
                   | (from lid in LetId
                      from x in Ident
                      from u1 in Lang.WsChr('=')
                      from t in Term
                      from inid in InId
                      from c in Term
                      select new LetTerm(x, t, c) as Term)
                   | (from t in Term1
                      from ts in Prim.Many(Term1)
                      select new AppTerm(t, ts) as Term);

            Parser = from t in Term
                     from u in Lang.WsChr(';')
                     select t;
        }
Example #4
0
        public void BuildLangParser()
        {
            var opChars = ";.,<>?/\\|\"':=+-_*&^%$£@!".AsEnumerable();

            Id = from w in Prim.WhiteSpace()
                 from c in Prim.Letter()
                 from cs in Prim.Many(Prim.LetterOrDigit())
                 select c.Cons(cs);

            Op = (from w in Prim.WhiteSpace()
                  from o in Prim.Satisfy(c => opChars.Contains(c), "an operator")
                  from os in Prim.Many(Prim.Satisfy(c => opChars.Contains(c), "an operator"))
                  select o.Cons(os))
                 .Fail("an operator");

            Ident = (from s in Id
                     where
                     s.IsNotEqualTo("let") &&
                     s.IsNotEqualTo("in")
                     select s)
                    .Fail("identifier");

            LetId = (from s in Id
                     where s.IsEqualTo("let")
                     select s)
                    .Fail("let");

            InId = (from s in Id
                    where s.IsEqualTo("in")
                    select s)
                   .Fail("'in'");

            Semi = (from s in Op
                    where s.IsEqualTo(";")
                    select s)
                   .Fail("';'");

            LambdaArrow = (from s in Op
                           where s.IsEqualTo("=>")
                           select s)
                          .Fail("a lambda arrow '=>'");

            Integer = (from w in Prim.WhiteSpace()
                       from d in Prim.Integer()
                       select new IntegerTerm(d) as Term)
                      .Fail("an integer");

            String = (from w in Prim.WhiteSpace()
                      from o in Prim.Character('"')
                      from cs in Prim.Many(Prim.Satisfy(c => c != '"'))
                      from c in Prim.Character('"')
                      select new StringTerm(cs) as Term)
                     .Fail("a string literal");

            Term1 = Integer
                    | String
                    | (from x in Ident
                       select new VarTerm(x) as Term)
                    | (from u1 in Lang.WsChr('(')
                       from t in Term
                       from u2 in Lang.WsChr(')')
                       select t)
                    .Fail("a term");

            Term = (from x in Ident
                    from arrow in LambdaArrow
                    from t in Term
                    select new LambdaTerm(x, t) as Term)
                   | (from lid in LetId
                      from x in Ident
                      from u1 in Lang.WsChr('=')
                      from t in Term
                      from s in Semi
                      from c in Term
                      select new LetTerm(x, t, c) as Term)
                   | (from t in Term1
                      from ts in Prim.Many(Term1)
                      select new AppTerm(t, ts) as Term)
                   .Fail("a term");

            Parser = from t in Term
                     from u in Lang.WsChr(';')
                     from w in Prim.WhiteSpace()
                     select t;
        }