예제 #1
0
        private void Resolve厳密等価演算子(ScriptAnalyser sa2)
        {
            ScriptAnalyser.Token[] tokens = sa2.NBTokens;

            for (int index = 0; index < tokens.Length; index++)
            {
                ScriptAnalyser.Token token = tokens[index];

                if (token.Kind == ScriptAnalyser.Token.Kind_e.SYMBOL && token.Pattern == "==")
                {
                    if (
                        index + 1 < tokens.Length &&
                        tokens[index + 1].Kind == ScriptAnalyser.Token.Kind_e.TOKEN &&
                        tokens[index + 1].Pattern == "false"
                        )
                    {
                        token.Pattern             = "!==";
                        tokens[index + 1].Pattern = "true";
                    }
                    else
                    {
                        token.Pattern = "===";
                    }
                }
                else if (token.Kind == ScriptAnalyser.Token.Kind_e.SYMBOL && token.Pattern == "!=")
                {
                    token.Pattern = "!==";
                }
            }
        }
예제 #2
0
        private string ResolveScriptToken(string code)
        {
            ScriptAnalyser sa = new ScriptAnalyser(code);

            Resolve厳密等価演算子(sa);

            return(sa.GetString());
        }
        public string ResolveJSCode(string code)
        {
            ScriptAnalyser sa = new ScriptAnalyser(code);

            ResolveGlobalIdentifier(sa);

            return(sa.GetString());
        }
        private void ResolveGlobalIdentifier(ScriptAnalyser sa)
        {
            ScriptAnalyser.Token[] tokens = sa.NBTokens;

            foreach (ScriptAnalyser.Token token in tokens)
            {
                if (token.Kind == ScriptAnalyser.Token.Kind_e.TOKEN && this.Identifiers.Contains(token.Pattern))
                //if (token.Kind == ScriptAnalyser.Token.Kind_e.TOKEN && this.Identifiers.Contains(this.Identifiers.GetFerret(token.Pattern))) // old
                {
                    token.Pattern = Ground.GlobalName + "_" + token.Pattern;
                }
            }
        }
        private void CollectGlobalIdentifier(ScriptAnalyser sa)
        {
            ScriptAnalyser.Token[] tokens = sa.NBTokens;

            for (int index = 0; index < tokens.Length; index++)
            {
                ScriptAnalyser.Token token = tokens[index];

                if (tokens[index].Kind == ScriptAnalyser.Token.Kind_e.TOKEN &&
                    (tokens[index].Pattern == "function" || tokens[index].Pattern == "var") && index + 1 < tokens.Length &&
                    IsGlobalIdentifier(tokens[index + 1].Pattern))
                {
                    this.Identifiers.Add(tokens[index + 1].Pattern);
                }
            }
        }
        //private SortedList<string> Identifiers = new SortedList<string>(StringTools.Comp); // old

        public void AddJSCode(string code)
        {
            ScriptAnalyser sa = new ScriptAnalyser(code);

            CollectGlobalIdentifier(sa);
        }