Exemple #1
0
 private ParseException Error(Token token, string message)
 {
     Lox.Error(token, message);
     return(new ParseException());
 }
Exemple #2
0
        public void Log_SetSourcePathTrimRuleExternal()
        {
            UT_INIT();

            // for the unit tests to reset, we need an extra lox to be able to clear the global rules
            // beforewe initialize our main lox
            Lox clearLox = new Lox("ClearingRules");

            // global rule
            clearLox.ClearSourcePathTrimRules(Inclusion.Include, false);
            {
                // create iniFile
                String iniFileContents =
                    "[ALOX]\n"
                    + "TESTML_FORMAT= \"%Sp\"  \n"

                    + "GLOBAL_SOURCE_PATH_TRIM_RULES=  *src.cs/   , true  ;     \\   \n"
                    + "    /usr/lib/libzip/include/  , false, 9, true"
                    + "\n"
                ;

/* SNIPPIT FOR Dox
 * //! [Man_SourcePathTrimming]
 * [ALOX]
 * GLOBAL_SOURCE_PATH_TRIM_RULES= *src.cs/                  , true                ; \
 *                             /usr/lib/libzip/include/  , false, 9, true
 * //! [Man_SourcePathTrimming]
 */
                String       fileName = Environment.CurrentDirectory + "/Log_ConfigTrimRules.ini";
                StreamWriter file     = new StreamWriter(fileName);
                file.Write(iniFileContents);
                file.Close();

                IniFile iniFile = new IniFile(fileName);
                iniFile.ReadFile();
                //iniFile.WriteFile(); // temporarily enable to see what we have written above

                ALIB.Config.InsertPlugin(iniFile, Configuration.PrioIniFile);

                // test
                Lox lox = new Lox("T_LOX", false);

                lox.SetVerbosity(Lox.CreateConsoleLogger("CONSOLE"), Verbosity.Verbose);
                lox.SetVerbosity("CONSOLE", Verbosity.Verbose, ALox.InternalDomains);

                MemoryLogger ml = new MemoryLogger("TESTML");
                lox.SetVerbosity(ml, Verbosity.Verbose);

                lox.Info("");  UT_EQ("alox.unittests", ml.MemoryLog); ml.MemoryLog._(); ml.AutoSizes.Reset();

                ALIB.Config.RemovePlugin(iniFile);
                lox.RemoveLogger(ml);
                lox.RemoveLogger("CONSOLE");
            }

            // local rule
            clearLox.ClearSourcePathTrimRules(Inclusion.Include, false);
            {
                // create iniFile
                IniFile iniFile = new IniFile("*"); // don't read
                iniFile.Save(ALox.ConfigCategoryName, "TESTML_FORMAT", "%Sp");
                iniFile.Save(ALox.ConfigCategoryName, "T_LOX_SOURCE_PATH_TRIM_RULES",
                             "*;**;*alox.u*, incl ;*;**"   // default values, 0, ignore"
                                                           // the * will be removed
                                                           // two illegal rules before and after
                             );
                ALIB.Config.InsertPlugin(iniFile, Configuration.PrioIniFile);


                // test
                Lox lox = new Lox("T_LOX", false);

                lox.SetVerbosity(Lox.CreateConsoleLogger("CONSOLE"), Verbosity.Verbose);
                lox.SetVerbosity("CONSOLE", Verbosity.Verbose, ALox.InternalDomains);

                MemoryLogger ml = new MemoryLogger("TESTML");
                lox.SetVerbosity(ml, Verbosity.Verbose);

                lox.Info(""); UT_EQ("nittests", ml.MemoryLog); ml.MemoryLog._(); ml.AutoSizes.Reset();

                ALIB.Config.RemovePlugin(iniFile);
                lox.RemoveLogger(ml);
                lox.RemoveLogger("CONSOLE");
            }

            clearLox.ClearSourcePathTrimRules(Inclusion.Include, false);
            {
                // create iniFile
                IniFile iniFile = new IniFile("*"); // don't read
                iniFile.Save(ALox.ConfigCategoryName, "TESTML_FORMAT", "%Sp");
                iniFile.Save(ALox.ConfigCategoryName, "T_LOX_SOURCE_PATH_TRIM_RULES",
                             "*alox.u, excl, 2, sens"
                             );
                ALIB.Config.InsertPlugin(iniFile, Configuration.PrioIniFile);


                // test
                Lox lox = new Lox("T_LOX", false);

                lox.SetVerbosity(Lox.CreateConsoleLogger("CONSOLE"), Verbosity.Verbose);
                lox.SetVerbosity("CONSOLE", Verbosity.Verbose, ALox.InternalDomains);

                MemoryLogger ml = new MemoryLogger("TESTML");
                lox.SetVerbosity(ml, Verbosity.Verbose);

                lox.Info(""); UT_EQ("ox.unittests", ml.MemoryLog); ml.MemoryLog._(); ml.AutoSizes.Reset();

                ALIB.Config.RemovePlugin(iniFile);
                lox.RemoveLogger(ml);
                lox.RemoveLogger("CONSOLE");
            }

            // ignore case
            clearLox.ClearSourcePathTrimRules(Inclusion.Include, false);
            {
                // create iniFile
                IniFile iniFile = new IniFile("*"); // don't read
                iniFile.Save(ALox.ConfigCategoryName, "TESTML_FORMAT", "%Sp");
                iniFile.Save(ALox.ConfigCategoryName, "T_LOX_SOURCE_PATH_TRIM_RULES",
                             "*aLOX.U, exc, 2, ign"
                             );
                ALIB.Config.InsertPlugin(iniFile, Configuration.PrioIniFile);


                // test
                Lox lox = new Lox("T_LOX", false);

                lox.SetVerbosity(Lox.CreateConsoleLogger("CONSOLE"), Verbosity.Verbose);
                lox.SetVerbosity("CONSOLE", Verbosity.Verbose, ALox.InternalDomains);

                MemoryLogger ml = new MemoryLogger("TESTML");
                lox.SetVerbosity(ml, Verbosity.Verbose);

                lox.Info(""); UT_EQ("ox.unittests", ml.MemoryLog); ml.MemoryLog._(); ml.AutoSizes.Reset();

                ALIB.Config.RemovePlugin(iniFile);
                lox.RemoveLogger(ml);
                lox.RemoveLogger("CONSOLE");
            }

            clearLox.ClearSourcePathTrimRules(Inclusion.Include, false);
            {
                // create iniFile
                IniFile iniFile = new IniFile("*"); // don't read
                iniFile.Save(ALox.ConfigCategoryName, "TESTML_FORMAT", "%Sp");
                iniFile.Save(ALox.ConfigCategoryName, "T_LOX_SOURCE_PATH_TRIM_RULES",
                             "*aLOX.U, excl, 2, sens"
                             );
                ALIB.Config.InsertPlugin(iniFile, Configuration.PrioIniFile);


                // test
                Lox lox = new Lox("T_LOX", false);

                lox.SetVerbosity(Lox.CreateConsoleLogger("CONSOLE"), Verbosity.Verbose);
                lox.SetVerbosity("CONSOLE", Verbosity.Verbose, ALox.InternalDomains);

                MemoryLogger ml = new MemoryLogger("TESTML");
                lox.SetVerbosity(ml, Verbosity.Verbose);

                lox.Info("");
                if (Path.DirectorySeparatorChar == '/')
                {
                    UT_EQ("src.cs/alox.unittests", ml.MemoryLog);
                }
                else
                {
                    UT_EQ("src.cs\\alox.unittests", ml.MemoryLog);
                }

                ml.MemoryLog._(); ml.AutoSizes.Reset();
                ALIB.Config.RemovePlugin(iniFile);
                lox.RemoveLogger(ml);
                lox.RemoveLogger("CONSOLE");
            }
        }
Exemple #3
0
    private void ScanToken()
    {
        char c = Advance();

        switch (c)
        {
        case '(':
            AddToken(LeftParen);
            break;

        case ')':
            AddToken(RightParen);
            break;

        case '{':
            AddToken(LeftBrace);
            break;

        case '}':
            AddToken(RightBrace);
            break;

        case ',':
            AddToken(Comma);
            break;

        case '.':
            AddToken(Dot);
            break;

        case '-':
            AddToken(Minus);
            break;

        case '+':
            AddToken(Plus);
            break;

        case ';':
            AddToken(Semicolon);
            break;

        case '*':
            AddToken(Star);
            break;

        case '!':
            AddToken(Match('=') ? BangEqual : Bang);
            break;

        case '=':
            AddToken(Match('=') ? EqualEqual : Equal);
            break;

        case '<':
            AddToken(Match('=') ? LessEqual : Less);
            break;

        case '>':
            AddToken(Match('=') ? GreaterEqual : Greater);
            break;

        case '/':
            if (Match('/'))
            {
                while (Peek() != '\n' && !IsAtEnd())
                {
                    Advance();
                }
            }
            else
            {
                AddToken(Slash);
            }
            break;

        case ' ':
        case '\r':
        case '\t':
            break;

        case '\n':
            Line++;
            break;

        case '"':
            String();
            break;

        default:
            if (IsDigit(c))
            {
                Number();
            }
            else if (IsAlpha(c))
            {
                Identifier();
            }
            else
            {
                Lox.Error(Line, "Unexpected character.");
            }
            break;
        }
    }
        public static void XML( String      domain,     Verbosity verbosity,
                                XElement    xElement,   String       headLine=  null,
                                Lox         lox= null,
                                [CallerLineNumber] int cln=0,[CallerFilePath] String csf="",[CallerMemberName] String cmn="" )
        {
            #if ALOX_DBG_LOG || ALOX_REL_LOG
                try { Lock.Acquire();

                    // create/clear toolBuf
                    if ( toolBuf == null )
                        toolBuf= new AString( 1024 );
                    else
                        toolBuf.Clear();

                    // dump exception to the Buffer
                    xmlElement( xElement, headLine, 0 );

                    // if no lox given, use static Log.LOX or, if debug logging is not active, return
                    if ( lox == null )
                        #if ALOX_DBG_LOG
                            lox= Log.LOX;
                        #else
                            return;
                        #endif

                    // log it using the static Log interface
                    lox.Entry ( domain, verbosity, toolBuf, cln,csf,cmn );


                } finally { Lock.Release(); }
            #endif
        }
 public static void XML( Verbosity verbosity,
                         XElement    xElement,    String  headLine,
                         Lox         lox= null,
                         [CallerLineNumber] int cln=0,[CallerFilePath] String csf="",[CallerMemberName] String cmn="" )
 {
     #if ALOX_DBG_LOG || ALOX_REL_LOG
         XML( null, verbosity, xElement, headLine, lox, cln,csf,cmn );
     #endif
 }
    public static void Instance( Verbosity verbosity,
                                 Object     o,                  int    maxRecursion,
                                 String     headline= null,
                                 Lox        lox=      null,
                                 [CallerLineNumber] int cln=0,[CallerFilePath] String csf="",[CallerMemberName] String cmn="" )

    {
        #if ALOX_DBG_LOG || ALOX_REL_LOG
            Instance( null, verbosity, o, maxRecursion, headline, lox, cln,csf,cmn );
        #endif
    }
    public static void Instance( String  domain,              Verbosity verbosity,
                                 Object  o,                   int         maxRecursion,
                                 String  headline=  null,
                                 Lox     lox=       null,
                                 [CallerLineNumber] int cln=0,[CallerFilePath] String csf="",[CallerMemberName] String cmn="" )

    {
        #if ALOX_DBG_LOG || ALOX_REL_LOG
            try { Lock.Acquire();

                // if no lox given, use static Log.LOX or, if debug logging is not active, return
                if ( lox == null )
                    #if ALOX_DBG_LOG
                        lox= Log.LOX;
                    #else
                        return;
                    #endif

                #if !(ALOX_WP71 || ALOX_WP8 || ALOX_NO_REFLECTION)

                    // dump exception to the Buffer
                    instMain( o, maxRecursion, headline );

                    // log it using the static Log interface
                    lox.Entry ( domain, verbosity, toolBuf, cln,csf,cmn );

                #else
                    lox.Entry ( domain, verbosity, "LoxTools.Instance(): Reflection not supported on this platform. ToString(): ", cln,csf,cmn );
                    lox.Entry ( domain, verbosity, ( "  " + (o == null ? "null" : o.ToString())), cln,csf,cmn );
                #endif // NO_REFLECTION

            } finally { Lock.Release(); }
        #endif
    }
    public static void Exception( Exception e,             String headline= null,
                                  Lox       lox=   null,
                                  [CallerLineNumber] int cln=0,[CallerFilePath] String csf="",[CallerMemberName] String cmn="" )

    {
        #if ALOX_DBG_LOG || ALOX_REL_LOG
            Exception( null, Verbosity.Error, e, headline, lox, cln,csf,cmn );
        #endif
    }
Exemple #9
0
        private Option <Token> ScanToken()
        {
            char c = Advance();

            switch (c)
            {
            case '(': return(GenerateToken(TokenType.LeftParen).Some());

            case ')': return(GenerateToken(TokenType.RightParen).Some());

            case '{': return(GenerateToken(TokenType.LeftBrace).Some());

            case '}': return(GenerateToken(TokenType.RightBrace).Some());

            case ',': return(GenerateToken(TokenType.Comma).Some());

            case '.': return(GenerateToken(TokenType.Dot).Some());

            case '-': return(GenerateToken(TokenType.Minus).Some());

            case '+': return(GenerateToken(TokenType.Plus).Some());

            case ';': return(GenerateToken(TokenType.SemiColon).Some());

            case '*': return(GenerateToken(TokenType.Star).Some());

            case '?': return(GenerateToken(TokenType.Question).Some());

            case ':': return(GenerateToken(TokenType.Colon).Some());

            // operators
            case '!': return(GenerateToken(Match('=') ? TokenType.BangEqual : TokenType.Bang).Some());

            case '=': return(GenerateToken(Match('=') ? TokenType.EqualEqual : TokenType.Equal).Some());

            case '<': return(GenerateToken(Match('=') ? TokenType.LessEqual : TokenType.Less).Some());

            case '>': return(GenerateToken(Match('=') ? TokenType.GreaterEqual : TokenType.Greater).Some());

            case '/':
                if (Match('/'))
                {
                    while (Peek() != '\n' && !IsAtEnd())
                    {
                        Advance();
                    }
                }
                else if (Match('*'))
                {
                    MultiLine();
                }
                else
                {
                    return(GenerateToken(TokenType.Slash).Some());
                }
                break;

            // whitespace
            case ' ':
            case '\r':
            case '\t':
                break;

            case '\n':
                _line++;
                break;

            case '"': return(String().Some());

            // unrecognized character
            default:
                if (IsDigit(c))
                {
                    return(Number().Some());
                }
                else if (IsAlpha(c))
                {
                    return(Identifier().Some());
                }
                else
                {
                    Lox.Error(_line, "Unexpected character.");
                    break;
                }
            }

            return(Option.None <Token>());
        }
Exemple #10
0
 /** ************************************************************************************
  * Constructs an \b %ALoxReportWriter.
  * @param lox    The \b Lox to report to.
  **************************************************************************************/
 public ALoxReportWriter(Lox lox)
 {
     this.lox = lox;
 }