////////////////////////////// public override string ToString() { return(String.Format( "{0}", //ID, String.Join(" ", Linq2.ToArray(Linq2.Select(this.Tokens, i => i.TokenName))))); }
public void Set(IList <Char> TokenName, Boolean CorrectPriority) { this.TokenChars = TokenName; this.TokenName = new String(Linq2.ToArray(this.TokenChars)); if (CorrectPriority) { this.Priority = OnpOnpTokenHelper.GetPriority(this); } }
public void Set(String TokenName, Boolean CorrectPriority) { this.TokenChars = Linq2.ToArray(TokenName.ToCharArray()); this.TokenName = TokenName; if (CorrectPriority) { this.Priority = OnpOnpTokenHelper.GetPriority(this); } }
public ExpressionToken Clone() { ExpressionToken item = (ExpressionToken)this.MemberwiseClone(); item.TokenChars = Linq2.ToArray(this.TokenChars); if (item.TokenData != null) { item.TokenData = item.TokenData.Clone(); } return(item); }
/*public DynLanCodeLine GetCodeLine(Int32 Depth, CodeLine line, CodeLine nextLine) * { * return SetCodeLine(null, Depth, line, nextLine); * }*/ /*public DynLanCodeLine SetCodeLine(DynLanCodeLine compiledLine, Int32 Depth, String line) * { * return SetCodeLine(compiledLine, Depth, new CodeLine(line)); * }*/ public DynLanCodeLine SetCodeLine(DynLanCodeLine compiledLine, CodeLine line, CodeLine nextLine, ref Int32 Depth, ref int CharIndex) { Int32 orgDepth = Depth; IList <Char> lineTrimmed = Linq2.ToArray( StringHelper.TrimStart( StringHelper.TrimEnd(line))); IList <Char> lineBody = line; EOperatorType operatorType = EOperatorType.NONE; // IF: wykrycie definicji IF'a if (//lineTrimmed.Count > str_if.Length && StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_if, true, true) /* && * Char.IsWhiteSpace(lineTrimmed[str_if.Length])*/) { Int32 depth = GetDepth(line); operatorType = EOperatorType.IF; lineBody = Linq2.ToList( StringHelper.TrimStart( StringHelper.Substring2(lineTrimmed, str_if.Length))); #if SPACES_FOR_DEPTH for (int i = 0; i < depth; i++) { lineBody.Insert(0, ' '); } // lineBody.TrimEnd(':'); #else if (lineBody.Count == 0) { throw new Exception("IF body cannot be empty !"); } if (!StringHelper.SequenceEqualInsensitive(nextLine, DynLanuageSymbols.DepthBegin)) { throw new Exception("IF body should begin with bracket { !"); } else { Depth++; CharIndex++; } #endif } // WHILE: wykrycie definicji WHILE'a else if (//lineTrimmed.Count > str_while.Length && StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_while, true, true) /*&& * Char.IsWhiteSpace(lineTrimmed[str_while.Length])*/) { Int32 depth = GetDepth(line); operatorType = EOperatorType.WHILE; lineBody = Linq2.ToList( StringHelper.TrimStart( StringHelper.Substring2(lineTrimmed, str_while.Length))); #if SPACES_FOR_DEPTH for (int i = 0; i < depth; i++) { lineBody.Insert(0, ' '); } // lineBody.TrimEnd(':'); #else if (lineBody.Count == 0) { throw new Exception("WHILE body cannot be empty !"); } if (!StringHelper.SequenceEqualInsensitive(nextLine, DynLanuageSymbols.DepthBegin)) { throw new Exception("WHILE body should begin with bracket { !"); } else { Depth++; CharIndex++; } #endif } // ELSE: wykrycie definicji ELSE'a else if (// lineTrimmed.Count >= str_else.Length && StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_else, true, true)) { Int32 depth = GetDepth(line); operatorType = EOperatorType.ELSE; lineBody = Linq2.ToList( StringHelper.TrimStart( StringHelper.Substring2(lineTrimmed, str_else.Length))); #if SPACES_FOR_DEPTH for (int i = 0; i < depth; i++) { lineBody.Insert(0, ' '); } // lineBody.TrimEnd(':'); #else if (lineBody.Count > 0) { throw new Exception("ELSE body must be empty !"); } if (!StringHelper.SequenceEqualInsensitive(nextLine, DynLanuageSymbols.DepthBegin)) { throw new Exception("ELSE body should begin with bracket { !"); } else { Depth++; CharIndex++; } #endif } // ELIF: wykrycie definicji ELIF'a else if (// lineTrimmed.Count > str_elif.Length && StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_elif, true, true) /*&& * Char.IsWhiteSpace(lineTrimmed[str_elif.Length])*/) { Int32 depth = GetDepth(line); operatorType = EOperatorType.ELIF; lineBody = Linq2.ToList( StringHelper.TrimStart( StringHelper.Substring2(lineTrimmed, str_elif.Length))); #if SPACES_FOR_DEPTH for (int i = 0; i < depth; i++) { lineBody.Insert(0, ' '); } // lineBody.TrimEnd(':'); #else if (lineBody.Count == 0) { throw new Exception("ELIF body cannot be empty !"); } if (!StringHelper.SequenceEqualInsensitive(nextLine, DynLanuageSymbols.DepthBegin)) { throw new Exception("ELIF body should begin with bracket { !"); } else { Depth++; CharIndex++; } #endif } // RETURN: wykrycie definicji RETURN'a else if (// lineTrimmed.Count > str_return.Length && StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_return, true, true) /*&& * Char.IsWhiteSpace(lineTrimmed[str_return.Length])*/) { Int32 depth = GetDepth(line); operatorType = EOperatorType.RETURN; lineBody = Linq2.ToList( StringHelper.TrimStart( StringHelper.Substring2(lineTrimmed, str_return.Length))); #if SPACES_FOR_DEPTH for (int i = 0; i < depth; i++) { lineBody.Insert(0, ' '); } // lineBody.TrimEnd(':'); #endif } // RETURN: wykrycie definicji RETURN'a /*else if (// lineTrimmed.Count >= str_return.Length && * StringHelper.StartsWith(lineTrimmed.TrimStart().ToArray(), str_return, true, true)) * { * Int32 depth = GetDepth(line); * operatorType = EOperatorType.RETURN; * * lineBody = lineTrimmed. * Substring2(str_return.Length). * TrimStart(). * ToList(); * #if SPACES_FOR_DEPTH * for (int i = 0; i < depth; i++) * lineBody.Insert(0, ' '); * // lineBody.TrimEnd(':'); #endif * }*/ // RETURN: wykrycie definicji PASS'a else if (//(lineTrimmed.Count == str_pass.Length || (lineTrimmed.Count > str_pass.Length && Char.IsWhiteSpace(lineTrimmed[str_pass.Length]))) StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_pass, true, true)) { Int32 depth = GetDepth(line); operatorType = EOperatorType.PASS; lineBody = Linq2.ToList( StringHelper.TrimStart( StringHelper.Substring2(lineTrimmed, str_pass.Length))); #if SPACES_FOR_DEPTH for (int i = 0; i < depth; i++) { lineBody.Insert(0, ' '); } // lineBody.TrimEnd(':'); #endif } // TRY: wykrycie definicji TRY'a else if (// lineTrimmed.Count > str_try.Length && StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_try, true, true) /*&& * Char.IsWhiteSpace(lineTrimmed[str_try.Length])*/) { Int32 depth = GetDepth(line); operatorType = EOperatorType.TRY; lineBody = Linq2.ToList( StringHelper.TrimStart( StringHelper.Substring2(lineTrimmed, str_try.Length))); #if SPACES_FOR_DEPTH for (int i = 0; i < depth; i++) { lineBody.Insert(0, ' '); } // lineBody.TrimEnd(':'); #else if (!StringHelper.SequenceEqualInsensitive(nextLine, DynLanuageSymbols.DepthBegin)) { throw new Exception("TRY body should begin with bracket { !"); } else { Depth++; CharIndex++; } #endif } // CATCH: wykrycie definicji CATCH'a else if (// lineTrimmed.Count > str_catch.Length && StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_catch, true, true) /*&& * Char.IsWhiteSpace(lineTrimmed[str_catch.Length])*/) { Int32 depth = GetDepth(line); operatorType = EOperatorType.CATCH; lineBody = Linq2.ToList( StringHelper.TrimStart( StringHelper.Substring2(lineTrimmed, str_catch.Length))); #if SPACES_FOR_DEPTH for (int i = 0; i < depth; i++) { lineBody.Insert(0, ' '); } // lineBody.TrimEnd(':'); #else if (!StringHelper.SequenceEqualInsensitive(nextLine, DynLanuageSymbols.DepthBegin)) { throw new Exception("CATCH body should begin with bracket { !"); } else { Depth++; CharIndex++; } #endif } // FINALLY: wykrycie definicji FINALLY'a else if (// lineTrimmed.Count > str_finally.Length && StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_finally, true, true) /*&& * Char.IsWhiteSpace(lineTrimmed[str_finally.Length])*/) { Int32 depth = GetDepth(line); operatorType = EOperatorType.FINALLY; lineBody = Linq2.ToList( StringHelper.TrimStart( StringHelper.Substring2(lineTrimmed, str_finally.Length))); #if SPACES_FOR_DEPTH for (int i = 0; i < depth; i++) { lineBody.Insert(0, ' '); } // lineBody.TrimEnd(':'); #else if (!StringHelper.SequenceEqualInsensitive(nextLine, DynLanuageSymbols.DepthBegin)) { throw new Exception("FINALLY body should begin with bracket { !"); } else { Depth++; CharIndex++; } #endif } // THROW: wykrycie definicji THROW'a else if (lineTrimmed.Count > str_throw.Length && StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_throw, true, true) /*&& * Char.IsWhiteSpace(lineTrimmed[str_THROW.Length])*/) { Int32 depth = GetDepth(line); operatorType = EOperatorType.THROW; lineBody = Linq2.ToList( StringHelper.TrimStart( StringHelper.Substring2(lineTrimmed, str_throw.Length))); #if SPACES_FOR_DEPTH for (int i = 0; i < depth; i++) { lineBody.Insert(0, ' '); } // lineBody.TrimEnd(':'); #endif } // BREAK: wykrycie definicji BREAK'a else if (// lineTrimmed.Count > str_break.Length && StringHelper.StartsWith(Linq2.ToArray(StringHelper.TrimStart(lineTrimmed)), str_break, true, true) /*&& * Char.IsWhiteSpace(lineTrimmed[str_break.Length])*/) { Int32 depth = GetDepth(line); operatorType = EOperatorType.BREAK; lineBody = Linq2.ToList( StringHelper.TrimStart( StringHelper.Substring2(lineTrimmed, str_break.Length))); #if SPACES_FOR_DEPTH for (int i = 0; i < depth; i++) { lineBody.Insert(0, ' '); } // lineBody.TrimEnd(':'); #endif } ExpressionGroup expressionGroup = TokenizerInvariant.I. Compile(lineBody); if (compiledLine == null) { compiledLine = new DynLanCodeLine(); } compiledLine.Code = StringHelper.ToString2(line); compiledLine.ExpressionGroup = expressionGroup; compiledLine.OperatorType = operatorType; compiledLine.IsLineEmpty = lineTrimmed.Count == 0; #if !SPACES_FOR_DEPTH compiledLine.Depth = orgDepth; #else compiledLine.Depth += GetDepth(lineBody); #endif return(compiledLine); }
//////////////////////////// /// <summary> /// Zwraca przygotowane wyrażenie /// </summary> public void PrepareMainExpression( String ExpressionId, IList <Char> ExpressionChars, ParserSettings ParserSettings, ExpressionGroup ExpressionGroup) { try { Expression onpExpression = new Expression(ExpressionId); onpExpression.Tokens = TokenGetter.GetOptimizedTokens(ExpressionChars, ParserSettings); ExpressionGroup.Expressions[ExpressionId] = onpExpression; // zamiania znaków równości na wołanie funkcji List <ExpressionTokens> resultTokens = new List <ExpressionTokens>(); while (true) { ExpressionTokens setTokens = TakeSetTokens( onpExpression.Tokens); if (setTokens == null) { break; } resultTokens.Insert(0, setTokens); } Expression currentExpression = onpExpression; foreach (ExpressionTokens resultToken in resultTokens) { Expression setExpression = new Expression(); setExpression.IsOnpExecution = false; setExpression.Tokens = resultToken; ExpressionGroup.Expressions[setExpression.ID] = setExpression; PrepareExpressions( setExpression, ParserSettings, ExpressionGroup); CorrectSetExpression( setExpression, currentExpression.ID, ParserSettings, ExpressionGroup); currentExpression = setExpression; } ExpressionGroup.MainExpression = currentExpression; PrepareExpressions( onpExpression, ParserSettings, ExpressionGroup); } catch (Exception ex) { throw new DynLanCompileException( "Error in expression: '" + new string(Linq2.ToArray(ExpressionChars), 0, ExpressionChars.Count).Replace("'", "\\'") + "'; " + ex.Message, ex); } }
public static IList <OnpMethodPart> ExtractNames(String Code, Boolean AllObjects) { List <OnpMethodPart> parts = new List <OnpMethodPart>(); Code = Code.Trim(); Int32 indexOfBracketStart = Code.IndexOf("("); Int32 indexOfBracketEnd = Code.LastIndexOf(")"); Int32 indexOfMethodInvoke = indexOfBracketStart >= 0 ? Code.Substring(0, indexOfBracketStart).LastIndexOf(".") : Code.IndexOf("."); // variable invoke if (indexOfBracketStart < 0 && indexOfBracketEnd < 0) { String propertyPath = Code; parts.Add(new OnpMethodPart() { Part = propertyPath == "," ? EOnpMethodPart.COMA : EOnpMethodPart.PARAMETER, Code = propertyPath }); } // method for object invoke else if (indexOfMethodInvoke >= 0 && indexOfBracketStart >= 0 && indexOfBracketEnd >= 0) { String propertyPath = Code.Substring( 0, indexOfMethodInvoke).Trim(); parts.Add(new OnpMethodPart() { Part = propertyPath == "," ? EOnpMethodPart.COMA : EOnpMethodPart.PARAMETER, Code = propertyPath }); String methodName = Code.Substring( indexOfMethodInvoke + 1, indexOfBracketStart - indexOfMethodInvoke - 1).Trim(); IList <String> parameters = Linq2.ToArray(SplitMethodParameters( Code.Substring(indexOfBracketStart + 1, Code.Length - indexOfBracketStart - 2), AllObjects)); if (AllObjects) { parts.Add(new OnpMethodPart() { Part = EOnpMethodPart.METHOD_NAME, Code = methodName }); parts.Add(new OnpMethodPart() { Part = EOnpMethodPart.BRACKET, Code = "(" }); } foreach (String parameter in parameters) { parts.Add(new OnpMethodPart() { Part = parameter == "," ? EOnpMethodPart.COMA : EOnpMethodPart.PARAMETER, Code = parameter }); } if (AllObjects) { parts.Add(new OnpMethodPart() { Part = EOnpMethodPart.BRACKET, Code = ")" }); } } // global method invoke else if (indexOfMethodInvoke < 0 && indexOfBracketStart >= 0 && indexOfBracketEnd >= 0) { String methodName = Code.Substring(0, indexOfBracketStart).Trim(); IList <String> parameters = Linq2.ToArray(SplitMethodParameters( //Code.Substring(indexOfBracketStart + 1, Code.Length - indexOfBracketStart - 2), AllObjects). Code.Substring(indexOfBracketStart + 1, indexOfBracketEnd - indexOfBracketStart - 1), AllObjects)); parameters = parameters; if (AllObjects) { parts.Add(new OnpMethodPart() { Part = EOnpMethodPart.METHOD_NAME, Code = methodName }); parts.Add(new OnpMethodPart() { Part = EOnpMethodPart.BRACKET, Code = "(" }); } foreach (String parameter in parameters) { parts.Add(new OnpMethodPart() { Part = parameter == "," ? EOnpMethodPart.COMA : EOnpMethodPart.PARAMETER, Code = parameter }); } if (AllObjects) { parts.Add(new OnpMethodPart() { Part = EOnpMethodPart.BRACKET, Code = ")" }); } } return(parts); }