Example #1
0
        static void Main(string[] args)
        {
            //Program program = new Program();
            //program.GameTest();

            Config config = new Config();

            Scheme parentScheme = new Scheme("ParentScheme");

            config.AddScheme(parentScheme);

            Scheme scheme = new Scheme("MyScheme");

            scheme.Code = File.ReadAllText("language/examples/scheme_example1.txt");

            SchemeLang.Compile(scheme, config);

            string code = scheme.CompiledScheme.GetFullCode();

            SchemeLangOptimizer.Optimize(scheme.CompiledScheme.GetFunctionByName("DoStuff"));

            string optimizedCode = scheme.CompiledScheme.GetFullCode();

            //File.WriteAllText("output.txt", code);

            Console.WriteLine(code);
            Console.Write(optimizedCode);
            Console.ReadKey();
        }
Example #2
0
        public void Compile(Config config)
        {
            // compile self
            if (Code != null && Code != "")
            {
                SchemeLang.Compile(this, config);
            }

            IsCompiledValid = true;

            // compile parents
            foreach (var parent in Parents)
            {
                parent.Compile(config);
            }
        }
Example #3
0
        //Return true if generation is successfull
        public bool GenerateDataFromCode(bool optimize = true)
        {
            RemoveAllErrorHighlight();

            var item = ((ListBoxItem)list.SelectedItem);

            if (item == null)
            {
                return(false);
            }

            Scheme scheme = (Scheme)item.Tag;

            scheme.Code = tbCode.Text;

            if (scheme.Code == null || scheme.Code == "")
            {
                return(true);
            }

            var errors = SchemeLang.CompileWithErrors(scheme, Project.Current.Config);

            item.Content = (scheme?.Name == null ? "<unknown>" : scheme.Name);

            if (errors.Count > 0)
            {
                HighlightErrors(errors);
                return(false);
            }

            if (optimize)
            {
                SchemeLangOptimizer.Optimize(scheme);
            }

            //var visitor = new Classlist_langVisitor();
            //visitor.Visit(tree);

            //Config.ClassLists = visitor.ClassLists;

            return(true);
        }
Example #4
0
        private void ValidateSchemes(List <EditorErrorDescriptor> eeds)
        {
            List <string> collisions = new List <string>();

            foreach (Scheme scheme in Schemes)
            {
                if (scheme.Name == null || scheme.Name.Length == 0)
                {
                    eeds.Add(new InvalidSchemeEED(scheme));
                    continue;
                }

                if (!collisions.Contains(scheme.Name))
                {
                    var schemeNameCollisionEED = new SchemeNameCollisionEED(scheme);
                    Schemes.ForEach(s =>
                    {
                        if (s != scheme && s.Name == scheme.Name)
                        {
                            schemeNameCollisionEED.AddScheme(s);
                        }
                    });

                    if (schemeNameCollisionEED.ContainsCollision)
                    {
                        collisions.Add(scheme.Name);
                        eeds.Add(schemeNameCollisionEED);
                    }
                }

                Objects.Where(obj => obj.Id == scheme.Name).ToList().ForEach(obj => eeds.Add(new SchemeObjectNameCollisionEED(obj, scheme)));

                var errors = SchemeLang.CompileWithErrors(scheme, this);

                if (errors != null && errors.Count > 0)
                {
                    eeds.Add(new InvalidSchemeEED(scheme));
                }
            }
        }
Example #5
0
        private void RefreshActions(string selectedActionName)
        {
            cbActionName.Items.Clear();

            Scheme scheme = Project.Current.Config.GetSchemeByName(SpecialSchemes.Map);

            //add default item with 'null' (so we can select 'none' action)
            ComboBoxItem defaultItem = new ComboBoxItem();

            defaultItem.Content = "(no action)";
            defaultItem.Tag     = null;
            cbActionName.Items.Add(defaultItem);
            if (selectedActionName == null)
            {
                defaultItem.IsSelected = true;
            }

            if (scheme == null)
            {
                return;
            }

            var errors = SchemeLang.CompileWithErrors(scheme, Project.Current.Config);

            foreach (var action in scheme.CompiledScheme.ActionFunctions)
            {
                ComboBoxItem item = new ComboBoxItem();
                item.Content = item.Tag = action.Name;
                cbActionName.Items.Add(item);

                if (selectedActionName == action.Name)
                {
                    item.IsSelected = true;
                }
            }
        }