示例#1
3
        void ICompletionSource.AugmentCompletionSession(ICompletionSession session, IList<CompletionSet> completionSets)
        {
            return;

            var keywords = Keywords.Get();

            var snapshot = this.Buffer.CurrentSnapshot;
            var trackSpan = this.FindTokenSpanAtPosition(session.GetTriggerPoint(this.Buffer), session);
            var preSpan = new SnapshotSpan(snapshot, new Span(snapshot.GetLineFromLineNumber(0).Start,
                trackSpan.GetStartPoint(snapshot).Position));

            var tokens = new PSharpLexer().Tokenize(preSpan.GetText());
            var parser = new PSharpParser();
            parser.ParseTokens(tokens);
            this.RefineAvailableKeywords(parser.GetExpectedTokenTypes(), keywords);

            this.CompletionList = new List<Completion>();

            foreach (var keyword in keywords)
            {
                this.CompletionList.Add(new Completion(keyword.Key, keyword.Key,
                    keyword.Value.Item1, null, null));
            }

            if (keywords.Count == 0)
            {
                return;
            }

            completionSets.Add(new CompletionSet(
                "Tokens",
                "Tokens",
                trackSpan,
                this.CompletionList,
                null));
        }
        public Task<bool> HasSuggestedActionsAsync(ISuggestedActionCategorySet requestedActionCategories,
            SnapshotSpan range, CancellationToken cancellationToken)
        {
            return Task.Factory.StartNew(() =>
            {
                return false;

                TextExtent extent;
                if (!this.TryGetWordUnderCaret(out extent))
                {
                    return false;
                }

                var extentToken = new PSharpLexer().Tokenize(extent.Span.GetText()).FirstOrDefault();
                if (extentToken == null)
                {
                    return false;
                }

                var snapshot = extent.Span.Snapshot;
                var trackSpan = range.Snapshot.CreateTrackingSpan(extent.Span, SpanTrackingMode.EdgeInclusive);
                var preSpan = new SnapshotSpan(snapshot, new Span(snapshot.GetLineFromLineNumber(0).Start,
                    trackSpan.GetStartPoint(snapshot).Position));

                var tokens = new PSharpLexer().Tokenize(preSpan.GetText());
                var parser = new PSharpParser(ParsingOptions.CreateDefault());
                parser.ParseTokens(tokens);

                var expected = parser.GetExpectedTokenTypes();
                if (this.IsExpectedTokenType(extentToken, expected))
                {
                    return false;
                }

                return extent.IsSignificant;
            });
        }
示例#3
0
        public void TestMachineDeferEventDeclarationWithExtraComma()
        {
            var test = @"
            namespace Foo {
            machine M {
            group G {
            start state S
            {
            defer e1,e2,;
            }
            }
            }
            }";

            ParsingOptions options = ParsingOptions.CreateDefault()
                .DisableThrowParsingException();
            var parser = new PSharpParser(new PSharpProject(),
                SyntaxFactory.ParseSyntaxTree(test), options);

            var tokens = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Expected event identifier.",
                parser.GetParsingErrorLog());
        }
示例#4
0
        public void TestVoidMethodDeclaration()
        {
            var test = @"
namespace Foo {
machine M {
start state S { }
void Bar() { }
}
}";

            var tokens = new PSharpLexer().Tokenize(test);
            var program = new PSharpParser(new PSharpProject(),
                SyntaxFactory.ParseSyntaxTree(test), false).ParseTokens(tokens);
            program.Rewrite();

            var expected = @"
using System;
using Microsoft.PSharp;
namespace Foo
{
class M : Machine
{
[Microsoft.PSharp.Start]
class S : MachineState
{
}
private void Bar(){ }

}
}";

            Assert.AreEqual(expected.Replace(Environment.NewLine, string.Empty),
                program.GetSyntaxTree().ToString().Replace("\n", string.Empty));
        }
示例#5
0
        public void TestUnexpectedTokenWithoutNamespace()
        {
            var test = "private";

            var parser = new PSharpParser(new PSharpProject(), SyntaxFactory.ParseSyntaxTree(test), false);

            var tokens = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Unexpected token.",
                parser.GetParsingErrorLog());
        }
示例#6
0
        public void TestNamespaceDeclarationWithoutIdentifier()
        {
            var test = "namespace { }";

            var parser = new PSharpParser(new PSharpProject(), SyntaxFactory.ParseSyntaxTree(test), false);

            var tokens = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Expected namespace identifier.",
                parser.GetParsingErrorLog());
        }
示例#7
0
        public void TestIncorrectUsingDeclaration()
        {
            var test = "using System.Text";

            var parser = new PSharpParser(new PSharpProject(), SyntaxFactory.ParseSyntaxTree(test), false);

            var tokens = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Expected \";\".",
                parser.GetParsingErrorLog());
        }
示例#8
0
        public void TestEventDeclarationWithoutNamespace()
        {
            var test = "event e;";

            var parser = new PSharpParser(new PSharpProject(),
                SyntaxFactory.ParseSyntaxTree(test), false);

            var tokens = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Must be declared inside a namespace.",
                parser.GetParsingErrorLog());
        }
示例#9
0
        public void TestEventDeclarationWithoutNamespace()
        {
            var test = "event e;";

            ParsingOptions options = ParsingOptions.CreateDefault()
                .DisableThrowParsingException();
            var parser = new PSharpParser(new PSharpProject(),
                SyntaxFactory.ParseSyntaxTree(test), options);

            var tokens = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Must be declared inside a namespace.",
                parser.GetParsingErrorLog());
        }
示例#10
0
        public void TestUnexpectedTokenWithoutNamespace()
        {
            var test = "private";

            ParsingOptions options = ParsingOptions.CreateDefault()
                .DisableThrowParsingException();
            var parser = new PSharpParser(new PSharpProject(),
                SyntaxFactory.ParseSyntaxTree(test), options);

            var tokens = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Unexpected token.",
                parser.GetParsingErrorLog());
        }
示例#11
0
        public void TestUsingDeclarationWithoutIdentifier()
        {
            var test = "using;";

            ParsingOptions options = ParsingOptions.CreateDefault()
                .DisableThrowParsingException();
            var parser = new PSharpParser(new PSharpProject(),
                SyntaxFactory.ParseSyntaxTree(test), options);

            var tokens = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Expected identifier.",
                parser.GetParsingErrorLog());
        }
示例#12
0
        public void TestPrivateEventDeclaration()
        {
            var test = @"
namespace Foo {
private event e;
}";

            var parser = new PSharpParser(new PSharpProject(),
                SyntaxFactory.ParseSyntaxTree(test), false);

            var tokens = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual(parser.GetParsingErrorLog(),
                "Event and machine declarations must be internal or public.");
        }
示例#13
0
        public void TestUsingDeclaration()
        {
            var test = "using System.Text;";

            var tokens = new PSharpLexer().Tokenize(test);
            var program = new PSharpParser(new PSharpProject(),
                SyntaxFactory.ParseSyntaxTree(test), false).ParseTokens(tokens);
            program.Rewrite();
            
            var expected = @"
using System;
using Microsoft.PSharp;
using System.Text;";

            Assert.AreEqual(expected.Replace(Environment.NewLine, string.Empty),
                program.GetSyntaxTree().ToString().Replace("\n", string.Empty));
        }
示例#14
0
        public void TestMachineDeclarationWithoutState()
        {
            var test = @"
namespace Foo {
machine M {
}
}";

            var parser = new PSharpParser(new PSharpProject(),
                SyntaxFactory.ParseSyntaxTree(test), false);

            var tokens = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("A machine must declare at least one state.",
                parser.GetParsingErrorLog());
        }
示例#15
0
        public void TestEventDeclarationWithGenericError2()
        {
            var test = @"
            namespace Foo {
            event e<;
            }";

            ParsingOptions options = ParsingOptions.CreateDefault()
                .DisableThrowParsingException();
            var parser = new PSharpParser(new PSharpProject(),
                SyntaxFactory.ParseSyntaxTree(test), options);

            var tokens = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Invalid generic expression.",
                parser.GetParsingErrorLog());
        }
示例#16
0
        public void TestMachineFieldDeclarationWithoutSemicolon()
        {
            var test = @"
            namespace Foo {
            machine M {
            machine N
            start state S { }
            }
            }";

            var parser = new PSharpParser(new PSharpProject(), SyntaxFactory.ParseSyntaxTree(test), false);

            var tokens = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Expected \"(\" or \";\".",
                parser.GetParsingErrorLog());
        }
示例#17
0
        public void TestInternalFieldDeclaration()
        {
            var test = @"
            namespace Foo {
            machine M {
            internal int k;
            start state S { }
            }
            }";

            var parser = new PSharpParser(new PSharpProject(), SyntaxFactory.ParseSyntaxTree(test), false);

            var tokens = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("A field or method cannot be internal.",
                parser.GetParsingErrorLog());
        }
示例#18
0
        public void TestEventDeclaration()
        {
            var test = @"
            namespace Foo {
            event e1;
            internal event e2;
            public event e3;
            }";

            var tokens = new PSharpLexer().Tokenize(test);
            var program = new PSharpParser(new PSharpProject(), SyntaxFactory.ParseSyntaxTree(test), false).
                ParseTokens(tokens);
            program.Rewrite();

            var expected = @"
            using System;
            using Microsoft.PSharp;
            namespace Foo
            {
            class e1 : Event
            {
             internal e1()
              : base()
             { }
            }
            internal class e2 : Event
            {
             internal e2()
              : base()
             { }
            }
            public class e3 : Event
            {
             internal e3()
              : base()
             { }
            }
            }";

            Assert.AreEqual(expected.Replace(Environment.NewLine, string.Empty),
                program.GetSyntaxTree().ToString().Replace("\n", string.Empty));
        }
示例#19
0
        public void TestEntryDeclarationWithUnexpectedIdentifier()
        {
            var test = @"
            namespace Foo {
            machine M {
            start state S
            {
            entry Bar {}
            }
            }
            }";

            var parser = new PSharpParser(new PSharpProject(), SyntaxFactory.ParseSyntaxTree(test), false);

            var tokens = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Expected \"{\".",
                parser.GetParsingErrorLog());
        }
示例#20
0
        public void TestMachineColdGroup()
        {
            var test = @"
            namespace Foo {
            machine M {
            cold group G { }
            }
            }";

            ParsingOptions options = ParsingOptions.CreateDefault()
                .DisableThrowParsingException();
            var parser = new PSharpParser(new PSharpProject(),
                SyntaxFactory.ParseSyntaxTree(test), options);

            var tokens = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("A state group cannot be cold.",
                parser.GetParsingErrorLog());
        }
示例#21
0
        public void TestDeferEventDeclarationWithoutComma()
        {
            var test = @"
            namespace Foo {
            machine M {
            start state S
            {
            defer e1 e2;
            }
            }
            }";

            var parser = new PSharpParser(new PSharpProject(), SyntaxFactory.ParseSyntaxTree(test), false);

            var tokens = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Expected \",\".",
                parser.GetParsingErrorLog());
        }
示例#22
0
        public void TestMachineDeclarationWithTwoBodies()
        {
            var test = @"
namespace Foo {
machine M {
start state S { }
}
{
}
}";

            var parser = new PSharpParser(new PSharpProject(),
                SyntaxFactory.ParseSyntaxTree(test), false);

            var tokens = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Unexpected token.",
                parser.GetParsingErrorLog());
        }
示例#23
0
        public void TestMachineDeclarationWithMoreThanOneStartState()
        {
            var test = @"
            namespace Foo {
            machine M {
            start state S1 {}
            start state S2 { }

            start state S3 { }
            }
            }";

            var parser = new PSharpParser(new PSharpProject(), SyntaxFactory.ParseSyntaxTree(test), false);

            var tokens = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("A machine can declare only a single start state.",
                parser.GetParsingErrorLog());
        }
示例#24
0
        public void TestIntFieldDeclarationWithoutSemicolon()
        {
            var test = @"
            namespace Foo {
            machine M {
            int k
            start state S { }
            }
            }";

            ParsingOptions options = ParsingOptions.CreateDefault()
                .DisableThrowParsingException();
            var parser = new PSharpParser(new PSharpProject(),
                SyntaxFactory.ParseSyntaxTree(test), options);

            var tokens = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Expected \"(\" or \";\".",
                parser.GetParsingErrorLog());
        }
示例#25
0
        public void TestStateDeclarationWithMoreThanOneExit()
        {
            var test = @"
namespace Foo {
machine M {
start state S
{
exit{}
exit {}
}
}
}";

            var parser = new PSharpParser(new PSharpProject(),
                SyntaxFactory.ParseSyntaxTree(test), false);

            var tokens = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Duplicate exit declaration.",
                parser.GetParsingErrorLog());
        }
示例#26
0
        public void TestMonitorMethodInsideGroup()
        {
            var test = @"
            namespace Foo {
            monitor M {
            group G
            {
            void Bar() { }
            }
            }
            }";

            ParsingOptions options = ParsingOptions.CreateDefault()
                .DisableThrowParsingException();
            var parser = new PSharpParser(new PSharpProject(),
                SyntaxFactory.ParseSyntaxTree(test), options);

            var tokens = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Unexpected token 'void'.",
                parser.GetParsingErrorLog());
        }
示例#27
0
        /// <summary>
        /// Parses a P# syntax tree to C#.
        /// th
        /// </summary>
        /// <param name="tree">SyntaxTree</param>
        /// <param name="options">ParsingOptions</param>
        private void ParsePSharpSyntaxTree(SyntaxTree tree, ParsingOptions options)
        {
            var root = (CompilationUnitSyntax)tree.GetRoot();

            var tokens = new PSharpLexer().Tokenize(root.ToFullString());
            var program = new PSharpParser(this, tree, options).ParseTokens(tokens);

            this.PSharpPrograms.Add(program as PSharpProgram);
            this.ProgramMap.Add(program, tree);
        }
示例#28
0
        public void TestMonitorOnEventGotoStateDeclarationWithoutState()
        {
            var test = @"
            namespace Foo {
            monitor M {
            group G
            {
            start state S1
            {
            on e goto;
            }
            }
            }
            }";

            ParsingOptions options = ParsingOptions.CreateDefault()
                .DisableThrowParsingException();
            var parser = new PSharpParser(new PSharpProject(),
                SyntaxFactory.ParseSyntaxTree(test), options);

            var tokens = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Expected state identifier.",
                parser.GetParsingErrorLog());
        }
示例#29
0
        public IEnumerable<SuggestedActionSet> GetSuggestedActions(ISuggestedActionCategorySet requestedActionCategories,
            SnapshotSpan range, CancellationToken cancellationToken)
        {
            return Enumerable.Empty<SuggestedActionSet>();

            TextExtent extent;
            if (!this.TryGetWordUnderCaret(out extent) || !extent.IsSignificant)
            {
                return Enumerable.Empty<SuggestedActionSet>();
            }

            var extentToken = new PSharpLexer().Tokenize(extent.Span.GetText()).FirstOrDefault();
            if (extentToken == null)
            {
                return Enumerable.Empty<SuggestedActionSet>();
            }

            var snapshot = extent.Span.Snapshot;
            var trackSpan = range.Snapshot.CreateTrackingSpan(extent.Span, SpanTrackingMode.EdgeInclusive);
            var preSpan = new SnapshotSpan(snapshot, new Span(snapshot.GetLineFromLineNumber(0).Start,
                trackSpan.GetStartPoint(snapshot).Position));

            var tokens = new PSharpLexer().Tokenize(preSpan.GetText());
            var parser = new PSharpParser(ParsingOptions.CreateDefault());
            parser.ParseTokens(tokens);

            var expected = parser.GetExpectedTokenTypes();
            if (this.IsExpectedTokenType(extentToken, expected))
            {
                return Enumerable.Empty<SuggestedActionSet>();
            }

            var errorFixAction = new ErrorFixSuggestedAction(trackSpan);

            return new SuggestedActionSet[] { new SuggestedActionSet(new ISuggestedAction[] { errorFixAction }) };
        }
示例#30
0
        public void TestMonitorStateDeclarationWithMoreThanOneEntry()
        {
            var test = @"
            namespace Foo {
            monitor M {
            group G {
            start state S
            {
            entry {}
            entry{}
            }
            }
            }
            }";

            ParsingOptions options = ParsingOptions.CreateDefault()
                .DisableThrowParsingException();
            var parser = new PSharpParser(new PSharpProject(),
                SyntaxFactory.ParseSyntaxTree(test), options);

            var tokens = new PSharpLexer().Tokenize(test);
            var program = parser.ParseTokens(tokens);

            Assert.AreEqual("Duplicate entry declaration.",
                parser.GetParsingErrorLog());
        }