Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
 public void SetSource(string source, int offset)
 {
     //if (this.currentOffset != offset || this.currentLine != source)
     {
         this.currentOffset = offset;
         this.currentLine   = source;
         this.lexer         = null;
     }
 }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
0
 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);
     }
 }