/// <summary>Creates a new variable fragment by reading it from the given lexer.</summary>
        /// <param name="sr">The lexer to read the variable from.</param>
        public VariableFragment(CodeLexer sr)
        {
            Value += char.ToLower(sr.Read());

            // Read until some other block can take over:
            while (true)
            {
                char peek = sr.Peek();
                if (peek == ';' || peek == ',' || peek == StringReader.NULL || BracketFragment.AnyBracket(peek))
                {
                    // Pass control back to the operation:
                    break;
                }

                if (sr.PeekJunk())
                {
                    // Is Value anything special?
                    if (Value == "var")
                    {
                        break;
                    }
                    else if (Value == "private")
                    {
                        break;
                    }
                    else if (Value == "function")
                    {
                        break;
                    }
                    else if (Value == "class")
                    {
                        break;
                    }
                    else if (Value == "new")
                    {
                        GivenType = new TypeFragment(sr, false);
                        break;
                    }
                    else if (IsKeyword())
                    {
                        break;
                    }
                }

                Handler handle = Handlers.Find(peek);

                if (handle != Handler.Stop && handle != Handler.Variable && handle != Handler.Number)
                {
                    break;
                }

                Value += char.ToLower(sr.Read());
            }
        }
 /// <summary>Creates a property fragment by reading it from the given lexer.</summary>
 /// <param name="sr">The lexer to read the fragment from.</param>
 public PropertyFragment(CodeLexer sr)
 {
     // Skip the dot:
     sr.Read();
     // Read a 'variable':
     Value += char.ToLower(sr.Read());
     while (true)
     {
         char peek = sr.Peek();
         if (peek == ';' || peek == ',' || peek == '.' || peek == StringReader.NULL || BracketFragment.AnyBracket(peek))
         {
             // Pass control back to the operation:
             break;
         }
         Handler handle = Handlers.Find(peek);
         if (handle != Handler.Stop && handle != Handler.Variable && handle != Handler.Number && handle != Handler.Property)
         {
             break;
         }
         Value += char.ToLower(sr.Read());
     }
 }
Beispiel #3
0
        /// <summary>Reads a new operation from the given lexer.</summary>
        /// <param name="sr">The lexer to read the operation from.</param>
        /// <param name="parent">The fragment to parent the operation to.</param>
        public OperationFragment(CodeLexer sr, CodeFragment parent)
        {
            ParentFragment = parent;
            LineNumber     = sr.LineNumber;
            bool localMode = false;

            while (true)
            {
                char peek = sr.Peek();

                if (peek == StringReader.NULL)
                {
                    return;
                }

                if (peek == ';' || peek == ',')
                {
                    // Read it off:
                    sr.Read();
                    return;
                }

                Handler handler = Handlers.Find(peek);

                if (handler == Handler.Stop)
                {
                    return;
                }

                // Handle the fragment:
                CodeFragment fragment;

                try{
                    // Try to get the code fragment:
                    fragment = Handlers.Handle(handler, sr);
                }catch (CompilationException e) {
                    if (e.LineNumber == -1)
                    {
                        // Setup line number:
                        e.LineNumber = LineNumber;
                    }

                    // Rethrow:
                    throw e;
                }

                if (localMode)
                {
                    // Should always be a VariableFragment:

                    if (fragment.GetType() == typeof(VariableFragment))
                    {
                        VariableFragment local = (VariableFragment)fragment;
                        local.AfterVar = true;
                    }

                    localMode = false;
                }

                // Try adding the fragment to the operation:
                AddResult status = fragment.AddTo(this, sr);

                // What was the outcome?
                switch (status)
                {
                case AddResult.Stop:
                    // Halt.
                    return;

                case AddResult.Local:
                    // Local next:
                    localMode = true;
                    break;
                    // Ok otherwise.
                }
            }
        }