Beispiel #1
0
        public void Import(string fileName)
        {
            if (!hasBeenSetUp)
            {
                throw new Exception();
            }

            fileName = pathResolver.Resolve(fileName);

            string absoluteFileName = Path.GetFullPath(fileName);

            if (imported.Contains(absoluteFileName))
            {
                return;
            }

            if (verbose)
            {
                Console.WriteLine("importing " + fileName);
            }

            imported.Add(absoluteFileName);

            if (Path.GetExtension(fileName).ToLower() == ".dll")
            {
                Assembly.LoadFrom(fileName);
            }
            else
            {
                pathResolver.PushDirectory(fileName);

                Lexer        lexer        = new Lexer(parseTrace, fileName);
                RuntimeState runtimeState = new RuntimeState(this, rootModule);

                currentLexer = lexer;

                Pattern oldRoot = grammar.RootPattern;

                try
                {
                    string extension = Path.GetExtension(fileName).ToLower();

                    if ((extension != "") && (extension != ".kat"))
                    {
                        IDictionary languages = (IDictionary)rootModule.GetName("languages");
                        object      callable  = languages[extension];
                        Type        rootType  = (Type)CallNode.Call(runtimeState, callable, null);

                        grammar.RootPattern = Pattern.PatternForType(rootType);
                    }

                    grammar.Parse(lexer, runtimeState);
                }
                catch (Exception exception)
                {
                    if (runtimeState.RunningSource != null)
                    {
                        Console.WriteLine(runtimeState.RunningSource);
                    }

                    throw exception;
                }
                finally
                {
                    grammar.RootPattern = oldRoot;
                }

                pathResolver.PopDirectory();
            }
        }
Beispiel #2
0
 public void Import(string fileName)
 {
     if (!hasBeenSetUp)
         throw new Exception();
     
     fileName = pathResolver.Resolve(fileName);
     
     string absoluteFileName = Path.GetFullPath(fileName);
     
     if (imported.Contains(absoluteFileName))
         return;
     
     if (verbose)
         Console.WriteLine("importing " + fileName);
     
     imported.Add(absoluteFileName);
     
     if (Path.GetExtension(fileName).ToLower() == ".dll")
     {
         Assembly.LoadFrom(fileName);
     }
     else
     {
         pathResolver.PushDirectory(fileName);
     
         Lexer lexer = new Lexer(parseTrace, fileName);
         RuntimeState runtimeState = new RuntimeState(this, rootModule);
     
         currentLexer = lexer;
         
         Pattern oldRoot = grammar.RootPattern;
         
         try
         {
             string extension = Path.GetExtension(fileName).ToLower();
             
             if ((extension != "") && (extension != ".kat"))
             {
                 IDictionary languages = (IDictionary) rootModule.GetName("languages");
                 object callable = languages[extension];
                 Type rootType = (Type) CallNode.Call(runtimeState, callable, null);
                     
                 grammar.RootPattern = Pattern.PatternForType(rootType);
             }
             
             grammar.Parse(lexer, runtimeState);
         }
         catch (Exception exception)
         {
             if (runtimeState.RunningSource != null)
                 Console.WriteLine(runtimeState.RunningSource);
             
             throw exception;
         }
         finally
         {
             grammar.RootPattern = oldRoot;
         }
         
         pathResolver.PopDirectory();
     }
 }
Beispiel #3
0
 public void ProgressChanged(Lexer lexer)
 {
     if (ProgressChangedEvent != null)
         ProgressChangedEvent(lexer);
 }