コード例 #1
0
        public static void BinarizeStatementList(JsonNode node)
        {
            if (node.kind == JsonNodeKind.Body)
            {
                var statementNodes = node.children;

                var stmtListNode = new JsonNode(JsonNodeKind.StatementList, Guid.NewGuid().ToString());
                stmtListNode.AddChild(
                    JsonNode.Create(JsonNodeKind.Statement, Guid.NewGuid().ToString())
                    .AddChild(new JsonNode(JsonNodeKind.Empty, Guid.NewGuid().ToString()))
                    );

                for (int i = statementNodes.Count - 1; i >= 0; i--)
                {
                    var newStmtListNode = new JsonNode(JsonNodeKind.StatementList, Guid.NewGuid().ToString());
                    newStmtListNode.AddChild(statementNodes[i]);
                    newStmtListNode.AddChild(stmtListNode);
                    stmtListNode = newStmtListNode;
                }

                node.children = new List <JsonNode>();
                node.AddChild(stmtListNode);
            }

            foreach (var child in node.children)
            {
                BinarizeStatementList(child);
            }
        }
コード例 #2
0
        public static void AddBodyNodes(JsonNode node)
        {
            if (ShouldAddBody(node.kind))
            {
                var bodyNode = new JsonNode(JsonNodeKind.Body, node.location)
                {
                    children = node.children
                };
                node.children = new List <JsonNode>();
                node.AddChild(bodyNode);
            }

            foreach (var child in node.children)
            {
                AddBodyNodes(child);
            }
        }
コード例 #3
0
        public static JsonNode ConvertToJsonNode(ICommonTreeNode node)
        {
            string name = null;

            JsonNodeKind kind;

            if (!Enum.TryParse(node.Value, out kind))
            {
                kind = JsonNodeKind.Identifier;
                name = node.Value;
            }

            JsonNode jNode = new JsonNode(kind, "unknown", name);

            node.Children.ForEach(c => jNode.AddChild(ConvertToJsonNode(c)));

            return(jNode);
        }