public void SetSource(string source, int offset) { //if (this.currentOffset != offset || this.currentLine != source) { this.currentOffset = offset; this.currentLine = source; this.lexer = null; } }
public bool ScanTokenAndProvideInfoAboutIt(TokenInfo tokenInfo, ref int state) { try { if (this.lexer == null) { this.lexer = new MetaDslx.Compiler.MetaModelLexer(new AntlrInputStream(this.currentLine + "\r\n")); } this.LoadState(state, this.lexer); IToken token = this.lexer.NextToken(); int tokenType = -1; foreach (var modeAnnot in this.modeAnnotations) { if (this.lexer.CurrentMode >= modeAnnot.First && this.lexer.CurrentMode <= modeAnnot.Last) { tokenType = modeAnnot.Kind; break; } } foreach (var syntaxAnnot in this.syntaxAnnotations) { if (token.Type >= syntaxAnnot.First && token.Type <= syntaxAnnot.Last) { tokenType = syntaxAnnot.Kind; break; } } if (tokenType >= 1 && tokenType <= MetaModelLanguageConfig.Instance.ColorableItems.Count) { MetaModelLanguageColorableItem colorItem = MetaModelLanguageConfig.Instance.ColorableItems[tokenType - 1]; 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; } }