// Recursively gets prefix operators from the list private static List <CLObjectPiece> RecursiveGetPrefixOpers(string input, int pos) { if (PrefixOperators.ContainsKey(input)) { return(CLUtils.ListOfOne(new CLObjectPiece(input, CLObjectPieceType.PrefixOperator, pos))); } for (int i = 1; i < input.Length; i++) { string thisOper = input[0..i];
public void DBInit() { if (File.Exists(config.DatabaseAddress)) { DBDelete(); } using (var context = new Context(config)) { try { string createScript = CLUtils.ReadResource("Premy.Chatovatko.Client.Libs.Database.SqlScripts.sqlBuild.sqll"); context.Database.ExecuteSqlCommand(createScript); } catch (Exception ex) { DBDelete(); throw new ChatovatkoException(this, ex, "Initialization of database failed"); } } logger.Log(this, "Database initialized"); }
public static List <CLObjectPiece> Lex(string input) { List <CLObjectPiece> ret = new List <CLObjectPiece>(); string last = ""; int pos = 0; while (input.Length > 0) { int move = 0; Match match = null; // See if it's whitespace before any tokens. if (CLUtils.RegexMatches(rgxWhitespace, input, out match)) { move = match.Length; } // Is it a number? else if (CLUtils.RegexMatches(rgxNumber, input, out match)) { last = match.Value; ret.Add(new CLObjectPiece(last, CLObjectPieceType.Number, pos)); move = match.Length; } // Is it a separator? else if (CLUtils.RegexMatches(rgxSeparator, input, out match)) { last = match.Value; ret.Add(new CLObjectPiece(last, CLObjectPieceType.Spacer, pos)); move = match.Length; } // Is it a comment? else if (CLUtils.RegexMatches(rgxComment, input, out match)) { move = match.Length; // comments aren't included in the syntax tree } // Is it a name? else if (CLUtils.RegexMatches(rgxName, input, out match)) { last = match.Value; ret.Add(new CLObjectPiece(last, CLObjectPieceType.FunctionName, pos)); move = match.Length; } // ... Is it an operator, or group thereof? else if (CLUtils.RegexMatches(rgxOperator, input, out match)) { string opers = rgxWhitespaceReplace.Replace(match.Value, ""); move = match.Length; string next = ""; if (input.Length > move) { next = input.Substring(move, 1); } // If the operator immediately follows a separator, // it must be a prefix operator. bool prefix = (last == "" || last == "[" || last == "," || last == "("); // If the operator immediately precedes a separator, // it must be a postfix operator. bool postfix = (next == "" || next == "]" || next == "," || next == ")" || next == "}"); // It can't be both (as in the only thing between two separators). if (prefix && postfix) { throw new CLSyntaxException("A value was expected between brackets.", pos); } // There might be multiple operators in a row, so let's be sure to get them all. List <CLObjectPiece> pcs = CLOperators.GetOpers(opers, prefix, postfix, pos); ret.AddRange(pcs); last = match.Value; } // No match? That's a paddlin. else { throw new CLSyntaxException("I don't know what this means.", pos); } // Discard what we've found. input = input.Substring(move); pos += move; } return(ret); }