当前位置: 首页>>代码示例>>C#>>正文


C# CompilerContext.CreateErrorTokenAndReportError方法代码示例

本文整理汇总了C#中CompilerContext.CreateErrorTokenAndReportError方法的典型用法代码示例。如果您正苦于以下问题:C# CompilerContext.CreateErrorTokenAndReportError方法的具体用法?C# CompilerContext.CreateErrorTokenAndReportError怎么用?C# CompilerContext.CreateErrorTokenAndReportError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CompilerContext的用法示例。


在下文中一共展示了CompilerContext.CreateErrorTokenAndReportError方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BeginFiltering

 public override IEnumerable<Token> BeginFiltering(CompilerContext context, IEnumerable<Token> tokens)
 {
     foreach (Token token in tokens) {
     if (!token.Terminal.IsSet(TermOptions.IsBrace)) {
       yield return token;
       continue;
     }
     //open brace symbol
     if (token.Terminal.IsSet(TermOptions.IsOpenBrace)) {
       _braces.Push(token);
       yield return token;
       continue;
     }
     //We have closing brace
     if (_braces.Count == 0) {
       yield return context.CreateErrorTokenAndReportError( token.Location, token.Text, "Unmatched closing brace '{0}'", token.Text);
       continue;
     }
     //check match
     Token last = _braces.Pop();
     if (last.AsSymbol.IsPairFor != token.AsSymbol) {
       yield return context.CreateErrorTokenAndReportError(token.Location, token.Text,
       "Unmatched closing brace '{0}' - expected '{1}'", last.AsSymbol.IsPairFor.Name);
       continue;
     }
     //everything is ok, there's matching brace on top of the stack
     Token.LinkMatchingBraces(last, token);
     context.CurrentParseTree.OpenBraces.Add(last);
     yield return token; //return this token
       }//foreach token
       yield break;
 }
开发者ID:TheByte,项目名称:sones,代码行数:32,代码来源:BraceMatchFilter.cs

示例2: TryMatch

 public override Token TryMatch(CompilerContext context, ISourceStream source)
 {
     Token result;
       if (context.ScannerState.Value != 0) {
     // we are continuing in line mode - restore internal env (none in this case)
     context.ScannerState.Value = 0;
       } else {
     //we are starting from scratch
     if (!BeginMatch(context, source)) return null;
       }
       result = CompleteMatch(context, source);
       if (result != null) return result;
       //if it is LineComment, it is ok to hit EOF without final line-break; just return all until end.
       if (_isLineComment)
     return new Token(this, source.TokenStart, source.GetLexeme(), null);
       if (context.Mode == CompileMode.VsLineScan)
     return CreateIncompleteToken(context, source);
       return context.CreateErrorTokenAndReportError(source.TokenStart, string.Empty, "Unclosed comment block");
 }
开发者ID:TheByte,项目名称:sones,代码行数:19,代码来源:CommentTerminal.cs

示例3: BeginFiltering

        public override IEnumerable<Token> BeginFiltering(CompilerContext context, IEnumerable<Token> tokens)
        {
            //TODO: fix this.
              // This is a temporary workaround, to "undo" the change to whitespace made by NewLineTerminal.
              // if we have both NewLineTerminal in the grammar and CodeOutlineFilter, then NewLines should be generated by filter,
              //  not by terminal.
              context.Compiler.Language.Grammar.WhitespaceChars = " \t\r\n\v";
              _prevLine = 0;
              _indents.Clear();
              foreach (Token token in tokens) {
            if (token.Terminal == base.Grammar.Eof) {
              yield return CreateSpecialToken(GrammarData.Grammar.NewLine, token.Location); //this is necessary, because grammar rules reference newLine terminator
              //unindent all buffered indents
              if (_trackIndents)
            foreach (int i in _indents)
              yield return CreateSpecialToken(GrammarData.Grammar.Dedent, token.Location);
              _indents.Clear();
              //return EOF token
              yield return token;
              yield break;
            }//if Eof

            //Now deal with normal, non-EOF tokens
            //We intercept only content tokens on new lines
            if (token.Terminal.Category != TokenCategory.Content || token.Location.Line == _prevLine) {
              yield return token;
              continue;
            }
            //if we are here, we have content token on new line; produce newLine token and possibly indents
            yield return CreateSpecialToken(GrammarData.Grammar.NewLine, token.Location);
            _prevLine = token.Location.Line;
            if (!_trackIndents) {
              yield return token;
              continue;
            }
            //Now  take care of indents
            int currIndent = token.Location.Column;
            int prevIndent = _indents.Count == 0 ? 0 : _indents.Peek();
            if (currIndent > prevIndent) {
              _indents.Push(currIndent);
              yield return CreateSpecialToken(GrammarData.Grammar.Indent, token.Location);
            } else if (currIndent < prevIndent) {
              //produce one or more dedent tokens while popping indents from stack
              while (_indents.Count > 0 && _indents.Peek() > currIndent) {
            _indents.Pop();
            yield return CreateSpecialToken(GrammarData.Grammar.Dedent, token.Location);
              }
              if (_indents.Count == 0 || _indents.Peek() != currIndent) {
            yield return context.CreateErrorTokenAndReportError (token.Location, string.Empty, "Invalid dedent level, no previous matching indent found.");
            //TODO: add error recovery here
              }
            }//else if currIndent < prevIndent
            yield return token;
              } //foreach token
        }
开发者ID:TheByte,项目名称:sones,代码行数:55,代码来源:CodeOutlineFilter.cs


注:本文中的CompilerContext.CreateErrorTokenAndReportError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。