少年修仙传客户端基础资源
dabaoji
2025-06-04 34d28a982a741d63f183884881b0bea73f8c8b47
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.IO;
using System.Linq;
using System;
 
#if UNITY_XCODE_API_BUILD
namespace UnityEditor.iOS.Xcode.PBX
#else
namespace UnityEditor.iOS.Xcode.Custom.PBX
#endif
{
    class ValueAST {}
 
    // IdentifierAST := <quoted string> \ <string>
    class IdentifierAST : ValueAST
    {
        public int value = 0; // token id
    }
 
    // TreeAST := '{' KeyValuePairList '}'
    // KeyValuePairList := KeyValuePair ',' KeyValuePairList
    //                     KeyValuePair ','
    //                     (empty)
    class TreeAST : ValueAST
    {
        public List<KeyValueAST> values = new List<KeyValueAST>();
    }
 
    // ListAST := '(' ValueList ')'
    // ValueList := ValueAST ',' ValueList
    //              ValueAST ','
    //              (empty)
    class ArrayAST : ValueAST
    {
        public List<ValueAST> values = new List<ValueAST>();
    }
 
    // KeyValueAST := IdentifierAST '=' ValueAST ';'
    // ValueAST := IdentifierAST | TreeAST | ListAST
    class KeyValueAST
    {
        public IdentifierAST key = null;
        public ValueAST value = null; // either IdentifierAST, TreeAST or ListAST
    }
    
    class Parser
    { 
        TokenList tokens;
        int currPos;
 
        public Parser(TokenList tokens)
        {
            this.tokens = tokens;
            currPos = SkipComments(0);
        }
        
        int SkipComments(int pos)
        {
            while (pos < tokens.Count && tokens[pos].type == TokenType.Comment)
            {
                pos++;
            }
            return pos;
        }
       
        // returns new position
        int IncInternal(int pos)
        {
            if (pos >= tokens.Count)
                return pos;
            pos++;
            
            return SkipComments(pos);
        }
        
        // Increments current pointer if not past the end, returns previous pos
        int Inc()
        {
            int prev = currPos;
            currPos = IncInternal(currPos);
            return prev;
        }
 
        // Returns the token type of the current token
        TokenType Tok()
        {
            if (currPos >= tokens.Count)
                return TokenType.EOF;
            return tokens[currPos].type;
        }
        
        void SkipIf(TokenType type)
        {
            if (Tok() == type)
                Inc();
        }
        
        string GetErrorMsg()
        {
            return "Invalid PBX project (parsing line " + tokens[currPos].line + ")";
        }
        
        public IdentifierAST ParseIdentifier()
        {
            if (Tok() != TokenType.String && Tok() != TokenType.QuotedString)
                throw new Exception(GetErrorMsg());
            var ast = new IdentifierAST();
            ast.value = Inc();
            return ast;
        }
        
        public TreeAST ParseTree()
        {
            if (Tok() != TokenType.LBrace)
                throw new Exception(GetErrorMsg());
            Inc();
            
            var ast = new TreeAST();
            while (Tok() != TokenType.RBrace && Tok() != TokenType.EOF)
            {
                ast.values.Add(ParseKeyValue());
            }
            SkipIf(TokenType.RBrace);
            return ast;  
        }
        
        public ArrayAST ParseList()
        {
            if (Tok() != TokenType.LParen)
                throw new Exception(GetErrorMsg());
            Inc();
            
            var ast = new ArrayAST();
            while (Tok() != TokenType.RParen && Tok() != TokenType.EOF)
            {
                ast.values.Add(ParseValue());
                SkipIf(TokenType.Comma);
            }
            SkipIf(TokenType.RParen);
            return ast;  
        }
        
        // throws on error
        public KeyValueAST ParseKeyValue()
        {
            var ast = new KeyValueAST();
            ast.key = ParseIdentifier();
          
            if (Tok() != TokenType.Eq)
                throw new Exception(GetErrorMsg());
            Inc(); // skip '='
                       
            ast.value = ParseValue();
            SkipIf(TokenType.Semicolon);
 
            return ast;
        }
        
        // throws on error
        public ValueAST ParseValue()
        {
            if (Tok() == TokenType.String || Tok() == TokenType.QuotedString)
                return ParseIdentifier();
            else if (Tok() == TokenType.LBrace)
                return ParseTree();
            else if (Tok() == TokenType.LParen)
                return ParseList();
            throw new Exception(GetErrorMsg());
        }
    } 
    
} // namespace UnityEditor.iOS.Xcode