protected virtual void OnNormalAction(string current, CStreamReader input, StreamWriter output) { int idx = current.IndexOf("//"); if (idx >= 0) { output.Write(current.Substring(0, idx).Trim() + Environment.NewLine); // 끝 주석때문에 newline 필요 } idx = current.IndexOf("/*"); if (idx >= 0) { int cnt = 1; int max = current.Length - 1; StringBuilder builder = new StringBuilder(max - 3); builder.Append(current.Substring(0, idx).Trim()); int begin = 0; for (; idx < max; idx += 2) { char f1 = current[idx]; char f2 = current[idx + 1]; if (f1 == '/' && f2 == '*') { builder.Append(current.Substring(begin, idx).Trim()); cnt++; } else if (f1 == '*' && f2 == '/') { cnt--; if (cnt == 0) { begin = idx + 2; } } } string temp = builder.ToString(); if (FnCHAR.IsNewLine(temp[builder.Length - 1])) { output.Write(temp); } else { output.Write(temp + Environment.NewLine); } } else { output.Write(current); } }
private unsafe int LexSymbol(char read, out string temp, out TokenType type) { // step 1. 한 문자 읽기 // step 2. StartsWith이 일치하는 모든 심볼 찾기 // step 3-true. 단 1개의 심볼만 일치하는 경우 반환 // step 3-false. 실패 CStreamReader sr = this.sr; char *ptr = stackalloc char[4]; // 최대 4개의 심볼을 인식한다 ptr[0] = read; IEnumeratorPair <string, TokenType> e1 = sys; string key = null; TokenType tt = 0; int ptrcnt = 1; bool found = false; loop: int swcnt = 0; while (e1.MoveNext()) { if (e1.Item1.StartsWith(ptr, ptrcnt)) { swcnt++; if (FnCHAR.Equals(ptr, ptrcnt, e1.Item1)) { found = true; key = e1.Item1; tt = e1.Item2; } } } e1.Reset(); if (swcnt == 0 && !found) { handler.Fail(FMSG.L_C2); temp = null; type = 0; return(-1); } else if (swcnt > 1) { ptr[ptrcnt] = (char)sr.Peek(ptrcnt - 1); ptrcnt++; goto loop; } else if (swcnt == 1 && ptrcnt > 1) { sr.Move(ptrcnt - 1); } temp = key; type = tt; return(key.Length); }