Exemplo n.º 1
0
 static void ParseFile(string filePath)
 {
     var fileLoader = new FileLoader();
     var content    = File.ReadAllText(filePath, GetFileEncoding(filePath));
     var parser     = Parser.FromText(content, filePath, CompilerDefines.CreateStandard(), fileLoader);
     var parseTree  = parser.ParseRule(RuleType.Goal);
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            ParseFile(@"H:\Work\Unit.pas");


            var matches    = new List <string>();
            var fileLoader = new FileLoader();

            var path = @"E:\Work";

            foreach (var filePath in Directory.EnumerateFiles(path, "*.pas", SearchOption.TopDirectoryOnly))
            {
                try {
                    var content   = File.ReadAllText(filePath, GetFileEncoding(filePath));
                    var parser    = Parser.FromText(content, filePath, CompilerDefines.CreateStandard(), fileLoader);
                    var parseTree = parser.ParseRule(RuleType.Goal);
                } catch (Exception ex) {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Error in " + filePath);
                    Console.ResetColor();
                    Directory.CreateDirectory("Errors");
                    File.WriteAllText(Path.Combine("Errors", Path.GetFileName(filePath) + ".txt"), ex.ToString());
                }
            }
        }
Exemplo n.º 3
0
        string Convert(string unitFileName, string delphiCode)
        {
            CodeBase codeBase = new CodeBase(CompilerDefines.CreateEmpty(), new MemoryFileLoader());

            codeBase.AddFileExpectingSuccess(unitFileName, delphiCode);
            return(new ToCSharpVisitor().Convert(codeBase));
        }
Exemplo n.º 4
0
        public void ToCodeWithoutTrailingDirectives()
        {
            Parser parser = Parser.FromText("procedure of object", "",
                                            CompilerDefines.CreateEmpty(), new MemoryFileLoader());
            AstNode node = parser.ParseRule(RuleType);

            Assert.That(node.ToCode(), Is.EqualTo("procedure of object"));
        }
Exemplo n.º 5
0
 public void SetUp()
 {
     _fileLoader = new MemoryFileLoader();
     _defines    = CompilerDefines.CreateEmpty();
     _defines.DefineSymbol("TRUE");
     _defines.UndefineSymbol("FALSE");
     _defines.DefineDirectiveAsTrue("IF True");
     _defines.DefineDirectiveAsFalse("IF False");
 }
        protected IList <Hit> HitsFor(params string[] text)
        {
            List <string> unit = new List <string>();

            AddPrefix(unit);
            unit.AddRange(text);
            AddSuffix(unit);
            string   joinedText = String.Join(Environment.NewLine, unit.ToArray());
            CodeBase codeBase   = new CodeBase(CompilerDefines.CreateEmpty(), new MemoryFileLoader());

            codeBase.AddFileExpectingSuccess("Foo.pas", joinedText);
            return(CreateAction().Execute(codeBase));
        }
Exemplo n.º 7
0
        private static UnitNode CreateAstNodeTree(string delphiCode)
        {
#if NEVER
            // Parse without filtering out comment tokens...
            Lexer  lexer  = new Lexer(delphiCode, "input");
            Parser parser = Parser.FromTokens(lexer.Tokens);
#endif
            Parser parser = Parser.FromText(delphiCode, "input", CompilerDefines.CreateStandard(),
                                            new MemoryFileLoader());

            AstNode tree = parser.ParseRule(RuleType.Unit);
            //var Text = tree.Inspect();

            UnitNode unitNode = (UnitNode)tree;
            return(unitNode);
        }
Exemplo n.º 8
0
 public void Parse()
 {
     try
     {
         Parser parser = Parser.FromText(viewSourceControl1.Text, "input", CompilerDefines.CreateStandard(),
                                         new MemoryFileLoader());
         AstNode tree = parser.ParseRule(_ruleType);
         edtResults.Text = tree.Inspect();
     }
     catch (DGrokException ex)
     {
         edtResults.Text = "Filename: " + ex.Location.FileName + Environment.NewLine +
                           "Offset: " + ex.Location.Offset + Environment.NewLine +
                           ex.Message;
         viewSourceControl1.Focus();
         viewSourceControl1.ScrollToOffset(ex.Location.Offset);
         return;
     }
 }
Exemplo n.º 9
0
 //[global::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitialize]
 public void SetUp()
 {
     _defines = CompilerDefines.CreateEmpty();
 }
Exemplo n.º 10
0
        private AstNode Parse(string text, RuleType ruleType)
        {
            Parser parser = Parser.FromText(text, "", CompilerDefines.CreateEmpty(), new MemoryFileLoader());

            return(parser.ParseRule(ruleType));
        }
Exemplo n.º 11
0
 public void SetUp()
 {
     _codeBase = new CodeBase(CompilerDefines.CreateEmpty(), new MemoryFileLoader());
 }
Exemplo n.º 12
0
 public static Parser CreateParser(string source)
 {
     return(Parser.FromText(source, "", CompilerDefines.CreateEmpty(),
                            new MemoryFileLoader()));
 }
Exemplo n.º 13
0
 public void SetUp()
 {
     _parser = Parser.FromText("Foo.Bar.Baz", "",
                               CompilerDefines.CreateEmpty(), new MemoryFileLoader());
 }
Exemplo n.º 14
0
        private void AssertDefined(string directive, Constraint constraint)
        {
            CompilerDefines defines = _options.CreateCompilerDefines();

            Assert.That(defines.IsTrue(directive, null), constraint, directive);
        }