Represents a code expression to be emitted in the source code of the generated parser.
Наследование: Expression
            protected override void WalkCodeExpression(CodeExpression codeExpression)
            {
                var ix = (codeExpression.CodeType == CodeType.Error || codeExpression.CodeType == CodeType.Result)
                    ? Tuple.Create("state =>", "")
                    : Tuple.Create("state => {", "}");
                var prefix = ix.Item1;
                var suffix = ix.Item2;

                var startCursor = codeExpression.CodeSpan.Start;
                var code = (prefix + codeExpression.CodeSpan.Code + suffix).TrimEnd();
                var expression = Syntax.ParseExpression(code);

                if (expression.ContainsDiagnostics)
                {
                    foreach (var diag in new DummySyntaxTree().GetDiagnostics(expression))
                    {
                        var cursor = diag.Location.IsInSource
                            ? startCursor.Advance(-prefix.Length + diag.Location.SourceSpan.Start)
                            : startCursor;

                        this.result.Errors.Add(new CompilerError(startCursor.FileName, cursor.Line, cursor.Column, diag.Info.MessageIdentifier, diag.Info.GetMessage()) { IsWarning = diag.Info.Severity == DiagnosticSeverity.Warning });
                    }
                }

                if (expression.Span.Length != code.Length)
                {
                    var sliced = code.Substring(expression.Span.Length);
                    var trimmed = sliced.TrimStart();
                    this.result.AddCompilerError(startCursor.Advance(-prefix.Length + expression.Span.Length + (sliced.Length - trimmed.Length)), () => Resources.CS1026_ERROR_UnexpectedCharacter, trimmed[0]);
                }
            }
Пример #2
0
            protected override void WalkCodeExpression(CodeExpression codeExpression)
            {
                const string prefix = "state =>";

                var startCursor = codeExpression.CodeSpan.Start;
                var code = (prefix + codeExpression.CodeSpan.Code).TrimEnd();
                var expression = SyntaxFactory.ParseExpression(code);

                if (expression.ContainsDiagnostics)
                {
                    foreach (var diag in expression.GetDiagnostics())
                    {
                        var cursor = diag.Location.IsInSource
                            ? startCursor.Advance(-prefix.Length + diag.Location.SourceSpan.Start)
                            : startCursor;

                        this.result.Errors.Add(new CompilerError(startCursor.FileName ?? string.Empty, cursor.Line, cursor.Column, diag.Id, diag.GetMessage()) { IsWarning = diag.WarningLevel > 0 });
                    }
                }
            }
Пример #3
0
 protected virtual void WalkCodeExpression(CodeExpression codeExpression)
 {
 }
Пример #4
0
 protected override void WalkCodeExpression(CodeExpression codeExpression)
 {
     this.Set(codeExpression, "string");
 }
 protected override void WalkCodeExpression(CodeExpression codeExpression)
 {
     this.containsAssertions[codeExpression] = false;
 }
Пример #6
0
 protected override void WalkCodeExpression(CodeExpression codeExpression) => this.RenderCodeExpression(codeExpression, this.writer, this.currentIndentation);
Пример #7
0
 protected override void WalkCodeExpression(CodeExpression codeExpression)
 {
     this.containsAssertions[codeExpression] = codeExpression.CodeType == CodeType.Parse;
 }
Пример #8
0
            protected override void WalkCodeExpression(CodeExpression codeExpression)
            {
                switch (codeExpression.CodeType)
                {
                    case CodeType.Result:
                    case CodeType.State:
                        this.zeroWidth[codeExpression] = true;
                        break;

                    case CodeType.Error:
                        this.zeroWidth[codeExpression] = false;
                        break;

                    default:
                        throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Unknown code type '{0}'.", codeExpression.CodeType));
                }
            }