예제 #1
0
        private Expression Primary(INode node)
        {
            switch (node.Name)
            {
            case "identifier":
                return(NameExpression.From(node, Identifier(node)));

            case "singleString":
            case "doubleString":
                return(StringLiteral(node));

            case ".":
                return(AnyExpression.From(node));

            case "choice":
                return(Expression(node));

            case "class":
                return(Class(node));

            case "ε":
                return(EpsilonExpression.From(node));

            case "inline":
                return(InlineExpression.From(node, Rule(node[0])));

            default:
                throw new NotImplementedException();
            }
        }
예제 #2
0
        public ChangeTimeView()
        {
            InitializeComponent();

            ChangeTimeViewModel vm = (ChangeTimeViewModel)DataContext;

            vm.PropertyChanged += (_, args) => {
                if (args.PropertyName == nameof(vm.Title))
                {
                    InlineExpression.SetInlineExpression(TitleBlock, vm.Title);
                }
            };
            Loaded += (_, _) => {
                // Window Setup
                _window = Window.GetWindow(this);
                Debug.Assert(_window != null, nameof(_window) + " != null");
                _window.Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0));

                (double dpiWidthFactor, double dpiHeightFactor) = WindowHelpers.GetDpiFactors(_window);
                _window.CenterOnScreen(dpiWidthFactor, dpiHeightFactor);
            };

            MouseDown += (_, e) => {
                if (e.ChangedButton == MouseButton.Left)
                {
                    DependencyObject scope = FocusManager.GetFocusScope(Root);
                    FocusManager.SetFocusedElement(scope, _window);
                    _window.DragMove();
                }
            };
        }
예제 #3
0
            protected override void VisitInlineExpression(InlineExpression expression)
            {
                var rule = Grammar.Attr.Rules[expression.Rule.Identifier.Name];

                if (rule.Attr.SetIsReachable(true))
                {
                    VisitExpression(rule.Expression);
                }
            }
예제 #4
0
        /// <summary>
        /// Construeix la funcio de transicio.
        /// </summary>
        /// <param name="state">El estat.</param>
        /// <param name="transitionName">El nom de la transicio.</param>
        /// <returns>La funcio.</returns>
        ///
        private FunctionDeclaration MakeOnTransitionFunction(State state, string transitionName, string contextClassName, string ownerClassName)
        {
            StatementList bodyStatements = new StatementList();

            // Intruccio per recuperar el context.
            //
            bodyStatements.Add(
                new InlineStatement(
                    String.Format("{0}* ctx = static_cast<{0}*>(getContext())", contextClassName)));
            bodyStatements.Add(
                new InlineStatement(
                    String.Format("{0}* owner = ctx->getOwner()", ownerClassName)));

            foreach (Transition transition in state.Transitions)
            {
                if (transition.TransitionEvent.Name == transitionName)
                {
                    StatementList trueBodyStatements = new StatementList();

                    trueBodyStatements.Add(new InvokeStatement(
                                               new InvokeExpression(
                                                   new IdentifierExpression("ctx->beginTransition"))));

                    // Accio de transicio.
                    //
                    if (transition.Action != null)
                    {
                        trueBodyStatements.AddRange(MakeActionStatements(transition.Action));
                    }

                    trueBodyStatements.Add(new InvokeStatement(
                                               new InvokeExpression(
                                                   new IdentifierExpression("ctx->endTransition"),
                                                   new InvokeExpression(
                                                       new IdentifierExpression("ctx->getStateInstance"),
                                                       new IdentifierExpression(
                                                           String.Format("Context::StateID::{0}", transition.NextState.Name))))));

                    Expression conditionExpr = new InlineExpression(transition.Guard == null ? "true" : transition.Guard.Expression);
                    bodyStatements.Add(new IfThenElseStatement(
                                           conditionExpr,
                                           new BlockStatement {
                        Statements = trueBodyStatements
                    },
                                           null));
                }
            }

            return(new FunctionDeclaration {
                Access = AccessSpecifier.Public,
                Implementation = ImplementationSpecifier.Override,
                ReturnType = TypeIdentifier.FromName("void"),
                Name = String.Format("transition_{0}", transitionName),
                Body = new BlockStatement(bodyStatements),
            });
        }
예제 #5
0
            protected override void VisitInlineExpression(InlineExpression expression)
            {
                var rule = expression.InlineRule;

                Writer.WriteLine($"({rule.Identifier} {OpSymbols.DefPlain}");
                Writer.Indent(() =>
                {
                    VisitExpression(rule.Expression);
                    Writer.Write(")");
                });
            }
예제 #6
0
        public AboutControl(MainWindow mainWindow)
        {
            InitializeComponent();

            AboutBox.Text = mainWindow.AssemblyInfo.Description;

            AboutArea.Header       = LanguageLibrary.Language.Default.group_about_area;
            AuthorsGroupBox.Header = LanguageLibrary.Language.Default.group_authors_area;

            var authors = Properties.Resources.Authors;

            var sp = new StackPanel {
                Orientation = Orientation.Vertical
            };

            using (var reader = new StringReader(authors))
            {
                var line = string.Empty;
                do
                {
                    line = reader.ReadLine();
                    if (line != null)
                    {
                        var tb = new TextBlock
                        {
                            Text    = line,
                            Padding = new Thickness(5)
                        };

                        var l = line.Split('|');

                        if (l.Length > 0)
                        {
                            var inlineExpression =
                                string.Format(
                                    "<bold>{0}</bold> | <hyperlink NavigateUri='{1}' Click='Url_Click'>{1}</hyperlink>",
                                    l[0], l[1]);
                            InlineExpression.SetInlineExpression(tb, inlineExpression);
                        }

                        sp.Children.Add(tb);
                    }
                } while (line != null);
            }

            AuthorsGroupBox.Content = sp;
        }
예제 #7
0
            protected override void VisitInlineExpression(InlineExpression expression)
            {
                var parent = this.parents.Peek();
                var rule   = Rule.From(parent.Identifier.With(expression.InlineRule.Identifier), expression.InlineRule.Expression);

                Check.TryAdd(rule);
                rule.Attr.SetIsLexical(parent.Attr.IsLexical);
                rule.Attr.SetIsInline(true);
                if (rule.Attr.IsLexical)
                {
                    Grammar.LexicalRules.Add(rule);
                }
                else
                {
                    Grammar.SyntaxRules.Add(rule);
                }
                expression.Rule = rule;
                Visit(rule);
            }
예제 #8
0
            private static Expression Expression(INode node)
            {
                switch (node.Name)
                {
                case "sequence": return(Sequence(node));

                case "choice": return(Choice(node));

                case "prefix.drop": return(DropExpression.From(node[0], Expression(node[0])));

                case "prefix.lift": return(LiftExpression.From(node[0], Expression(node[0])));

                case "prefix.fuse": return(FuseExpression.From(node[0], Expression(node[0])));

                case "prefix.not": return(NotExpression.From(node[0], Expression(node[0])));

                case "suffix.zero-or-more": return(StarExpression.From(node[0], Expression(node[0])));

                case "suffix.one-or-more": return(PlusExpression.From(node[0], Expression(node[0])));

                case "suffix.zero-or-one": return(OptionalExpression.From(node[0], Expression(node[0])));

                case "inline": return(InlineExpression.From(node[0], Tree.Rule.From(Identifier(node[0]), Expression(node[1]))));

                case "identifier": return(NameExpression.From(node, Identifier(node)));

                case "any": return(AnyExpression.From(node));

                case "verbatim-string": return(StringLiteralExpression.From(node, ((ILeaf)node).Value));

                case "character-class": return(Class(node));

                case "string": return(String(node));

                default:
                    throw new NotImplementedException();
                }
            }
예제 #9
0
 protected override void VisitInlineExpression(InlineExpression expression)
 {
     Grammar.Attr.Rules[expression.Rule.Identifier.Name].Attr.SetIsUsed(true);
 }
예제 #10
0
 public virtual void Visit(InlineExpression exp)
 {
 }
예제 #11
0
 public override void Visit(InlineExpression exp)
 {
     cb.Write(exp.Code);
 }
예제 #12
0
 protected override void VisitInlineExpression(InlineExpression expression)
 {
     CS.IndentInOut(
         "InlineExpression",
         () => CS.Ln($"{Locals.Result} = {Cfg.CU(expression.Rule.Identifier)}({Cfg.CurName});"));
 }
예제 #13
0
 protected override void VisitInlineExpression(InlineExpression expression)
 {
     Push(new Name(() => (Parsers.ICombiParser)Grammar.Attr.Rules[expression.Rule.Identifier.Name].Attr.Parser, expression.Rule.Identifier));
 }
예제 #14
0
        /// <summary>
        /// Sets the body text block.
        /// </summary>
        private void SetBodyTextBlock()
        {
            string body = Article.Article.Body;

            List <bool> whoMatched   = new List <bool>();
            List <bool> whenMatched  = new List <bool>();
            List <bool> whereMatched = new List <bool>();
            bool        whatMatched  = false;
            bool        whyMatched   = false;

            List <string> whoAnnotations   = new List <string>();
            List <string> whenAnnotations  = new List <string>();
            List <string> whereAnnotations = new List <string>();

            List <BodySegment> listBodySegments = new List <BodySegment>();

            // Match annotations to body

            foreach (string who in Article.Annotation.Who.Split(';'))
            {
                if (!string.IsNullOrEmpty(who))
                {
                    bool isFound = body.Contains(who);

                    if (isFound)
                    {
                        whoMatched.Add(true);
                        whoAnnotations.Add(who);

                        int index = body.IndexOf(who);

                        listBodySegments.Add(new BodySegment()
                        {
                            StartIndex = index,
                            EndIndex   = index + who.Length,
                            Label      = "WHO"
                        });
                    }
                    else
                    {
                        whoMatched.Add(false);

                        //Console.WriteLine("\"{0}\" was not found in the article.", who);
                    }
                }
                else
                {
                    break;
                }
            }

            foreach (string when in Article.Annotation.When.Split(';'))
            {
                if (!string.IsNullOrEmpty(when))
                {
                    bool isFound = body.Contains(when);

                    if (isFound)
                    {
                        whenMatched.Add(true);
                        whenAnnotations.Add(when);

                        int index = body.IndexOf(when);

                        listBodySegments.Add(new BodySegment()
                        {
                            StartIndex = index,
                            EndIndex   = index + when.Length,
                            Label      = "WHEN"
                        });
                    }
                    else
                    {
                        whenMatched.Add(false);

                        //Console.WriteLine("\"{0}\" was not found in the article.", when);
                    }
                }
                else
                {
                    break;
                }
            }

            foreach (string where in Article.Annotation.Where.Split(';'))
            {
                if (!string.IsNullOrEmpty(where))
                {
                    bool isFound = body.Contains(where);

                    if (isFound)
                    {
                        whereMatched.Add(true);
                        whereAnnotations.Add(where);

                        int index = body.IndexOf(where);

                        listBodySegments.Add(new BodySegment()
                        {
                            StartIndex = index,
                            EndIndex   = index + where.Length,
                            Label      = "WHERE"
                        });
                    }
                    else
                    {
                        whereMatched.Add(false);

                        //Console.WriteLine("\"{0}\" was not found in the article.", where);
                    }
                }
                else
                {
                    break;
                }
            }

            if (!string.IsNullOrEmpty(Article.Annotation.What))
            {
                string what = Article.Annotation.What;

                what = what.Replace("`` ", "\"");
                what = what.Replace(" ''", "\"");

                whatMatched = body.Contains(what);

                if (whatMatched)
                {
                    int index = body.IndexOf(what);

                    listBodySegments.Add(new BodySegment()
                    {
                        StartIndex = index,
                        EndIndex   = index + what.Length,
                        Label      = "WHAT"
                    });
                }
                else
                {
                    //Console.WriteLine("\"{0}\" was not found in the article.", what);
                }
            }

            if (!string.IsNullOrEmpty(Article.Annotation.Why))
            {
                whyMatched = body.Contains(Article.Annotation.Why);

                if (whyMatched)
                {
                    int index = body.IndexOf(Article.Annotation.Why);

                    listBodySegments.Add(new BodySegment()
                    {
                        StartIndex = index,
                        EndIndex   = index + Article.Annotation.Why.Length,
                        Label      = "WHY"
                    });
                }
                else
                {
                    //Console.WriteLine("\"{0}\" was not found in the article.", Article.Annotation.Why);
                }
            }

            // Check for overlapping ranges

            for (int i = 0; i < listBodySegments.Count; i++)
            {
                for (int j = i + 1; j < listBodySegments.Count; j++)
                {
                    if (listBodySegments[i].Intersects(listBodySegments[j]))
                    {
                        //Console.WriteLine("\"{0}\":{1} intersects with \"{2}\":{3}",
                        //    body.Substring(listBodySegments[i].StartIndex, listBodySegments[i].EndIndex),
                        //    listBodySegments[i].Label,
                        //    body.Substring(listBodySegments[j].StartIndex, listBodySegments[j].EndIndex),
                        //    listBodySegments[j].Label);
                    }
                }
            }

            listBodySegments = listBodySegments.OrderByDescending(s => s.EndIndex).ToList();

            // Set the body text block

            foreach (BodySegment segment in listBodySegments)
            {
                //body = body.Insert(segment.EndIndex, "</bold>");
                //body = body.Insert(segment.StartIndex, "<bold>");
            }

            InlineExpression.SetInlineExpression(BodyTextBlock, body);

            //Console.WriteLine("Who: {0} | When: {1} | Where: {2} | What: {3} | Why: {4}",
            //    whoAnnotations.Count > 0 ? whoMatched.Count(x => x == true) / whoAnnotations.Count : -1,
            //    whenAnnotations.Count > 0 ? whenMatched.Count(x => x == true) / whenAnnotations.Count : -1,
            //    whereAnnotations.Count > 0 ? whereMatched.Count(x => x == true) / whereAnnotations.Count : -1,
            //    whatMatched ? 1 : -1,
            //    whyMatched ? 1 : -1);
        }
예제 #15
0
 public override void Visit(InlineExpression obj)
 {
     cb.Write(obj.Code);
 }