private void LoadState(int state, MetaDslx.Languages.Soal.Syntax.InternalSyntax.SoalLexer lexer) { LanguageScannerState value = default(LanguageScannerState); this.states.TryGetValue(state, out value); value.Restore(lexer); }
public LanguageScannerState(MetaDslx.Languages.Soal.Syntax.InternalSyntax.SoalLexer lexer) { this._mode = lexer.CurrentMode; this._modeStack = lexer.ModeStack.Count > 0 ? new List <int>(lexer.ModeStack) : null; this._type = lexer.Type; this._channel = lexer.Channel; this._state = lexer.State; }
public void SetSource(string source, int offset) { //if (this.currentOffset != offset || this.currentLine != source) { this.currentOffset = offset; this.currentLine = source; this.lexer = null; } }
private int SaveState(MetaDslx.Languages.Soal.Syntax.InternalSyntax.SoalLexer lexer) { int result = 0; LanguageScannerState state = new LanguageScannerState(lexer); if (!this.inverseStates.TryGetValue(state, out result)) { result = ++lastState; this.states.Add(result, state); this.inverseStates.Add(state, result); } return(result); }
public void Restore(MetaDslx.Languages.Soal.Syntax.InternalSyntax.SoalLexer lexer) { lexer.CurrentMode = this._mode; lexer.ModeStack.Clear(); if (this._modeStack != null) { foreach (var item in this._modeStack) { lexer.ModeStack.Push(item); } } lexer.Type = this._type; lexer.Channel = this._channel; lexer.State = this._state; }
public bool ScanTokenAndProvideInfoAboutIt(TokenInfo tokenInfo, ref int state) { try { if (this.lexer == null) { this.lexer = new MetaDslx.Languages.Soal.Syntax.InternalSyntax.SoalLexer(new AntlrInputStream(this.currentLine + "\r\n")); } this.LoadState(state, this.lexer); IToken token = this.lexer.NextToken(); int tokenType = (int)this.syntaxFacts.GetTokenKind(token.Type); if (tokenType == 0) { tokenType = (int)this.syntaxFacts.GetModeTokenKind(this.lexer.CurrentMode); } if (tokenType >= 0 && tokenType < SoalLanguageConfig.Instance.ColorableItems.Count) { SoalLanguageColorableItem colorItem = SoalLanguageConfig.Instance.ColorableItems[tokenType]; tokenInfo.Token = token.Type; tokenInfo.Type = colorItem.TokenType; tokenInfo.Color = (TokenColor)tokenType; tokenInfo.Trigger = TokenTriggers.None; } else { tokenInfo.Token = token.Type; tokenInfo.Type = TokenType.Text; tokenInfo.Color = TokenColor.Text; tokenInfo.Trigger = TokenTriggers.None; } if (string.IsNullOrEmpty(token.Text) || this.currentOffset >= this.currentLine.Length) { return(false); } tokenInfo.StartIndex = this.currentOffset; this.currentOffset += token.Text.Length; tokenInfo.EndIndex = this.currentOffset - 1; state = this.SaveState(lexer); return(true); } catch (Exception) { return(false); } }