/// <summary> /// Receive LexerResult and Parse asynchronously, order of Index will be checked. /// </summary> /// <param name="lexerResult">The Result of Lexer</param> public async Task ParseLexUnitAsync(LexerResult lexerResult) { //check the order if (lexerResult.Index != index) { throw new ParseIndexException(index, lexerResult.Index, "Index Error: Index should be " + index + " instead of " + lexerResult.Index); } //transfer to parse unit ParseUnit parseUnit = new ParseUnit(lexerResult.Name, null, lexerResult.Position, lexerResult.Value, null); //to parse it index++;// move to next for sync await JoinParse(parseUnit, lexerResult.Index); }
/// <summary> /// Receive LexerResult and Parse synchronously, order of Index will be check. /// </summary> /// <param name="lexerResult">The Result of Lexer</param> public void ParseLexUnit(LexerResult lexerResult) { //check the order if (lexerResult.Index != index) { throw new ParseIndexException(index, lexerResult.Index, "Index Error: Index should be " + index + " instead of " + lexerResult.Index); } //transfer to parse unit ParseUnit parseUnit = new ParseUnit(lexerResult.Name, null, lexerResult.Position, lexerResult.Value, null); //to parse it index++; // move to next for sync door.GetIn(); // move to next for async, but no use in here. Parse(parseUnit); }
protected Task JoinParse(ParseUnit parseUnit, long index) { Task task = new Task(new Action <object>(x => Parse((ParseUnit)x)), parseUnit); while (door.Index < index) { } if (door.Index == index) { lock (door) { door.GetIn(); // move to next for async task.RunSynchronously(); // run it exclusively } } else { throw new AsyncIndexException(index, door.Index, "Async Index Error: Async Index should be " + index + " instead of " + door.Index + ". Check your code please."); } return(task); }
/// <summary> /// parsing entrance methods /// </summary> /// <param name="parseUnit">parse unit</param> protected virtual void Parse(ParseUnit parseUnit) { }
protected override void Parse(ParseUnit parseUnit) { }