コード例 #1
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="TSParser.object_decl"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitObject_decl([NotNull] TSParser.Object_declContext context)
 {
     return(VisitChildren(context));
 }
コード例 #2
0
        TSObject ProcessObject(TSParser.Object_declContext objectDecl)
        {
            var retObj = ScriptableObject.CreateInstance <TSObject>();

            // Metadata
            retObj.ClassName = objectDecl.class_name_expr().GetText();
            retObj.Name      = objectDecl.object_name().GetText();

            var fieldBlock = objectDecl.object_declare_block();

            if (fieldBlock == null)
            {
                return(retObj);
            }

            // Fields
            foreach (var assignList in fieldBlock.slot_assign_list())
            {
                foreach (var slot in assignList.slot_assign())
                {
                    var key        = slot.children[0].GetText();
                    var arrayValue = slot.aidx_expr()?.expr();
                    var value      = slot.expr();

                    if (arrayValue != null)
                    {
                        for (int i = 0; i < arrayValue.Length; i++)
                        {
                            if (i > 0)
                            {
                                key += "_";
                            }

                            key += arrayValue[i].GetText();
                        }
                    }

                    var valueStr = value.GetText();

                    var str = value.STRATOM();
                    if (str != null)
                    {
                        valueStr = str.GetText().Substring(1, valueStr.Length - 2);
                    }

                    retObj.Fields.Add(key.ToLower(), valueStr);
                }
            }

            // Sub Objects
            foreach (var subObject in fieldBlock.object_decl_list())
            {
                foreach (var subObjectDecl in subObject.object_decl())
                {
                    var child = ProcessObject(subObjectDecl);
                    child.Parent = retObj;
                    retObj.Children.Add(child);
                }
            }

            return(retObj);
        }
コード例 #3
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="TSParser.object_decl"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitObject_decl([NotNull] TSParser.Object_declContext context)
 {
 }