示例#1
0
        public override ParseTree Parse(Lexer lexer, ParserState state)
        {
            lexer.Whitespace(state.RuntimeState);

            int start = lexer.Position;

            state.RuntimeState.Runtime.ParseTrace.Enter(this, lexer.CurrentSource(), "[]");

            char character = lexer.Peek();

            if (character == '\0')
            {
                state.RuntimeState.Runtime.ParseTrace.No(this, lexer.SourceFrom(start), "End of source");
                return(ParseTree.No);
            }

            lexer.Read();

            state.RuntimeState.Runtime.ParseTrace.Yes(this, lexer.SourceFrom(start), TextEscape.Quote(character));

            if (state.BuildTextNodes)
            {
                return(new ParseTree(Convert.ToString(character)));
            }
            else
            {
                return(ParseTree.Yes);
            }
        }
示例#2
0
        public override ParseTree Parse(Lexer lexer, ParserState state)
        {
            lexer.Whitespace(state.RuntimeState);

            int start = lexer.Position;

            state.RuntimeState.Runtime.ParseTrace.Enter(this, lexer.CurrentSource(), range.ToString());

            char character = lexer.Peek();

            if (!range.Contains(character))
            {
                lexer.ErrorStrings[start].Add(range.ToString());

                state.RuntimeState.Runtime.ParseTrace.No(this,
                                                         lexer.SourceFrom(start), TextEscape.Quote(character));

                return(ParseTree.No);
            }

            lexer.Read();

            state.RuntimeState.Runtime.ParseTrace.Yes(this,
                                                      lexer.SourceFrom(start), TextEscape.Quote(character));

            if (state.BuildTextNodes)
            {
                return(new ParseTree(Convert.ToString(character)));
            }
            else
            {
                return(ParseTree.Yes);
            }
        }
示例#3
0
        public static object GetMember(object obj, string member,
                                       object[] parametersHint, bool throwIfUndefined)
        {
            if (obj is IScope)
            {
                // FIXME - shouldn't be using exceptions for this

                try
                {
                    return(((IScope)obj).GetName(member));
                }
                catch
                {
                }
            }

            MemberInfo memberInfo = FindMember(obj, member,
                                               parametersHint);

            if (memberInfo == null)
            {
                if (throwIfUndefined)
                {
                    throw new Exception("can't find getable member "
                                        + TextEscape.Quote(member) + " in "
                                        + TypeNames.GetName(obj.GetType()));
                }
                else
                {
                    return(null);
                }
            }

            if (memberInfo is MethodInfo)
            {
                return(new ClrObjectMethodBinding(obj, (MethodInfo)memberInfo));
            }
            else if (memberInfo is PropertyInfo)
            {
                return(((PropertyInfo)memberInfo).GetValue(obj, null));
            }
            else if (memberInfo is FieldInfo)
            {
                object fieldValue = ((FieldInfo)memberInfo).GetValue(obj);

                if (fieldValue is Method)
                {
                    fieldValue = new ObjectMethodBinding(obj,
                                                         (Method)fieldValue);
                }

                return(fieldValue);
            }
            else
            {
                throw new Exception("can't get "
                                    + TypeNames.GetName(memberInfo.GetType()));
            }
        }
示例#4
0
 public override string ToString()
 {
     if (min == max)
     {
         return(TextEscape.Quote(min));
     }
     else
     {
         return(TextEscape.Quote(min) + ".." + TextEscape.Quote(max));
     }
 }
示例#5
0
        public RuntimeObject Parse(Lexer lexer, RuntimeState runtimeState)
        {
            runtimeState.Runtime.ParseTrace.Enter(this, null, lexer.FileName);

            while (true)
            {
                ParserState state = new ParserState(runtimeState);

                ParseTree tree;

                if (runtimeState.Runtime.CompileParser)
                {
                    tree = RootPattern.ParseUsingCompiler(lexer, state);
                }
                else
                {
                    tree = RootPattern.Parse(lexer, state);
                }

                RuntimeObject obj = (RuntimeObject)tree.Value;

                if (!lexer.Finished)
                {
                    string got;

                    if (lexer.MaxPosition < lexer.Text.Length)
                    {
                        got = TextEscape.Quote(lexer.Text[lexer.MaxPosition]);
                    }
                    else
                    {
                        got = "end of source code";
                    }

                    throw new ParseException(
                              lexer.SourceAt(lexer.MaxPosition),
                              lexer.ErrorStrings[lexer.MaxPosition],
                              got);
                }

                runtimeState.Runtime.ParseTrace.Parsed(lexer.FileName, obj);

                if (lexer.ChangingRoots)
                {
                    lexer.Restart();
                    continue;
                }

                runtimeState.Runtime.ParseTrace.Yes(this, null);

                return(obj);
            }
        }
示例#6
0
 public override string ToString()
 {
     if (parameter == null)
     {
         return("    " + op.ToString());
     }
     else if (parameter is string)
     {
         return("    " + op + " " + TextEscape.Quote((string)parameter));
     }
     else if (parameter is Type)
     {
         return("    " + op + " " + TypeNames.GetName((Type)parameter));
     }
     else if (parameter is FieldInfo)
     {
         FieldInfo field = (FieldInfo)parameter;
         return("    " + op + " " + TypeNames.GetName(field.DeclaringType) + "::" + field.Name);
     }
     else if (parameter is MethodInfo)
     {
         MethodInfo method = (MethodInfo)parameter;
         return("    " + op + " " + TypeNames.GetName(method.DeclaringType) + "::" + method.Name);
     }
     else if (parameter is ConstructorInfo)
     {
         ConstructorInfo constructor = (ConstructorInfo)parameter;
         return("    " + op + " " + TypeNames.GetName(constructor.DeclaringType));
     }
     else if (parameter is BlockLocal)
     {
         return("    " + op + " " + TypeNames.GetName(((BlockLocal)parameter).Type));
     }
     else
     {
         return("    " + op + " " + parameter);
     }
 }
示例#7
0
        public override Block CompileNewState(Runtime runtime,
                                              StateForCompiler state)
        {
            ParserBlock block = new ParserBlock(runtime);

            block.Comment("start of text --------------------");

            block.Enter(this, TextEscape.Quote(text));

            block.BeginScope();

            block.Whitespace(runtime, state);
            BlockLocal start = block.SavePosition();

            BlockLocal n = new BlockLocal(typeof(int));

            block.DeclareLocal(n);

            BlockLabel reitterate = new BlockLabel("reitterate");

            block.MarkLabel(reitterate);

            block.Comment("itteration");

            BlockLocal character = new BlockLocal(typeof(char));

            block.DeclareLocal(character);

            block.LoadLexer();
            block.LoadLocal(n);
            block.Call(typeof(Lexer).GetMethod("Peek",
                                               new Type[] { typeof(int) }));

            block.Dup();
            block.StoreLocal(character);

            block.Load(text);
            block.LoadLocal(n);
            block.GetProperty(typeof(string).GetProperty("Chars"));

            BlockLabel matched = new BlockLabel("matched");

            block.BranchIfEqual(matched);

            block.Comment("handle the failure");

            // todo error string

            // todo specifics
            block.No(this, start);

            block.LoadNo();

            BlockLabel returnLabel = new BlockLabel("return");

            block.Branch(returnLabel);

            block.MarkLabel(matched);

            block.Comment("increment and check the loop variable");

            block.LoadLocal(n);
            block.Increment();
            block.Dup();

            block.StoreLocal(n);

            block.Load(text.Length);
            block.BranchIfLess(reitterate);

            block.Comment("skip over the text");

            block.LoadLexer();
            block.Load(text.Length);
            block.Call(typeof(Lexer).GetMethod("Skip"));

            // todo specifics
            block.Yes(this, start);

            block.Comment("create the parse tree");

            if (state.BuildTextNodes)
            {
                block.Load(text);
                block.New(typeof(ParseTree).GetConstructor(
                              new Type[] { typeof(object) }));
            }
            else
            {
                block.LoadYes();
            }

            block.EndScope();

            block.MarkLabel(returnLabel);

            block.Comment("end of text --------------------");

            return(block);
        }
示例#8
0
        public override ParseTree Parse(Lexer lexer, ParserState state)
        {
            lexer.Whitespace(state.RuntimeState);

            int start = lexer.Position;

            state.RuntimeState.Runtime.ParseTrace.Enter(
                this,
                lexer.CurrentSource(),
                TextEscape.Quote(text));

            for (int n = 0; n < text.Length; n++)
            {
                char character = lexer.Peek(n);

                if (character != text[n])
                {
                    string stoppedString;

                    if (character == '\0')
                    {
                        stoppedString = "end";
                    }
                    else
                    {
                        stoppedString = TextEscape.Quote(character);
                    }

                    lexer.ErrorStrings[start + n].Add(TextEscape.Quote(text));

                    if (n > 0)
                    {
                        state.RuntimeState.Runtime.ParseTrace.No(
                            this,
                            lexer.SourceFrom(start),
                            TextEscape.Quote(lexer.Text.Substring(start, n))
                            + "..." + stoppedString);
                    }
                    else
                    {
                        state.RuntimeState.Runtime.ParseTrace.No(
                            this,
                            lexer.SourceFrom(start),
                            stoppedString);
                    }

                    return(ParseTree.No);
                }
            }

            lexer.Skip(text.Length);

            state.RuntimeState.Runtime.ParseTrace.Yes(this,
                                                      lexer.SourceFrom(start));

            if (state.BuildTextNodes)
            {
                return(new ParseTree(text));
            }
            else
            {
                return(ParseTree.Yes);
            }
        }
示例#9
0
 public ObjectViewHeader GetHeader(object obj)
 {
     return(new ObjectViewHeader(TextEscape.Quote((string)obj), false, false));
 }
示例#10
0
 private void AddNode(TreeIter parent, TextNode textNode)
 {
     store.AppendValues(parent, TextEscape.Quote(textNode.Text), textNode);
 }
示例#11
0
 private void Add(TreeIter parent, string prefix, string node)
 {
     store.AppendValues(parent, prefix + TextEscape.Quote(node), GtkProofBox.Box(node));
 }