Exemple #1
0
        public void HandleMouseDown(MouseEvtWithElement me)
        {
            this.lastMe = Maybe.Just(me);

            this.addMessage("classic dragging " + me.Element.Name);
            this.dragInfo.Set(new DragInfo(me, Canvas.GetLeft(me.Element.Polygon).ZeroIfNaN(), Canvas.GetTop(me.Element.Polygon).ZeroIfNaN()));
        }
Exemple #2
0
 public static IMaybe <TResult> Select <T, TResult>(
     this IMaybe <T> source,
     Func <T, TResult> selector)
 => source.Match <IMaybe <TResult> >(
     nothing: new Nothing <TResult>(),
     just: x => new Just <TResult>(selector(x)));
Exemple #3
0
        public void Test_Imay_Sem_Valo()
        {
            IMaybe <Car> mayCar = Maybe <Car> .None;

            Assert.IsTrue(!mayCar.HasValue);
        }
Exemple #4
0
 public Lazy(IInvokable invokable)
 {
     this.invokable = invokable;
     _value         = none <IObject>();
 }
        public void Squash_WithNoValueInnerIMaybe_ReturnsNoValue()
        {
            IMaybe <IMaybe <int> > value = Maybe.Return <IMaybe <int> >(Maybe <int> .NoValue);

            Assert.IsTrue(Maybe <int> .NoValue == value.Squash());
        }
Exemple #6
0
            public override Value Next()
            {
                if (_currentGenerator.If(out var currentGenerator))
                {
                    var returnValue = currentGenerator.Next();
                    if (!returnValue.IsNil)
                    {
                        if (returnValue is INSGenerator returnGenerator)
                        {
                            returnGenerator.Region = Region;
                        }

                        return(returnValue);
                    }

                    _currentGenerator = none <INSGenerator>();
                }

                Value value;

                for (var i = index; i < block.builder.Verbs.Count; i++)
                {
                    var verb = block.builder.Verbs[i];
                    if (verb.Yielding)
                    {
                        var _generator = verb.PossibleGenerator();
                        if (_generator.If(out var generator))
                        {
                            var _evaluated = evaluateGenerator(generator, i);
                            if (_evaluated.If(out var evaluated))
                            {
                                return(evaluated);
                            }

                            continue;
                        }
                    }

                    if (State.ExitSignal || State.SkipSignal)
                    {
                        break;
                    }

                    if (verb.Precedence == VerbPrecedenceType.Statement)
                    {
                        State.Stack.Clear();
                    }

                    if (evaluateVerb(verb))
                    {
                        continue;
                    }

                    if (!State.ReturnSignal)
                    {
                        continue;
                    }

                    if (block.ResetReturnSignal)
                    {
                        State.ReturnSignal = false;
                    }

                    value = State.ReturnValue.Resolve();
                    if (value.PossibleIndexGenerator().If(out var generator1) && evaluateGenerator(generator1, i).If(out var evaluatedValue))
                    {
                        return(evaluatedValue);
                    }

                    index = i + 1;
                    return(block.evaluateReturn(value));
                }

                if (State.Stack.IsEmpty)
                {
                    return(NilValue);
                }

                value = State.Stack.Pop(block.ResolveVariables, LOCATION).ArgumentValue();
                return(value.PossibleIndexGenerator().Map(g => evaluateGenerator(g, index)).DefaultTo(() => block.evaluateReturn(value)));
            }
Exemple #7
0
 public Ss(char a, char b, IMaybe<Stream<char>> sw)
 {
     this.A = a;
     this.B = b;
     this.Sw = sw;
 }
Exemple #8
0
        protected void Playground_Load(object sender, EventArgs e)
        {
            try
            {
                var result =
                    from file in existingConfigurationFile()
                    from config in getConfiguration(file)
                    select config;
                if (result.If(out playgroundConfiguration))
                {
                }
                else
                {
                    playgroundConfiguration = new PlaygroundConfiguration
                    {
                        DefaultFolder = FolderName.Current,
                        FontName      = PLAYGROUND_FONT_NAME,
                        FontSize      = PLAYGROUND_FONT_SIZE,
                        PackageFolder = "C" + PLAYGROUND_PACKAGE_FOLDER
                    };
                }
            }
            catch (Exception exception)
            {
                labelStatus.Text = exception.Message;
            }

            packageFolder = playgroundConfiguration.PackageFolder;

            outputConsole = new TextBoxConsole(this, textConsole, playgroundConfiguration.FontName, playgroundConfiguration.FontSize,
                                               TextBoxConsole.ConsoleColorType.Quick);
            textWriter = outputConsole.Writer();
            textReader = outputConsole.Reader();
            context    = new PlaygroundContext(textWriter, textReader);
            colorizer  = new Colorizer(textEditor);

            try
            {
                _exceptionData = none <ExceptionData>();
                document       = new Document(this, textEditor, ".kagami", "Kagami", playgroundConfiguration.FontName, playgroundConfiguration.FontSize);
                var menus = document.Menus;
                menus.Menu("&File");
                menus.Menu("File", "&New", (_, _) =>
                {
                    textEditor.ClearModificationGlyphs();
                    document.New();
                });
                menus.Menu("File", "&Open", (_, _) =>
                {
                    textEditor.ClearModificationGlyphs();
                    document.Open();
                }, "^O");
                menus.Menu("File", "&Save", (_, _) =>
                {
                    textEditor.SetToSavedGlyphs();
                    document.Save();
                }, "^S");
                menus.Menu("File", "Save As", (_, _) =>
                {
                    textEditor.SetToSavedGlyphs();
                    document.SaveAs();
                });
                menus.Menu("File", "Exit", (_, _) => Close(), "%F4");

                document.StandardEditMenu();

                menus.Menu("Edit", "Duplicate", (_, _) => duplicate(), "^D");
                menus.Menu("Edit", "Indent", (_, _) => indent(), "^I");
                menus.Menu("Edit", "Unindent", (_, _) => unindent(), "^%I");
                menus.Menu("&Build");
                menus.Menu("Build", "Run", (_, _) => run(), "F5");
                menus.Menu("Build", "Manual", (s, _) =>
                {
                    manual = !manual;
                    ((ToolStripMenuItem)s).Checked = manual;
                }, "^F5");
                menus.Menu("Build", "Dump operations", (s, _) =>
                {
                    dumpOperations = !dumpOperations;
                    ((ToolStripMenuItem)s).Checked = dumpOperations;
                });
                menus.Menu("Build", "Trace", (s, _) =>
                {
                    tracing = !tracing;
                    ((ToolStripMenuItem)s).Checked = tracing;
                }, "^T");
                menus.Menu("&Insert");
                menus.Menu("Insert", "open sys", (_, _) => insertText("open sys\n\n", 0, 0), "^%S");
                menus.Menu("Insert", "open math", (_, _) => insertText("open math\n\n", 0, 0), "^%M");
                menus.Menu("Insert", "println()", (_, _) => insertText("println()", -1, 0), "^P");
                menus.Menu("Insert", "println() interpolated", (_, _) => insertText("println($\"\")", -2, 0), "^%P");
                menus.Menu("Insert", "print()", (_, _) => insertText("print()", -1, 0));
                menus.Menu("Insert", "put()", (_, _) => insertText("put()", -1, 0));
                menus.Menu("Insert", "peek()", (_, _) => surround("peek(", ")"), "^K");
                menus.Menu("Insert", "Triple quotes", (_, _) => insertText("\"\"\"\n\"\"\"", -3), "^Q");
                menus.Menu("Insert", "List", (_, _) => insertText("⌈⌉", -1), "^L");
                menus.Menu("Insert", "Set", (_, _) => insertText("⎩⎭", -1), "^E");

                menus.Menu("&Debug");
                menus.Menu("Debug", "Step Into", (_, _) => stepInto(), "F11");
                menus.Menu("Debug", "Step Over", (_, _) => stepOver(), "F10");

                menus.CreateMainMenu(this);
                menus.StandardContextEdit(document);

                textEditor.SetTabs(32, 64, 96, 128);
                textEditor.SetLeftMargin(70);
                textEditor.ReassignHandle();
                textEditor.Paint         += (_, evt) => paint(evt);
                textEditor.AnnotationFont = new Font(textEditor.Font, FontStyle.Bold);

                locked          = false;
                manual          = false;
                dumpOperations  = false;
                tracing         = false;
                stopwatch       = new Stopwatch();
                _exceptionIndex = none <int>();
                cancelled       = false;
                if (playgroundConfiguration.LastFile != null)
                {
                    document.Open(playgroundConfiguration.LastFile);
                }
            }
            catch (Exception exception)
            {
                textWriter.WriteLine(exception.Message);
            }
        }
Exemple #9
0
 public ReturnSignal(Generator generator)
 {
     expression = generator.Pushed.Some();
     typeName   = "";
 }
Exemple #10
0
 public ReturnSignal(Block expression)
 {
     this.expression = expression.Some();
     typeName        = "";
 }
Exemple #11
0
 public ReturnSignal()
 {
     expression = none <Block>();
     typeName   = "";
 }
Exemple #12
0
 /// <summary>
 ///     Check whether a maybe outcome has been decided
 /// </summary>
 /// <param name="maybe">
 ///     The result of the date validation that the check will
 ///  be performed against.
 /// </param>
 /// <returns>
 ///     True if the maybe is not null
 /// </returns>
 public static bool has_been_decided <T>
     (this IMaybe <T> maybe)
 {
     return(maybe != null);
 }
 public static U Case <T, U>(this IMaybe <T> maybe, Func <T, U> some, Func <U> none)
 {
     return(maybe.HasValue
         ? some(maybe.Value)
         : none());
 }
Exemple #14
0
 public override void Reset() => current = start.Some();
Exemple #15
0
 /// <exclude/>
 public IMaybe <T> Or(IMaybe <T> maybe) => maybe;
Exemple #16
0
 public AssignToNewField(bool mutable, string fieldName, Expression expression, IMaybe <TypeConstraint> typeConstraint)
 {
     this.mutable        = mutable;
     this.fieldName      = fieldName;
     this.expression     = expression;
     this.typeConstraint = typeConstraint;
 }
Exemple #17
0
 /// <exclude/>
 public IMaybe <U> And <U>(IMaybe <U> andMaybe) => new Nothing <U>();
Exemple #18
0
 public static MaybeAssertions <T> Should <T>(this IMaybe <T> maybe)
 {
     return(new MaybeAssertions <T>(maybe));
 }
Exemple #19
0
 public Sc(IMaybe<char> a, IMaybe<char> b, IMaybe<Cell<char>> sw)
 {
     this.A = a;
     this.B = b;
     this.Sw = sw;
 }
Exemple #20
0
 public MaybeAssertions(IMaybe <T> maybe) : base(maybe)
 {
     Subject = maybe;
 }
Exemple #21
0
 public ColumnDataType(ColumnName.Base name, DataType dataType, IMaybe <TSqlFragment> definingLocation)
 {
     _name     = name;
     _dataType = dataType;
     _definingLocationMaybe = definingLocation;
 }
Exemple #22
0
 public static IoEitherMaybe <TLeft, TRight> ToIoEitherMaybe <TLeft, TRight>(this IMaybe <TRight> m)
 {
     return(new IoEitherMaybe <TLeft, TRight>(m));
 }
        public void Squash_WithNoValueOuterIMaybe_ReturnsNoValue()
        {
            IMaybe <IMaybe <int> > value = Maybe <IMaybe <int> > .NoValue;

            Assert.IsTrue(Maybe <int> .NoValue == value.Squash());
        }
Exemple #24
0
 public Sc(IMaybe <char> a, IMaybe <char> b, IMaybe <DiscreteCell <char> > sw)
 {
     this.A  = a;
     this.B  = b;
     this.Sw = sw;
 }
        public void OfType_WithNullIMaybe_ReturnsNoValue()
        {
            IMaybe value = null;

            Assert.IsTrue(Maybe <object> .NoValue == value.OfType <object>());
        }
Exemple #26
0
 public Ss(char a, char b, IMaybe <Stream <char> > sw)
 {
     this.A  = a;
     this.B  = b;
     this.Sw = sw;
 }
Exemple #27
0
        public void Test_Imay_not_null()
        {
            IMaybe <Car> mayCar = Maybe <Car> .None;

            Assert.IsNotNull(mayCar);
        }
Exemple #28
0
 public static IMaybe <T> Some <T>(IMaybe <T> value) => value;
Exemple #29
0
 public static IChurchBoolean IsJust <T>(this IMaybe <T> m)
 => m.Match <IChurchBoolean>(
     nothing: new ChurchFalse(),
     just: _ => new ChurchTrue());
Exemple #30
0
        protected void update(bool execute, bool fromMenu)
        {
            if (!locked && textEditor.TextLength != 0)
            {
                locked = true;
                if (manual)
                {
                    labelStatus.Text = "running...";
                    Application.DoEvents();
                }
                else if (fromMenu)
                {
                    document.Save();
                }

                try
                {
                    textConsole.Clear();
                    context.ClearPeeks();
                    stopwatch.Reset();
                    stopwatch.Start();
                    _exceptionIndex = none <int>();
                    _exceptionData  = none <ExceptionData>();

                    var kagamiConfiguration = new CompilerConfiguration {
                        ShowOperations = dumpOperations, Tracing = tracing
                    };
                    var compiler = new Compiler(textEditor.Text, kagamiConfiguration, context);
                    if (compiler.Generate().If(out var machine, out var exception))
                    {
                        machine.PackageFolder = packageFolder.FullPath;
                        if (execute)
                        {
                            if (machine.Execute().IfNot(out exception))
                            {
                                textWriter.WriteLine(KAGAMI_EXCEPTION_PROMPT + exception.Message);
                                _exceptionIndex = compiler.ExceptionIndex;
                                if (_exceptionIndex.IsNone)
                                {
                                    _exceptionIndex = textEditor.SelectionStart.Some();
                                }
                            }
                            else
                            {
                                cancelled = context.Cancelled();
                                context.Reset();
                            }
                        }

                        stopwatch.Stop();
                        var state = textEditor.StopAutoScrollingAlways();
                        try
                        {
                            colorizer.Colorize(compiler.Tokens);
                        }
                        finally
                        {
                            textEditor.ResumeAutoScrollingAlways(state);
                        }

                        if (_exceptionIndex.If(out var index))
                        {
                            var remainingLineLength = getRemainingLineIndex(index);
                            if (remainingLineLength > -1)
                            {
                                showException(index, remainingLineLength);
                            }
                        }

                        if (dumpOperations && compiler.Operations.If(out var operations))
                        {
                            textWriter.WriteLine(operations);
                        }

                        document.Clean();

                        labelStatus.Text = stopwatch.Elapsed.ToLongString(true) + (cancelled ? " (cancelled)" : "");
                    }
                    else
                    {
                        textWriter.WriteLine(KAGAMI_EXCEPTION_PROMPT + exception.Message);
                        _exceptionIndex = compiler.ExceptionIndex;
                        if (_exceptionIndex.IsNone)
                        {
                            _exceptionIndex = textEditor.SelectionStart.Some();
                        }

                        if (_exceptionIndex.If(out var index))
                        {
                            var remainingLineLength = getRemainingLineIndex(index);
                            if (remainingLineLength > -1)
                            {
                                showException(index, remainingLineLength);
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                    textWriter.WriteLine(KAGAMI_EXCEPTION_PROMPT + exception.Message);
                }
                finally
                {
                    locked = false;
                }
            }
        }
Exemple #31
0
 public static IMaybe <TResult> Map <T, TResult>(
     this IMaybe <T> source,
     Func <T, TResult> selector)
 => source.Select(selector);
Exemple #32
0
 protected void showException(int index, int length)
 {
     _exceptionData = new ExceptionData(index, length).Some();
     textEditor.Invalidate();
 }
Exemple #33
0
 public void HandleMouseMove(MouseEvt me)
 {
     this.lastMe = Maybe.Just(me);
     this.Reposition();
 }
Exemple #34
0
 public static IMaybe <B> Select <A, B>(this IMaybe <A> a, Func <A, IMaybe <B> > func)
 {
     return(a.Bind(func));
 }