示例#1
0
文件: Dsl.cs 项目: dreamanlan/DSL
        public string GenerateBinaryCode(string content, Dictionary<string, string> encodeTable, DslLogDelegation logCallback)
        {
            #if FULL_VERSION
            List<DslInfo> infos = new List<DslInfo>();
            Parser.DslLog log = new Parser.DslLog();
            log.OnLog += logCallback;
            Parser.DslToken tokens = new Parser.DslToken(log, content);
            Parser.DslError error = new Parser.DslError(log, tokens);
            Parser.RuntimeAction action = new Parser.RuntimeAction(infos);
            action.onGetLastToken = () => { return tokens.getLastToken(); };
            action.onGetLastLineNumber = () => { return tokens.getLastLineNumber(); };
            action.onSetStringDelimiter = (string begin, string end) => { tokens.setStringDelimiter(begin, end); };
            action.onSetScriptDelimiter = (string begin, string end) => { tokens.setScriptDelimiter(begin, end); };
            Parser.DslParser.parse(action, tokens, error, 0);
            if (error.HasError) {
                return string.Empty;
            } else {
                MemoryStream stream = new MemoryStream();
                List<string> identifiers = new List<string>();
                foreach (DslInfo info in infos) {
                    Utility.writeBinary(stream, identifiers, (StatementData)info);
                }

                byte[] bytes = stream.ToArray();
                SortedDictionary<string, int> dict = new SortedDictionary<string, int>();
                int ct = identifiers.Count;
                if (ct > 0x00004000) {
                    System.Diagnostics.Debug.Assert(false);
                    //Console.WriteLine("Identifiers count {0} too large than 0x04000", ct);
                    return string.Empty;
                }
                for (int i = 0; i < ct; ++i) {
                    string key = identifiers[i];
                    key = Encode(key, encodeTable);
                    identifiers[i] = key;
                    if (!dict.ContainsKey(key)) {
                        dict.Add(key, 0);
                    }
                }
                List<string> keys = new List<string>(dict.Keys);
                byte[] bytes2;
                using (MemoryStream ms = new MemoryStream()) {
                    for (int i = 0; i < ct; ++i) {
                        string key = identifiers[i];
                        int ix = keys.BinarySearch(key);
                        if (ix < 0x80) {
                            ms.WriteByte((byte)ix);
                        } else {
                            ms.WriteByte((byte)((ix & 0x0000007f) | 0x00000080));
                            ms.WriteByte((byte)(ix >> 7));
                        }
                    }
                    bytes2 = ms.ToArray();
                }
                return string.Format("{0}|{1}|{2}", Convert.ToBase64String(bytes), Convert.ToBase64String(bytes2), string.Join("`", keys.ToArray()));
            }
            #else
              return string.Empty;
            #endif
        }
示例#2
0
文件: Dsl.cs 项目: dreamanlan/DSL
        public bool LoadFromString(string content, string resourceName, DslLogDelegation logCallback)
        {
            #if FULL_VERSION
            mDslInfos.Clear();
            Parser.DslLog log = new Parser.DslLog();
            log.OnLog += logCallback;
            Parser.DslToken tokens = new Parser.DslToken(log, content);
            Parser.DslError error = new Parser.DslError(log, tokens);
            Parser.RuntimeAction action = new Parser.RuntimeAction(mDslInfos);
            action.onGetLastToken = () => { return tokens.getLastToken(); };
            action.onGetLastLineNumber = () => { return tokens.getLastLineNumber(); };
            action.onGetComment = (out bool commentOnNewLine) => { commentOnNewLine = tokens.IsCommentOnNewLine(); List<string> ret = new List<string>();ret.AddRange(tokens.GetComments()); tokens.ResetComments(); return ret; };
            action.onSetStringDelimiter = (string begin, string end) => { tokens.setStringDelimiter(begin, end); };
            action.onSetScriptDelimiter = (string begin, string end) => { tokens.setScriptDelimiter(begin, end); };

            Parser.DslParser.parse(action, tokens, error, 0);
            if (error.HasError) {
                for (int i = 0; i < mDslInfos.Count; i++) {
                    mDslInfos[i].Clear();
                }
            } else {
                for (int i = 0; i < mDslInfos.Count; i++) {
                    mDslInfos[i].SetResourceName(resourceName);
                }
            }
            return !error.HasError;
            #else
              return false;
            #endif
        }
示例#3
0
文件: Dsl.cs 项目: CQiao/DSL
    public bool LoadFromString(string content, string resourceName, DslLogDelegation logCallback)
    {
#if FULL_VERSION
      mDslInfos.Clear();
      Parser.DslLog log = new Parser.DslLog();
      log.OnLog += logCallback;
		  Parser.DslToken tokens = new Parser.DslToken(log, content);
		  Parser.DslError error = new Parser.DslError(log, tokens);
      Parser.RuntimeAction action = new Parser.RuntimeAction(mDslInfos);
      action.onGetLastToken = () => { return tokens.getLastToken(); };
      action.onGetLastLineNumber = () => { return tokens.getLastLineNumber(); };
		  Parser.DslParser.parse(action,tokens,error,0);
		  if(error.HasError)
		  {
        for (int i = 0; i < mDslInfos.Count; i++ )
        {
          mDslInfos[i].Clear();
        }
		  }
      else
      {
        for (int i = 0; i < mDslInfos.Count; i++)
        {
          mDslInfos[i].SetResourceName(resourceName);
        }
		  }
		  return !error.HasError;
#else
      return false;
#endif
    }