public List <ImportedScript> Merge(IEnumerable <string> importPaths) { if (!importPaths.Any()) { throw new InvalidOperationException("ImportMerger requires at least one path to import."); } // step 2 // merge the code in such a way that it can be parsed and interpreted (what a novel idea..) // TODO: handle imports that cannot be read directly (maybe external libraries in the form of dlls or w/e) var importedScripts = new List <ImportedScript>(); foreach (var importPath in importPaths) { var source = File.ReadAllText(importPath); var reader = new ScriptReader(source, importPath); var importLexer = new ImportLexer(reader, new CommonLexer(reader)); var afterImportsPosition = importLexer.GetIndexAfterImports(); var codeWithoutImports = source.Substring(afterImportsPosition); var imported = new ImportedScript(importPath, codeWithoutImports, reader.Line); importedScripts.Add(imported); } return(importedScripts); }
//销毁实例 public static void DestoryInstance() { if (instance != null) { instance = null; } }
public SqlPlusScript(IScript script) { _script = script; _wrappedScriptPath = System.IO.Path.GetTempFileName(); var reader = new ScriptReader(); using (var fileStream = File.OpenWrite(_wrappedScriptPath)) { using (var tempFile = new StreamWriter(fileStream, UTF8.WithoutByteOrderMark)) { tempFile.WriteLine("SET ECHO ON"); tempFile.WriteLine("WHENEVER SQLERROR EXIT SQL.SQLCODE"); foreach (var scriptLine in reader.GetContents(_script.Path)) { tempFile.WriteLine(scriptLine); } tempFile.WriteLine("COMMIT;"); tempFile.WriteLine("EXIT"); } } }
public static IValue Eval(string code, ScriptEnvironment environment = null) { var reader = new ScriptReader(code, "eval"); var lexer = new ScriptLexer(reader, new CommonLexer(reader)); var parser = new Parser(lexer); var ast = parser.Parse(); if (environment == null) { environment = new ScriptEnvironment(new OperationCodeFactory(), new ValueFactory()); environment.AddClassesDerivedFromClassInAssembly(typeof(Eilang)); environment.AddExportedFunctionsFromAssembly(typeof(Eilang)); environment.AddExportedModulesFromAssembly(typeof(Eilang)); } Compiler.Compile(environment, ast #if LOGGING , logger: Console.Out #endif ); var interpreter = new Interpreter(environment #if LOGGING , logger: Console.Out #endif ); return(interpreter.Interpret()); }
public void InsertAppliedScript(DatabaseVersion version, string schema, IScript script, IScript rollbackScript = null) { var reader = new ScriptReader(); try { _connection.Execute(@"INSERT INTO {0}.appliedscripts (id, version_id, forward_script, backward_script) VALUES ({0}.appliedscripts_seq.nextval, (SELECT id as version_id FROM {0}.versions WHERE version = :version), :forwardScript, :rollbackScript)".FormatWith(schema), new { version = version.Version, forwardScript = string.Join(Environment.NewLine, reader.GetContents(script.Path)), rollbackScript = rollbackScript.IsNull() ? null : string.Join(Environment.NewLine, reader.GetContents(rollbackScript.Path)) }); } catch (OracleException oracleException) { if (oracleException.IsFor(OracleErrors.TableOrViewDoesNotExist)) { Output.Warn("Applied scripts table in schema '{0}' could not be found, applied script could not be recorded.".FormatWith(schema)); return; } throw; } }
public override void Initialize() { ScreenArea = new Rectangle(0,0,InaneSubterra.graphics.GraphicsDevice.Viewport.Width, InaneSubterra.graphics.GraphicsDevice.Viewport.Height); scriptReader = new ScriptReader(); splashColor = Color.Black; }
//Load public override void Load() { base.Load(); //シーンネームのLoadは呼び出し元(Operation)で先に行っていることに注意 //戦闘パートの盤面でロード必要なものをJSONから引っ張り、各static変数に代入 //戦闘パートの盤面でセーブ必要なものをJSONに。(デシリアライズは下で行う) //MapClassへ書き込み Mapclass.maporiginx = maporiginx; Mapclass.maporiginy = maporiginy; Mapclass.mapxnum = mapxnum; Mapclass.mapynum = mapynum; //BattleValへ書き込み //mapdataのデシリアライズ mapdata = ScriptReader.LoadMapSaveData(mapsavedata); BattleVal.mapdata = mapdata; BattleVal.unitlist = unitlist; BattleVal.id2index = id2index; BattleVal.turn = turn; BattleVal.turnplayer = turnplayer; BattleVal.actions = actions; Operation.used_event = used_event; }
//获取实例 public static ScriptReader GetInstance() { if (instance == null) { instance = new ScriptReader(); } return(instance); }
public static IScriptResource FromZipArchiveEntry(string archivePath, ZipArchiveEntry entry, bool userLoaded = false) { using var stream = entry.Open(); var origin = userLoaded ? ScriptResourceOrigin.User : ScriptResourceOrigin.Automatic; var keyframes = ScriptReader.Read(ScriptType.Funscript, stream); return(new ScriptResource(entry.Name, archivePath, keyframes, origin)); }
public static void BuildWorld(string script, out List <Error> errors) { World.Instance.Clear(); Instance.ClearState(); var tree = ScriptReader.MakeParseTree(script, out _); Instance.Visit(tree); errors = Instance.errors; }
void Load() { var gotOtherLines = false; using (var reader = File.OpenText(Path)) { var lines = ScriptReader.ReadLines(reader); foreach (var line in lines) { if (line.Text.StartsWith("///")) { var sectionName = line.Text.Substring(3).Trim(); var sectionLines = ScriptReader.ReadSection(lines); switch (sectionName) { case "extension": LoadExtension(sectionLines); break; case "imports": if (gotOtherLines) { throw new InvalidOperationException("imports section must appear before any commands or script content"); } LoadImports(sectionLines); if (MissingDependencies.Count > 0) { return; } break; case "usings": if (gotOtherLines || _commands.Count > 0) { throw new InvalidOperationException("usings section must appear before any commands or script content"); } if (_imports.Count == 0) { throw new InvalidOperationException("imports section must appear before usings"); } LoadUsings(sectionLines); break; case "command": LoadCommand(sectionLines); break; } } else if (line.Text != "") { gotOtherLines = true; } } } }
public static Thing BuildBreed(string script, out List <Error> errors) { Instance.ClearState(); Instance.buildBreedOnly = true; var parser = ScriptReader.GetParserForScript(script, out _); var breedTree = parser.baseDefinition(); Instance.Visit(breedTree); errors = Instance.errors; return(Instance.currentBreed); }
public static void ReplMode() { var environment = new ReplEnvironment(new OperationCodeFactory(), new ValueFactory()); var interpreter = new ReplInterpreter(); environment.AddClassesDerivedFromClassInAssembly(typeof(Eilang)); environment.AddExportedFunctionsFromAssembly(typeof(Eilang)); environment.AddExportedModulesFromAssembly(typeof(Eilang)); while (true) { Console.Write(">"); var code = Console.ReadLine() ?? ""; if (string.IsNullOrWhiteSpace(code)) { continue; } try { code = Simplify(code); var reader = new ScriptReader(code, "repl"); var lexer = new ScriptLexer(reader, new CommonLexer(reader)); var parser = new Parser(lexer); var ast = parser.Parse(); Compiler.Compile(environment, ast); var eval = interpreter.Interpret(environment); if (eval.Type != EilangType.Void) { ExportedFunctions.PrintLine(new State(environment, null, null, null, null, new ValueFactory()), Arguments.Create(eval, "eval")); } } catch (ExitException e) { if (!string.IsNullOrWhiteSpace(e.Message)) { var oldColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(e.Message); Console.ForegroundColor = oldColor; } Environment.Exit(e.ExitCode); } catch (ErrorMessageException e) { Program.LogLine(ConsoleColor.Red, e.Message); } catch (Exception e) { Console.WriteLine(e); } } }
/// <summary>スクリプトの実行を要求します。</summary> /// <param name="scriptName">実行してほしいスクリプトの名前</param> /// <param name="requestPriority">実行の優先度</param> public void Request(string scriptName, ScriptPriority requestPriority) { if (requestPriority > _currentPriority) { RequestedScriptName = scriptName; RequestedScriptPriority = requestPriority; IsScriptRequested = true; ScriptReader.CancelRead(); ScriptRequested?.Invoke(this, EventArgs.Empty); } }
void Start() { _scriptManager = FindObjectOfType <ScriptManager> (); _scriptReader = FindObjectOfType <ScriptReader> (); _voiceProcessor = FindObjectOfType <VoiceProcessor> (); _director = FindObjectOfType <Director> (); _player = FindObjectOfType <Player> (); _responseChecker = FindObjectOfType <ScriptResponseChecker> (); _scoreManager = FindObjectOfType <ScoreManager> (); _scriptManager.LoadScript(SelectedScriptIndex); }
// Loads a script file with the given encoding and script reader object. public static void LoadScript(string assetName, ScriptReader sr, Encoding encoding) { try { Stream stream = TitleContainer.OpenStream(contentManager.RootDirectory + "/" + assetName); StreamReader reader = new StreamReader(stream, encoding); sr.ReadScript(reader, assetName); stream.Close(); } catch (FileNotFoundException) { Console.WriteLine("Error loading file \"" + assetName + "\""); } }
void Start() { currentForces = new float [] { 0f, 0f, 0f, 0f }; rb = GetComponent <Rigidbody>(); if (events == null) { events = new DroneEvent(); } sr = new ScriptReader(); //events.AddListener(TestEventListener); }
public static IScriptResource FromFileInfo(FileInfo file, bool userLoaded = false) { if (!file.Exists) { return(null); } var path = file.FullName; var origin = userLoaded ? ScriptResourceOrigin.User : ScriptResourceOrigin.Automatic; var keyframes = ScriptReader.Read(ScriptType.Funscript, File.ReadAllBytes(path)); return(new ScriptResource(Path.GetFileName(path), Path.GetDirectoryName(path), keyframes, origin)); }
/// <inheritdoc /> public override void Invoke() { var negate = ActionName == "if-neq"; if ((!negate && ArgumentA != ArgumentB) || (negate && ArgumentA == ArgumentB)) { return; } foreach (var nestedXmlElement in NestedXmlElements) { ScriptReader.ExecuteElement(nestedXmlElement, DataContext, ParentAction); } }
public static IValue RunFile(string path, ScriptEnvironment environment = null) { var imports = new ImportResolver().ResolveImportsFromFile(path); var code = new ImportMerger().Merge(imports); ILexer finalLexer; if (code.Count > 1) { var lexers = new List <ILexer>(); foreach (var imported in code) { var reader = new ScriptReader(imported.Code, imported.Path, imported.LineOffset); var lexer = new ScriptLexer(reader, new CommonLexer(reader)); lexers.Add(lexer); } finalLexer = new MultifileLexer(lexers); } else { var imported = code.First(); var reader = new ScriptReader(imported.Code, imported.Path, imported.LineOffset); finalLexer = new ScriptLexer(reader, new CommonLexer(reader)); } var parser = new Parser(finalLexer); var ast = parser.Parse(); if (environment == null) { environment = new ScriptEnvironment(new OperationCodeFactory(), new ValueFactory()); environment.AddClassesDerivedFromClassInAssembly(typeof(Eilang)); environment.AddExportedFunctionsFromAssembly(typeof(Eilang)); environment.AddExportedModulesFromAssembly(typeof(Eilang)); } Compiler.Compile(environment, ast #if LOGGING , logger: Console.Out #endif ); var interpreter = new Interpreter(environment #if LOGGING , logger: Console.Out #endif ); return(interpreter.Interpret()); }
/// <summary> /// 02.载入脚本 /// </summary> /// <param name="id">编号</param> public void LoadScript(int id) { if (scriptLoaded) { reader.Close(); } scriptLoaded = true; index = id; var opcodes = (Dictionary <byte, ScriptOpcode>)ScriptUtil.Clone(bytesToOpcodeDict); reader = new ScriptReader(ScriptFilename(index), opcodes, scriptVersion); reader.ReadScript(); // 读入整个脚本 CurrentCodeID = 0; }
public static void Init(string path = ".", string scripts = "script", string cards = "cards.cdb") { PathManager.Init(path, scripts, cards); CardsManager.Init(cards); m_buffer = Marshal.AllocHGlobal(65536); m_creader = MyCardReader; m_sreader = MyScriptReader; m_msghandler = MyMessageHandler; set_card_reader(m_creader); set_script_reader(m_sreader); set_message_handler(m_msghandler); }
public static List <Error> CheckErrors(string script, Scope scope = null) { Instance.scope = scope ?? new Scope(); Instance.errors = new List <Error>(); var tree = ScriptReader.MakeParseTree(script, out var syntaxErrors); if (syntaxErrors.Count > 0) { return(syntaxErrors); } Instance.Visit(tree); return(Instance.errors); }
public static List <Error> CheckBreedScriptErrors(string script, Scope scope = null) { Instance.scope = scope ?? new Scope(); Instance.errors = new List <Error>(); var parser = ScriptReader.GetParserForScript(script, out var syntaxErrors); var breedTree = parser.breedScript(); if (syntaxErrors.Count > 0) { return(syntaxErrors); } Instance.Visit(breedTree); return(Instance.errors); }
// Use this for initialization void Start() { //ApplicationChrome.statusBarState = ApplicationChrome.States.Visible; characters[0] = GameObject.Find("left").GetComponent <Character>(); characters[1] = GameObject.Find("center").GetComponent <Character>(); characters[2] = GameObject.Find("right").GetComponent <Character>(); message = GameObject.Find("message").GetComponent <Message>(); speaker = GameObject.Find("speaker").GetComponent <Text>(); backGround = GameObject.Find("bg").GetComponent <Image>(); backGround2 = GameObject.Find("bg2").GetComponent <Image>(); reader = new ScriptReader(); Click(); }
//シリアライズ public override void OnBeforeSerialize() { //パーティメンバーとかのシリアライズは親が行う base.OnBeforeSerialize(); //mapdataのシリアライズ mapsavedata = ScriptReader.CreateMapSaveData(mapdata); //unitlistのシリアライズ unitsavelist = new List <UnitSaveData>(); unitdirection = new List <Vector3>(); foreach (Unitdata unit in unitlist) { unitsavelist.Add(new UnitSaveData(unit)); unitdirection.Add(unit.gobj.transform.forward); } //id2indexのシリアライズ id2indexkeys = new List <string>(); id2indexvalues = new List <UnitSaveData>(); foreach (KeyValuePair <string, Unitdata> kvp in id2index) { id2indexkeys.Add(kvp.Key); id2indexvalues.Add(new UnitSaveData(kvp.Value)); } //Action Stackのシリアライズ Stack <Action> temp = new Stack <Action>(); while (actions.Count > 0) { temp.Push(actions.Pop()); } actionslist = new List <ActionSaveData>(); while (temp.Count > 0) { actionslist.Add(new ActionSaveData(temp.Pop())); } //actionsを元に戻す foreach (ActionSaveData act in actionslist) { actions.Push(new Action(act, id2index)); } }
void Awake() { Scene._instance = this; Scene.list = this.transform.Find("List"); this.reader = new ScriptReader("script"); this.group = Scene.list.GetComponent <CanvasGroup>(); int num = Scene.list.transform.childCount; for (int i = 0; i < num; i++) { GameObject temp = Scene.list.transform.GetChild(i).gameObject; if (temp.activeSelf) { this.current = temp; break; } } }
public IEnumerable <string> ResolveImportsFromFile(string pathToMain) { // step 1 // read unique imports in code, add to list of new imports // recurse through all new imports and look for new unique imports // return an enumerable of unique imports var fileInfo = new FileInfo(pathToMain); var rootDirectory = fileInfo.DirectoryName; var fileName = fileInfo.Name; var check = new HashSet <string>(); var mainPath = ResolveImportPath(fileName.EndsWith(".ei") ? fileName : $"{fileName}.ei", rootDirectory); var allImports = new HashSet <string> { mainPath }; ResolveInner(mainPath); void ResolveInner(string path) { if (check.Contains(path)) { return; } check.Add(path); var code = GetCode(path); var reader = new ScriptReader(code, path); var lexer = new ImportLexer(reader, new CommonLexer(reader)); // maybe inject ImportResolver with a LexerFactory, // not really necessary at this point I feel var imports = lexer.GetImports(); foreach (var import in imports) { var canonicalized = ResolveImportPath(import.EndsWith(".ei") ? import : $"{import}.ei", path); allImports.Add(canonicalized); ResolveInner(canonicalized); } } return(allImports); }
public static void Init(string rootPath = ".", string scriptDirectory = "script", string databaseFile = "cards.cdb") { _rootPath = rootPath; _scriptDirectory = scriptDirectory; CardsManager.Init(Path.Combine(Path.GetFullPath(rootPath), databaseFile)); Duel.Duels = new Dictionary<IntPtr, Duel>(); _buffer = Marshal.AllocHGlobal(65536); _cardCallback = OnCardReader; _scriptCallback = OnScriptReader; _messageCallback = OnMessageHandler; set_card_reader(_cardCallback); set_script_reader(_scriptCallback); set_message_handler(_messageCallback); }
void Start() { LogSystem.InstallDefaultReactors(); _dataController = FindObjectOfType <DataController> (); _scriptReader = FindObjectOfType <ScriptReader> (); CredentialData serviceCredentials = _dataController.GetServiceCredentials(); ServiceCredential speechToTextCredential = serviceCredentials.speechToTextCredential; // Create credential and instantiate service Credentials credentials = new Credentials(speechToTextCredential.username, speechToTextCredential.password, speechToTextCredential.url); _speechToText = new SpeechToText(credentials); _speechToText.ProfanityFilter = false; Active = true; StartRecording(); }
/// <summary>ブロッキングしてスクリプトを実行します。</summary> /// <param name="scriptName">実行するスクリプト名</param> /// <param name="priority">スクリプトの優先度</param> public void Read(string scriptName, ScriptPriority priority) { try { _currentPriority = priority; ScriptReader.ReadAsync(GetScriptPath(scriptName)).Wait(); } catch (AggregateException ex) { if (ex.InnerExceptions.Count == 1 && ex.InnerExceptions[0] is OperationCanceledException) { } } finally { //待ち状態にしとかないとリクエストが通らない事に注意 _currentPriority = ScriptPriority.Idle; } }
public static void Init(string rootPath = ".", string scriptDirectory = "script", string databaseFile = "cards.cdb") { _rootPath = rootPath; _scriptDirectory = scriptDirectory; CardsManager.Init(Path.Combine(Path.GetFullPath(rootPath), databaseFile)); Duel.Duels = new Dictionary <IntPtr, Duel>(); _buffer = Marshal.AllocHGlobal(1024 * 128); // 128 KiB _cardCallback = OnCardReader; _scriptCallback = OnScriptReader; _messageCallback = OnMessageHandler; set_card_reader(_cardCallback); set_script_reader(_scriptCallback); set_message_handler(_messageCallback); }
/// <inheritdoc /> public override void Invoke() { if (!Regex.IsMatch(Name, @"^\w+$")) { throw new ScriptException("Invalid list name provided. Name cannot be empty and must contain only alphanumeric characters and underscores.", ActionXmlElement, "name"); } if (!DataContext.Lists.ContainsKey(Name)) { DataContext.Lists.Add(Name, new List <string>()); } ListValues = DataContext.Lists[Name]; foreach (var nestedXmlElement in NestedXmlElements) { ScriptReader.ExecuteElement(nestedXmlElement, DataContext, this); } }
public override void Initialize() { SequenceColors = new Color[] { Color.SpringGreen, Color.Red, new Color(1f,1f,1f, .5f), Color.DarkMagenta, Color.DarkOrange, Color.YellowGreen, Color.OrangeRed, new Color(.1f, .1f, .1f, 1f), Color.DarkOliveGreen, Color.MediumPurple }; crystals = new List<TitleScreenAnimation>(); ScreenArea = new Rectangle(0,0,InaneSubterra.graphics.GraphicsDevice.Viewport.Width, InaneSubterra.graphics.GraphicsDevice.Viewport.Height); titleColor = Color.Transparent; scriptReader = new ScriptReader(); }
public static extern void set_script_reader(ScriptReader f);
public override void Initialize() { // Set up the list of colors to be used as the player progresses through sequences. if (SequenceColors == null) { SequenceColors = new List<Color>() { new Color(), Color.Aquamarine, //Sequence 1: Curiosity Color.SpringGreen, //Sequence 2: Optimism Color.YellowGreen, //Sequence 3: Hope Color.DarkOliveGreen, //Sequence 4: Doubt Color.DarkOrange, //Sequence 5: Regret Color.OrangeRed, //Sequence 6: Fear Color.MediumPurple, //Sequence 7: Guilt Color.DarkMagenta, //Sequence 8: Despair Color.Red, //Sequence 9: Hate new Color(.1f, .1f, .1f, 1f), //Sequence 10: Introspection new Color(1f,1f,1f, .5f) //Sequence 0: Truth }; } // Set up the list of titles for the sequence if (SequenceTitles == null) { SequenceTitles = new List<string>() { "", "Curiosity", "Optimism", "Hope", "Doubt", "Denial", "Fear", "Guilt", "Despair", "Futility", "Introspection", "Truth" }; } // Set the sequence to 1. This has the effect of ignoring the first color in the Color list. CurrentSequence = 1; // Instantiate a new collision detection module collisionDetection = new CollisionDetection(this); // Instantiate a new gravity gravity = new Gravity(this); // Instantiate a new world generator worldGenerator = new WorldGenerator(this); // Create a new list to store the game objects gameObjects = new List<GameObject>(); sequenceText = new List<SequenceText>(); // Store the screen area Viewport view = InaneSubterra.graphics.GraphicsDevice.Viewport; ScreenArea = new Rectangle((int)Camera.X, (int)Camera.Y, view.Width, view.Height); scriptReader = new ScriptReader(); }