Esempio n. 1
0
        static void getChildren(string source, ref int index, Values.XML xml)
        {
            Parser parser = new XMLParser();

            while (parser.Scan(source, index))
            {
                xml.AddChild((Values.XML)parser.Result.Value);
                index = parser.Result.Position;
            }

            var matcher = new Matcher();

            if (matcher.IsMatch(source.Substring(index), @"^\s*<%%"))
            {
                var openLength = matcher[0].Length;
                Color(index, openLength, IDEColor.EntityType.Structure);
                index       += openLength;
                xml.Children = OrangeCompiler.Block(source, ref index, "%>");
            }

            parser = new IndirectXMLParser();
            while (parser.Scan(source, index))
            {
                xml.AddChild((Values.XML)parser.Result.Value);
                index = parser.Result.Position;
            }
        }
Esempio n. 2
0
 /// <summary>
 /// If the selected file can be compressed to a data uri, this will place it on the clipboard
 /// </summary>
 /// <param name="e"></param>
 protected void AddCopyDataURIMenu(ContextMenuOpeningEventArgs e)
 {
     if (e.Items.Count == 1)
     {
         var item = e.Items.First();
         if (item is ISiteFile)
         {
             var path = (item as ISiteFile).Path;
             if (OrangeCompiler.CanGetDataURI(path))
             {
                 var menuItem = new ContextMenuItem("Copy Data URI", null, new DelegateCommand((filePath) =>
                 {
                     var scheduler = TaskScheduler.FromCurrentSynchronizationContext();
                     Task.Factory.StartNew(() =>
                     {
                         var data = "data:image/" +
                                    Path.GetExtension(filePath as string).Replace(".", "") +
                                    ";base64," +
                                    Convert.ToBase64String(File.ReadAllBytes(filePath as string));
                         return(data);
                     }).ContinueWith((x) =>
                     {
                         Clipboard.SetText(x.Result);
                     }, scheduler);
                 }), path);
                 e.AddMenuItem(menuItem);
             }
         }
     }
 }
        public override Verb CreateVerb(string[] tokens)
        {
            Color(position, tokens[1].Length, IDEColor.EntityType.Whitespace);
            string visibility = tokens[2];

            Color(visibility.Length, IDEColor.EntityType.Verb);
            string scope = tokens[3];

            Color(scope.Length, IDEColor.EntityType.Verb);
            ClassParser.SetScopeAndVisibility(scope, visibility, this);
            string messageName = tokens[4];

            Color(messageName.Length, IDEColor.EntityType.Variable);
            Color(tokens[5].Length, IDEColor.EntityType.Structure);

            var              compiler       = new OrangeCompiler(source, position + length);
            Block            parameterBlock = compiler.Compile();
            int              index          = compiler.Position;
            List <Parameter> parameterList  = ParameterParser.GetParameterList(parameterBlock);
            var              parameters     = new Parameters(parameterList);

            if (functionBodyParser.Scan(source, index))
            {
                return(createMethod(messageName, functionBodyParser, parameters, false));
            }
            return(equalBlockParser.Scan(source, index) ? createMethod(messageName, equalBlockParser, parameters, true) : null);
        }
        public override Verb CreateVerb(string[] tokens)
        {
            Color(position, tokens[1].Length, IDEColor.EntityType.Verb);
            Color(tokens[2].Length, IDEColor.EntityType.Structure);
            var index         = position + length;
            var block         = OrangeCompiler.Block(source, ref index, true);
            var parameterList = ParameterParser.GetParameterList(block);
            var parameters    = new Parameters(new[]
            {
                new Parameter(""),
                new Parameter(""),
                new Parameter("")
            });

            if (parser.Scan(source, index))
            {
                block = (Block)parser.Result.Value;
                index = parser.Result.Position;
            }
            else
            {
                block = null;
            }
            overridePosition = index;
            var unpackedVariables = parameterList.Select(t => t.Name).ToList();

            return(new PushArrayParameters(parameters, block, unpackedVariables));
        }
Esempio n. 5
0
        public override Verb CreateVerb(string[] tokens)
        {
            Color(position, tokens[1].Length, IDEColor.EntityType.KeyWord);
            var index = position + length;

            if (closureParser.Scan(source, index))
            {
                var closure = (Closure)(closureParser.Result.Value);
                index = closureParser.Result.Position;
                if (matcher.IsMatch(source.Substring(index), @"^(\s*until)(\s*\()"))
                {
                    Color(index, matcher[0, 1].Length, IDEColor.EntityType.KeyWord);
                    Color(matcher[0, 2].Length, IDEColor.EntityType.Structure);
                    index += matcher[0].Length;
                    var checkExpression = OrangeCompiler.Block(source, ref index);
                    if (matcher.IsMatch(source.Substring(index), @"^(\s*then)(\s*\()"))
                    {
                        Color(index, matcher[0, 1].Length, IDEColor.EntityType.KeyWord);
                        Color(matcher[0, 2].Length, IDEColor.EntityType.Structure);
                        index += matcher[0].Length;
                        var finalValue = OrangeCompiler.Block(source, ref index);
                        overridePosition = index;
                        return(new TailCall(closure, checkExpression, finalValue));
                    }
                }
            }
            return(null);
        }
Esempio n. 6
0
        public override Verb CreateVerb(string[] tokens)
        {
            Color(position, length, IDEColor.EntityType.Structures);
            var index = position + length;
            var block = OrangeCompiler.ParseBlock(source, ref index, ")");

            overridePosition = index;
            return(new CreateReadOnlyArray(block));
        }
Esempio n. 7
0
        public Value Evaluate()
        {
            string source   = Text;
            var    compiler = new OrangeCompiler(source.Trim());
            Block  block    = compiler.Compile();

            block.Evaluate();
            return(RegionManager.Regions[variableName].Text);
        }
Esempio n. 8
0
        public static Block Parse(string source, ref int position, bool addEnd)
        {
            var block = OrangeCompiler.Block(source, ref position, Runtime.REGEX_END, OrangeCompiler.ConsumeEndOfBlockType.SingleLine);

            if (addEnd)
            {
                block.Add(new End());
            }
            return(block);
        }
Esempio n. 9
0
        public override Verb CreateVerb(string[] tokens)
        {
            Color(position, length, IDEColor.EntityType.Structure);
            var index = position + length;
            var block = OrangeCompiler.Block(source, ref index, ")");

            result.Value     = block;
            overridePosition = index;
            return(new NullOp());
        }
Esempio n. 10
0
        public override Verb CreateVerb(string[] tokens)
        {
            Color(position, tokens[1].Length, IDEColor.EntityType.Verb);
            Color(tokens[2].Length, IDEColor.EntityType.Structure);
            var   compiler = new OrangeCompiler(source, position + length);
            Block block    = compiler.Compile();

            result.Value     = block;
            overridePosition = compiler.Position;
            return(new NullOp());
        }
Esempio n. 11
0
        public override Verb CreateVerb(string[] tokens)
        {
            Color(position, tokens[1].Length, IDEColor.EntityType.Whitespaces);
            var className = tokens[2];

            Color(className.Length, IDEColor.EntityType.Variables);
            Color(tokens[3].Length, IDEColor.EntityType.Structures);
            var index = position + length;
            var block = OrangeCompiler.ParseBlock(source, ref index, "}");

            overridePosition = index;
            return(new SendNewMessage(className, block));
        }
Esempio n. 12
0
 public bool Parse(string source, ref int index, out Arguments arguments)
 {
     if (matcher.IsMatch(source.Substring(index), "^/s* '->' /s* '('"))
     {
         var length = matcher[0].Length;
         Parser.Color(index, length, IDEColor.EntityType.Structure);
         index += length;
         var block = OrangeCompiler.ParseBlock(source, ref index, ")");
         arguments = new Arguments(block);
         return(true);
     }
     arguments = null;
     return(false);
 }
Esempio n. 13
0
        /// <summary>
        /// process a file, generating the compiled output
        /// </summary>
        /// <param name="item"></param>
        protected void ProcessItem(OrangeJob job)
        {
            var threadedOpenCmd = new Action(() =>
            {
                mainDispatcher.Invoke(new Action(() =>
                {
                    var openCommand = host.HostCommands.OpenFileInEditor;
                    if (openCommand.CanExecute(job.OutputPath))
                    {
                        openCommand.Execute(job.OutputPath);
                    }
                }));
            });

            try
            {
                // do the actual compilation work
                CompileResults results = OrangeCompiler.Process(job);

                // show the notification bar to notify the user it happened
                if (!String.IsNullOrEmpty(results.Message))
                {
                    host.ShowNotification(results.Message, "Open File", threadedOpenCmd);
                }

                // refresh the tree so the new file (if created) shows up
                if (results.IsNewFile)
                {
                    mainDispatcher.Invoke(new Action(() =>
                    {
                        var refreshCommand = host.HostCommands.GetCommand(CommonCommandIds.GroupId, (int)CommonCommandIds.Ids.Refresh);
                        if (refreshCommand.CanExecute(null))
                        {
                            refreshCommand.Execute(null);
                        }
                    }));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                host.ShowNotification("There was an error processing " + job.Path, "Open File", threadedOpenCmd);
            }
        }
Esempio n. 14
0
        public override void Render(StringWriter writer, string variableName)
        {
            Stack.Push(text);
            writer.Write($"|<{text}");
            if (attributes.IsNotEmpty())
            {
                var index = 0;
                var block = OrangeCompiler.ParseBlock(attributes, ref index, "");
                var value = block.Evaluate();
                if (value != null)
                {
                    switch (value.Type)
                    {
                    case Value.ValueType.Array:
                        var attributesText = getAttributes((Array)value.Resolve());
                        writer.WriteLine($" {attributesText}>|.write('{variableName}');");
                        break;

                    case Value.ValueType.KeyedValue:
                        var attributeText = getAttribute((KeyedValue)value);
                        writer.WriteLine($" {attributeText}>|.write('{variableName}');");
                        break;

                    default:
                        writer.WriteLine($">|.write('{variableName}');");
                        break;
                    }
                }
                else
                {
                    writer.WriteLine($">|.write('{variableName}');");
                }
            }
            else
            {
                writer.WriteLine($">|.write('{variableName}');");
            }
        }
Esempio n. 15
0
        public override Verb CreateVerb(string[] tokens)
        {
            Color(position, tokens[1].Length, IDEColor.EntityType.Whitespace);
            string visibility = tokens[2];

            Color(visibility.Length, IDEColor.EntityType.Verb);
            string scope = tokens[3];

            Color(scope.Length, IDEColor.EntityType.Verb);
            ClassParser.SetScopeAndVisibility(scope, visibility, this);
            string messageName = tokens[4];

            Color(messageName.Length, IDEColor.EntityType.Variable);
            Color(tokens[5].Length, IDEColor.EntityType.Verb);
            Color(tokens[6].Length, IDEColor.EntityType.Structure);

            int   index    = position + length;
            var   compiler = new OrangeCompiler(source, index);
            Block block    = compiler.Compile();

            result.Position = compiler.Position;
            Builder.AddInitializedVariable(messageName, block, this, null);
            return(new NullOp());
        }
Esempio n. 16
0
        public override Verb CreateVerb(string[] tokens)
        {
            var tokens1Length = tokens[1].Length;

            Color(position, tokens1Length, IDEColor.EntityType.Variable);
            Value value;

            if (tokens[2] == "(")
            {
                Color(1, IDEColor.EntityType.Structure);
                var index = position + tokens1Length + 1;
                var block = OrangeCompiler.Block(source, ref index, ")", true);
                overridePosition = index;
                value            = new FieldBlockVariable(block);
            }
            else
            {
                Color(tokens[2].Length, IDEColor.EntityType.Number);
                var index = tokens[2].ToInt();
                value = new FieldVariable(index);
            }
            result.Value = value;
            return(new Push(value));
        }