コード例 #1
0
        /**
         * Common tasks for generating Ruby from blocks.
         * Handles comments for the specified block and any connected value blocks.
         * Calls any statements following this block.
         * @param {!Blockly.Block} block The current block.
         * @param {string} code The Ruby code created for this block.
         * @return {string} Ruby code with comments and subsequent blocks added.
         * @this {Blockly.CodeGenerator}
         * @private
         */
        public override JsArray <node> scrub_(Block block, JsArray <node> code)
        {
            var commentCode = "";

            // Only collect comments for blocks that aren't inline.
            if (block.outputConnection == null || block.outputConnection.targetConnection == null)
            {
                // Collect comment for this block.
                var comment = block.getCommentText();
                if (!String.IsNullOrEmpty(comment))
                {
                    commentCode += this.prefixLines(comment, "# ") + "\n";
                }
                // Collect comments for all value arguments.
                // Don't collect comments for nested statements.
                var inputList = block.inputList;
                for (var x = 0; x < inputList.Length; x++)
                {
                    if (inputList[x].type == Core.INPUT_VALUE)
                    {
                        var childBlock = inputList[x].connection.targetBlock();
                        if (childBlock != null)
                        {
                            comment = allNestedComments(childBlock);
                            if (!String.IsNullOrEmpty(comment))
                            {
                                commentCode += this.prefixLines(comment, "# ");
                            }
                        }
                    }
                }
            }
            Block nextBlock = null;

            if (block.nextConnection != null)
            {
                nextBlock = block.nextConnection.targetBlock();
            }
            var nextCode = blockToCode(nextBlock);

            if (nextCode == null)
            {
                return(code);
            }
            return(code.Concat(nextCode));
        }
コード例 #2
0
ファイル: factory_utils.cs プロジェクト: h7ga40/BlockFactory
        /// <summary>
        /// Fetch the type(s) defined in the given input.
        /// </summary>
        /// <param name="block"> Block with input.</param>
        /// <param  name="name">Name of the input.</param>
        /// <returns>List of types.</returns>
        private static JsArray <string> getTypesFrom_(Blockly.Block block, string name)
        {
            var typeBlock = block.getInputTargetBlock(name);
            JsArray <string> types;

            if (typeBlock == null || typeBlock.disabled)
            {
                types = new JsArray <string>();
            }
            else if (typeBlock.type == "type_other")
            {
                types = new JsArray <string> {
                    FactoryUtils.escapeString(typeBlock.getFieldValue("TYPE"))
                };
            }
            else if (typeBlock.type == "type_group")
            {
                types = new JsArray <string>();
                for (var n = 0; n < ((TypeGroup)typeBlock).typeCount_; n++)
                {
                    types = types.Concat(FactoryUtils.getTypesFrom_(typeBlock, "TYPE" + n));
                }
                // Remove duplicates.
                var hash = new Dictionary <string, object>();
                for (var n = types.Length - 1; n >= 0; n--)
                {
                    if (hash.ContainsKey(types[n]))
                    {
                        types.Splice(n, 1);
                    }
                    hash[types[n]] = true;
                }
            }
            else
            {
                var fi = typeBlock.GetType().GetField("valueType", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
                types = new JsArray <string> {
                    FactoryUtils.escapeString((string)fi.GetValue(null))
                };
            }
            return(types);
        }
コード例 #3
0
        public JsArray <AstNode> workspaceToNodes(Workspace workspace)
        {
            var nodes  = new JsArray <AstNode>();
            var blocks = workspace.getTopBlocks(true);

            foreach (var block in blocks)
            {
                var line = this.blockToCode(block);
                if (line != null)
                {
                    if (block.outputConnection != null /*&& this.scrubNakedValue*/)
                    {
                        // This block is a naked value.  Ask the language's code generator if
                        // it wants to append a semicolon, or something.
                        line = this.scrubNakedValue(line);
                    }
                    nodes = nodes.Concat(line);
                }
            }
            return(nodes);
        }