Example #1
0
        /* action -- do something! What you do is determined by the argument:
         *      1   Output A. Copy B to A. Get the next B.
         *      2   Copy B to A. Get the next B. (Delete A).
         *      3   Get the next B. (Delete B).
         * action treats a string as a single character. Wow!
         * action recognizes a regular expression if it is preceded by ( or , or =.
         */

        private void Action(JsMinAction d)
        {
            if (d == JsMinAction.OutputA)
            {
                WriteChar(_charA);
            }

            if (d == JsMinAction.OutputA || d == JsMinAction.CopyBtoA)
            {
                _charA = _charB;

                if (_charA == '\'' || _charA == '"')
                {
                    for (;;)
                    {
                        WriteChar(_charA);

                        _charA = Get();

                        if (_charA == _charB)
                        {
                            break;
                        }

                        if (_charA <= '\n' || _charA == EOF)
                        {
                            throw new Exception(string.Format("Error: JSMIN unterminated string literal: {0}\n", _charA));
                        }

                        if (_charA == '\\')
                        {
                            WriteChar(_charA);

                            _charA = Get();
                        }
                    }
                }
            }
            _charB = Next();

            if (_charB == '/' && (_charA == '(' || _charA == ',' || _charA == '=' ||
                                  _charA == '[' || _charA == '!' || _charA == ':' ||
                                  _charA == '&' || _charA == '|' || _charA == '?' ||
                                  _charA == '{' || _charA == '}' || _charA == ';' ||
                                  _charA == '\n'))
            {
                WriteChar(_charA);
                WriteChar(_charB);

                for (;;)
                {
                    _charA = Get();

                    if (_charA == '/')
                    {
                        break;
                    }

                    if (_charA == '\\')
                    {
                        WriteChar(_charA);

                        _charA = Get();
                    }
                    else if (_charA <= '\n' || _charA == EOF)
                    {
                        throw new Exception(string.Format("Error: JSMIN unterminated Regular Expression literal : {0}.\n", _charA));
                    }

                    WriteChar(_charA);
                }

                _charB = Next();
            }
        }
Example #2
0
        /* action -- do something! What you do is determined by the argument:
                1   Output A. Copy B to A. Get the next B.
                2   Copy B to A. Get the next B. (Delete A).
                3   Get the next B. (Delete B).
           action treats a string as a single character. Wow!
           action recognizes a regular expression if it is preceded by ( or , or =.
        */

        private void Action(JsMinAction d)
        {
            if (d == JsMinAction.OutputA)
            {
                WriteChar(_charA);
            }

            if (d ==JsMinAction.OutputA || d == JsMinAction.CopyBtoA)
            {
                _charA = _charB;

                if (_charA == '\'' || _charA == '"')
                {
                    for (;;)
                    {
                        WriteChar(_charA);

                        _charA = Get();

                        if (_charA == _charB)
                            break;

                        if (_charA <= '\n' || _charA == EOF)
                            throw new Exception(string.Format("Error: JSMIN unterminated string literal: {0}\n", _charA));

                        if (_charA == '\\')
                        {
                            WriteChar(_charA);

                            _charA = Get();
                        }
                    }
                }
            }
                _charB = Next();

                if (_charB == '/' && (_charA == '(' || _charA == ',' || _charA == '=' ||
                                      _charA == '[' || _charA == '!' || _charA == ':' ||
                                      _charA == '&' || _charA == '|' || _charA == '?' ||
                                      _charA == '{' || _charA == '}' || _charA == ';' ||
                                      _charA == '\n'))
                {
                    WriteChar(_charA);
                    WriteChar(_charB);

                    for (;;)
                    {
                        _charA = Get();

                        if (_charA == '/')
                            break;
                        
                        if (_charA == '\\')
                        {
                            WriteChar(_charA);

                            _charA = Get();
                        }
                        else if (_charA <= '\n' || _charA == EOF)
                        {
                            throw new Exception(string.Format("Error: JSMIN unterminated Regular Expression literal : {0}.\n", _charA));
                        }

                        WriteChar(_charA);
                    }

                    _charB = Next();
                }

        }