示例#1
0
 public void AttachParser(MultiParser multiParserToAttach)
 {
     foreach (Parser parser in multiParserToAttach.GetParsers())
     {
         AttachParser(parser);
     }
 }
示例#2
0
        private static void TypesafetyCheck_BodyShouldCompile()
        {
            // NOTE: This is just to test whether these calls compile successfully. There is no need to actually call the Parse methods.

            // ensure that parser is typesafe
            MultiParser <Program> _parser = parser;

            parser.Parse(string.Empty);
            parser.Parse(string.Empty, string.Empty);

            parser.Parse(string.Empty, grammar.B.Expression);
            parser.Parse(string.Empty, string.Empty, grammar.B.Expression);

            parser.Parse(string.Empty, (NonTerminal)grammar.B.Expression);
            parser.Parse(string.Empty, string.Empty, (NonTerminal)grammar.B.Expression);
        }
示例#3
0
        protected static void InitializeParser()
        {
            if (initializedParser)
            {
                return;
            }

            InitializeGrammar();

            if (Directory.Exists(actualResultsDir))
            {
                Directory.Delete(actualResultsDir, recursive: true);
            }

            Directory.CreateDirectory(actualResultsDir);

            parser = MultiParser.Create(grammar);

            Assert.IsTrue(parser.GrammarErrorLevel <= GrammarErrorLevel.Info, "Grammar error(s):\n{0}", string.Join("\n", parser.GrammarErrors));

            initializedParser = true;
        }
示例#4
0
        public static void AddMessage(this ChatTextBox textbox, Guid id, string user, string message, string fontName, int fontSize, System.Drawing.FontStyle fontStyle, System.Drawing.Color color, MultiParser parsers, bool allowEdit)
        {
            var item = new MessageItem(user, id, message, fontName, fontSize, fontStyle, color, parsers);

            textbox.AddItem(item, allowEdit);
        }
示例#5
0
//        static string path2 = @"..\..\..\Sarcasm.UnitTest\Test files\Binary1.expr";

        static void Main(string[] args)
        {
            var stopwatch = Stopwatch.StartNew();

            stopwatch.Start();
            var grammar = new MiniPLG.GrammarP();

            ShowTimeAndRestart(stopwatch, "Creation of grammar");

            var parser = MultiParser.Create(grammar);

            ShowTimeAndRestart(stopwatch, "Creation of parser");

            var parseTree = parser.Parse(File.ReadAllText(path), path);

            ShowTimeAndRestart(stopwatch, "Parsing");

            var astRootValue = parseTree.RootAstValue;

//            string generatedCode = new MiniPLC.CSharpGenerator().Generate(astRootValue);
//            string generatedCode = new MiniPLC.CppGenerator().Generate(astRootValue);

#if false
            var jsonGrammar = new JsonGrammar();

            Unparser universalUnparser = new Unparser(jsonGrammar);
            var      universalParser   = MultiParser.Create(jsonGrammar);
            string   text = universalUnparser.Unparse(astRootValue).AsText(universalUnparser);

            var foo = universalUnparser.Unparse(astRootValue).Select(utoken => utoken.GetDecoration()).ToList();

            var parseTree2    = universalParser.Parse(text);
            var astRootValue2 = parseTree2.RootAstValue;

            string text2 = universalUnparser.Unparse(astRootValue2).AsText(universalUnparser);

            bool eq = text == text2;
#endif

            Unparser unparser = new Unparser(grammar);
            ShowTimeAndRestart(stopwatch, "Creation of unparser");

            //var utokens = unparser.Unparse(astRootValue).ToList();
            //ShowTimeAndRestart(stopwatch, "Unparsing to utokens");

            //unparser.EnableParallelProcessing = false;
            //string unparsedText = unparser.Unparse(astRootValue).AsText(unparser);
            //var document = parseTree.GetDocument();
            //string unparsedText = unparser.Unparse(document).AsText(unparser);
            //ShowTimeAndRestart(stopwatch, "Converting utokens to string");

            unparser.EnableParallelProcessing = false;
            //foreach (Utoken utoken in unparser.Unparse(astRootValue))
            //    Console.WriteLine(utoken.ToString());
            unparser.Unparse(astRootValue).ConsumeAll();
            ShowTimeAndRestart(stopwatch, "Sequential unparsing to string");

            unparser.EnableParallelProcessing = true;
            //foreach (Utoken utoken in unparser.Unparse(astRootValue))
            //    Console.WriteLine(utoken.ToString());
            unparser.Unparse(astRootValue).ConsumeAll();
            ShowTimeAndRestart(stopwatch, "Parallel unparsing to string");

            //var utokensReverse = unparser.Unparse(astRootValue, Unparser.Direction.RightToLeft).ToList();
            //ShowTimeAndRestart(stopwatch, "Reverse unparsing to utokens");

            unparser.EnableParallelProcessing = false;
            unparser.Unparse(astRootValue, Unparser.Direction.RightToLeft).ConsumeAll();
            ShowTimeAndRestart(stopwatch, "Reverse sequential unparsing to string");

            unparser.EnableParallelProcessing = true;
            unparser.Unparse(astRootValue, Unparser.Direction.RightToLeft).ConsumeAll();
            ShowTimeAndRestart(stopwatch, "Reverse parallel unparsing to string");

            //stopwatch.Stop();
            //Console.WriteLine(stopwatch.ElapsedMilliseconds);
            //stopwatch.Start();
            //var parser2 = MultiParser.Create(grammar);
            //stopwatch.Stop();
            //Console.WriteLine(stopwatch.ElapsedMilliseconds);

            //var parseTree2 = parser.Parse(File.ReadAllText(path2), path2, grammar.B.Expression);
            //var parseTree3 = parser.Parse(File.ReadAllText(path2), path2, (NonTerminal)grammar.B.Expression);
            //MiniPL.DomainDefinitions.Expression astValue2 = parseTree2.RootAstValue;

            //Unparser unparser = new Unparser(grammar);

            //Directory.CreateDirectory("unparse_logs");
            //var stream = File.Create(@"unparse_logs\unparsed_text");
            //unparser.Unparse(parseTree.Root.AstNode).WriteToStream(stream, unparser);

            ////string str = unparser.Unparse(parseTree.Root.AstNode).AsString(unparser);
            ////Console.WriteLine(str);
        }
示例#6
0
 public void AttachParser(MultiParser multiParserToAttach)
 {
     foreach (Parser parser in multiParserToAttach.GetParsers())
         AttachParser(parser);
 }
示例#7
0
 public Formatter(MultiParser multiParserToAttach)
     : this(multiParserToAttach.GetMainParser().Context.Culture)
 {
     this.attachedParsers = new List<Parser>();
     AttachParser(multiParserToAttach);
 }
 public MessageItem(string user, Guid id, string message, string fontName, int fontSize, System.Drawing.FontStyle fontStyle, System.Drawing.Color color, MultiParser parsers)
 {
     this.User      = user;
     this.Id        = id;
     this.Message   = message;
     this.FontName  = fontName;
     this.FontSize  = fontSize;
     this.FontStyle = fontStyle;
     this.Color     = color;
     this.Parsers   = parsers;
 }
示例#9
0
 public Formatter(MultiParser multiParserToAttach)
     : this(multiParserToAttach.GetMainParser().Context.Culture)
 {
     this.attachedParsers = new List <Parser>();
     AttachParser(multiParserToAttach);
 }