// Load up the first source file public void Start(TextReader input, string filename) { _symbols.Find("$filename$").Value = TextValue.Create(filename); _inputpaths.Push(filename); PrepareTokens(input); Next(); }
///============================================================================================ /// /// Handle input files /// // Load up the first source file public void LoadSource(TextReader input, string filename) { Symbols.FindIdent("$filename$").Value = TextValue.Create(filename); _input = new ParserInput { InputText = input.ReadToEnd() }; }
// Load up the first source file internal void Start(TextReader input, string filename) { _symbols.Find("$filename$").Value = TextValue.Create(filename); _basepath = Path.GetDirectoryName(filename); _inputpaths.Push(filename); PrepareTokens(input); Next(); }
// translate string backslash to CRLF and grave to double-quote for displayable strings only protected TextValue FixText(TextValue text) { var newvalue = text.Value .Replace("\r\r", "\n") .Replace("\r", " ") .Replace('\\', '\n') .Replace('`', '"'); return(TextValue.Create(newvalue)); }
public override void Emit(Emitter e) { Logger.Assert(DataType.IsVariable || DataType == DataTypes.Void, DataType); e.OutLoad(TextValue.Create(UserFunc.DataType.Name)); foreach (var a in Arguments) { a.Emit(e); } e.OutCall(Func, NumVarArgs); }
// Insert a file into this one // TODO: pass new input back up the tree public bool Include(string filename) { if (!File.Exists(filename)) { return(false); } using (StreamReader sr = File.OpenText(filename)) { NewInput = new ParserInput { Filename = filename, InputText = sr.ReadToEnd(), }; Symbols.FindIdent("$filename$").Value = TextValue.Create(filename); } return(true); }
// Insert a file into this one public bool Include(string input) { if (!File.Exists(input)) { return(false); } using (StreamReader sr = File.OpenText(input)) { _symbols.Find("$filename$").Value = TextValue.Create(input); _inputpaths.Push(input); Include(sr); _inputpaths.Pop(); _symbols.Find("$filename$").Value = TextValue.Create(_inputpaths.Peek()); } return(true); }
// Get symbol from token, add to symbol table as needed // Look for existing symbol in catalog and nested scopes // If not found, define according to lexer type internal Symbol GetSymbol(Token token) { // First look for existing symbol Symbol sym; if (token.IsDefinable) { sym = Find(token.Value); if (sym != null) { while (sym.Atom == Atoms.ALIAS) { sym = sym.Link; } return(sym); } } // source code line token masquerades as another eol if (token.TokenType == TokenTypes.LINE) { return(Find(Token.EolName)); } // Create new symbol from token if (token.TokenType == TokenTypes.Number || token.TokenType == TokenTypes.HexNumber) { sym = MakeLiteral(NumberValue.Create(token.GetNumber() ?? Decimal.Zero)); } else if (token.TokenType == TokenTypes.Time) { sym = MakeLiteral(TimeValue.Create(token.GetTime() ?? DateTime.MinValue)); } else if (token.TokenType == TokenTypes.Identifier || token.TokenType == TokenTypes.IdLit) { sym = MakeIdent(); } else if (token.TokenType == TokenTypes.Binary) { sym = MakeLiteral(BinaryValue.Create(token.GetBinary())); } else { sym = MakeLiteral(TextValue.Create(token.Value)); } // note: only names for those we might define sym.Name = token.Value; return(sym); }
// Insert a file into this one internal bool Include(string filename) { var input = filename; if (!File.Exists(input)) { input = Path.Combine(_basepath, filename); if (!File.Exists(input)) { return(false); } } using (StreamReader sr = File.OpenText(input)) { _symbols.Find("$filename$").Value = TextValue.Create(filename); _inputpaths.Push(input); Include(sr); _inputpaths.Pop(); _symbols.Find("$filename$").Value = TextValue.Create(_inputpaths.Peek()); } return(true); }
public AstLiteral Text(string value) { return(LitValue(TextValue.Create(value))); }
GameDef Init() { Board = BoardDef.Create(null); // FIX:??? SetProperty("title", TextValue.Create("Unknown")); return(this); }
// Load and initialise the symbol table void AddSymbols() { AddSym(Token.EolName, Atoms.EOL); AddSym(Token.EofName, Atoms.EOF); AddSym("(", Atoms.LP); AddSym(")", Atoms.RP); AddSym("[", Atoms.LB); AddSym("]", Atoms.RB); AddSym("{", Atoms.LC); AddSym("}", Atoms.RC); AddSym(",", Atoms.SEP); AddSym(".", Atoms.DOT); AddSym("?", Atoms.QUERY); AddSym("$", Atoms.DOLLAR); AddSym("%", Atoms.PERCENT); AddSym(":", Atoms.COLON); AddSym("=>", Atoms.RA); AddSym(":=", Atoms.LA); AddSym("do", Atoms.DO); AddSym("def", Atoms.DEF); AddLiteral("true", BoolValue.True, DataTypes.Bool); AddLiteral("false", BoolValue.False, DataTypes.Bool); AddLiteral("$lineno$", NumberValue.Zero, DataTypes.Number); AddLiteral("$filename$", TextValue.Empty, DataTypes.Text); AddIdent("csv", SymKinds.SOURCE, TextValue.Create("csv"), DataTypes.Text); AddIdent("txt", SymKinds.SOURCE, TextValue.Create("txt"), DataTypes.Text); AddIdent("sql", SymKinds.SOURCE, TextValue.Create("sql"), DataTypes.Text); AddIdent("con", SymKinds.SOURCE, TextValue.Create("con"), DataTypes.Text); AddIdent("file", SymKinds.SOURCE, TextValue.Create("file"), DataTypes.Text); AddIdent("oledb", SymKinds.SOURCE, TextValue.Create("oledb"), DataTypes.Text); AddIdent("odbc", SymKinds.SOURCE, TextValue.Create("odbc"), DataTypes.Text); AddOperator("not", Atoms.NOT, 1, 9, DataTypes.Bool, "Not"); AddOperator("**", Atoms.SYMBOL, 2, 9, DataTypes.Number, "Pow"); AddOperator("u-", Atoms.MINUS, 1, 8, DataTypes.Number, "Neg"); AddFoldableOp("*", Atoms.STAR, 2, 7, DataTypes.Number, FoldableFlags.ANY, FoldSeeds.ONE, "Multiply"); AddFoldableOp("/", Atoms.SYMBOL, 2, 7, DataTypes.Number, FoldableFlags.ORDER, FoldSeeds.ONE, "Divide"); AddOperator("div", Atoms.IDENT, 2, 7, DataTypes.Number, "Div"); AddOperator("mod", Atoms.IDENT, 2, 7, DataTypes.Number, "Mod"); AddFoldableOp("+", Atoms.PLUS, 2, 6, DataTypes.Number, FoldableFlags.ANY, FoldSeeds.ZERO, "Add"); AddFoldableOp("-", Atoms.MINUS, 2, 6, DataTypes.Number, FoldableFlags.ORDER, FoldSeeds.ZERO, "Subtract"); AddFoldableOp("&", Atoms.SYMBOL, 2, 5, DataTypes.Text, FoldableFlags.ORDER, FoldSeeds.NUL, "Concat"); AddOperator("=", Atoms.SYMBOL, 2, 4, DataTypes.Bool, "Eq"); AddOperator("<>", Atoms.SYMBOL, 2, 4, DataTypes.Bool, "Ne"); AddOperator(">", Atoms.SYMBOL, 2, 4, DataTypes.Bool, "Gt"); AddOperator(">=", Atoms.SYMBOL, 2, 4, DataTypes.Bool, "Ge"); AddOperator("<", Atoms.SYMBOL, 2, 4, DataTypes.Bool, "Lt"); AddOperator("<=", Atoms.SYMBOL, 2, 4, DataTypes.Bool, "Le"); AddOperator("=~", Atoms.SYMBOL, 2, 4, DataTypes.Bool, "Match"); // These are overloaded by bit operations on integers AddFoldableOp("and", Atoms.IDENT, 2, 3, DataTypes.Unknown, FoldableFlags.ANY, FoldSeeds.TRUE, "And,BitAnd"); AddFoldableOp("or", Atoms.IDENT, 2, 2, DataTypes.Unknown, FoldableFlags.ANY, FoldSeeds.FALSE, "Or,BitOr"); AddFoldableOp("xor", Atoms.IDENT, 2, 2, DataTypes.Unknown, FoldableFlags.ANY, FoldSeeds.FALSE, "Xor,BitXor"); AddOperator("sub", Atoms.IDENT, 2, 4, DataTypes.Bool, "Subset"); AddOperator("sup", Atoms.IDENT, 2, 4, DataTypes.Bool, "Superset"); AddOperator("sep", Atoms.IDENT, 2, 4, DataTypes.Bool, "Separate"); AddFunction("db", Atoms.IDENT, 3, DataTypes.Void, CallKinds.FUNC, "Import", SymKinds.DB); AddFunction(Symbol.Assign, Atoms.NUL, 1, DataTypes.Void, CallKinds.FUNC, "Assign"); AddFunction(Symbol.Defer, Atoms.NUL, 1, DataTypes.Void, CallKinds.FUNC, "Defer"); AddFunction(Symbol.DoBlock, Atoms.NUL, 1, DataTypes.Any, CallKinds.FUNC, "DoBlock"); AddFunction(Symbol.Invoke, Atoms.NUL, 2, DataTypes.Any, CallKinds.VFUNCT, "Invoke"); AddFunction(Symbol.Lift, Atoms.NUL, 1, DataTypes.Void, CallKinds.FUNC, "Lift"); AddFunction(Symbol.Project, Atoms.NUL, 2, DataTypes.Table, CallKinds.VFUNC, "Project"); AddFunction(Symbol.Rename, Atoms.NUL, 2, DataTypes.Table, CallKinds.VFUNC, "Rename"); AddFunction(Symbol.Row, Atoms.NUL, 2, DataTypes.Row, CallKinds.VFUNC, "Row"); AddFunction(Symbol.Restrict, Atoms.NUL, 2, DataTypes.Table, CallKinds.VFUNC, "Restrict"); AddFunction(Symbol.Transform, Atoms.NUL, 2, DataTypes.Table, CallKinds.VFUNC, "Transform"); AddFunction(Symbol.TransAgg, Atoms.NUL, 2, DataTypes.Table, CallKinds.VFUNC, "TransAgg"); AddFunction(Symbol.TransOrd, Atoms.NUL, 2, DataTypes.Table, CallKinds.VFUNC, "TransOrd"); AddFunction(Symbol.Table, Atoms.NUL, 2, DataTypes.Table, CallKinds.VFUNC, "Table"); AddFunction(Symbol.UpdateJoin, Atoms.NUL, 3, DataTypes.Bool, CallKinds.FUNC, "UpdateJoin"); AddFunction(Symbol.UpdateTransform, Atoms.NUL, 3, DataTypes.Bool, CallKinds.VFUNC, "UpdateTrans"); AddFunction(Symbol.UserSelector, Atoms.NUL, 2, DataTypes.User, CallKinds.VFUNCT, "UserSelector"); AddFoldableFunction("max", Atoms.IDENT, 2, DataTypes.Ordered, CallKinds.FUNC, FoldableFlags.ANY, FoldSeeds.MIN, "Max"); AddFoldableFunction("min", Atoms.IDENT, 2, DataTypes.Ordered, CallKinds.FUNC, FoldableFlags.ANY, FoldSeeds.MAX, "Min"); AddFunction("fold", Atoms.IDENT, 0, DataTypes.Unknown, CallKinds.FUNC, "Fold", SymKinds.FOLD); AddFunction("cfold", Atoms.IDENT, 2, DataTypes.Unknown, CallKinds.FUNC, "CumFold", SymKinds.FOLD); AddFunction("if", Atoms.IDENT, 3, DataTypes.Unknown, CallKinds.FUNC, "If", SymKinds.IF); AddFunction("recurse", Atoms.IDENT, 2, DataTypes.Unknown, CallKinds.FUNC, "Recurse", SymKinds.RECURSE); AddFunction("ord", Atoms.IDENT, 0, DataTypes.Number, CallKinds.LFUNC, "Ordinal"); AddFunction("ordg", Atoms.IDENT, 0, DataTypes.Number, CallKinds.LFUNC, "OrdinalGroup"); AddFunction("lead", Atoms.IDENT, 0, DataTypes.Unknown, CallKinds.LFUNC, "ValueLead", SymKinds.VALUE); AddFunction("lag", Atoms.IDENT, 0, DataTypes.Unknown, CallKinds.LFUNC, "ValueLag", SymKinds.VALUE); AddFunction("nth", Atoms.IDENT, 0, DataTypes.Unknown, CallKinds.LFUNC, "ValueNth", SymKinds.VALUE); AddFunction("rank", Atoms.IDENT, 0, DataTypes.Unknown, CallKinds.LFUNC, "Rank", SymKinds.RANK); AddDyadic("join", Atoms.IDENT, 2, 4, JoinOps.JOIN, "DyadicJoin"); AddDyadic("compose", Atoms.IDENT, 2, 4, JoinOps.COMPOSE, "DyadicJoin"); AddDyadic("divide", Atoms.IDENT, 2, 4, JoinOps.DIVIDE, "DyadicJoin"); AddDyadic("rdivide", Atoms.IDENT, 2, 4, JoinOps.RDIVIDE, "DyadicJoin"); AddDyadic("semijoin", Atoms.IDENT, 2, 4, JoinOps.SEMIJOIN, "DyadicJoin"); AddDyadic("rsemijoin", Atoms.IDENT, 2, 4, JoinOps.RSEMIJOIN, "DyadicJoin"); AddDyadic("ajoin", Atoms.IDENT, 2, 4, JoinOps.ANTIJOIN, "DyadicAntijoin"); AddDyadic("rajoin", Atoms.IDENT, 2, 4, JoinOps.RANTIJOIN, "DyadicAntijoin"); AddDyadic("ajoinl", Atoms.IDENT, 2, 4, JoinOps.ANTIJOINL, "DyadicAntijoin"); AddDyadic("rajoinr", Atoms.IDENT, 2, 4, JoinOps.RANTIJOINR, "DyadicAntijoin"); AddDyadic("union", Atoms.IDENT, 2, 4, JoinOps.UNION, "DyadicSet"); AddDyadic("intersect", Atoms.IDENT, 2, 4, JoinOps.INTERSECT, "DyadicSet"); AddDyadic("symdiff", Atoms.IDENT, 2, 4, JoinOps.SYMDIFF, "DyadicSet"); AddDyadic("minus", Atoms.IDENT, 2, 4, JoinOps.MINUS, "DyadicSet"); AddDyadic("rminus", Atoms.IDENT, 2, 4, JoinOps.RMINUS, "DyadicSet"); AddAlias("matching", "semijoin"); AddAlias("notmatching", "ajoin"); AddAlias("joinlr", "compose"); AddAlias("joinlc", "matching"); AddAlias("joinl", "divide"); AddAlias("joincr", "rsemijoin"); AddAlias("joinr", "rdivide"); }
public void SetOption(string name, string value) { _gamedef.SetProperty(name, TextValue.Create(value)); CreateGameModel(); }