Exemple #1
0
 public void GetHashTest()
 {
     string fileName = "myFile.wasp";
     int characterNumber = 893892;
     var target = new Loc(fileName, characterNumber);
     Assert.AreEqual(target.GetHashCode(), new Loc(fileName, characterNumber).GetHashCode());
 }
Exemple #2
0
 public void SourceLocationCreateTest()
 {
     string filePath = @"c:\myFile.w";
     int character = 20;
     Loc target = new Loc(filePath, character);
     Assert.AreEqual(filePath, target.FilePath);
     Assert.AreEqual(character, target.Position);
 }
Exemple #3
0
 public void EqualsTest()
 {
     string fileName = "myFile.w";
     int characterNumber = 893892;
     var target = new Loc(fileName, characterNumber);
     Assert.AreEqual(target, target);
     Assert.AreEqual(target, new Loc(fileName, characterNumber));
     Assert.AreNotEqual(target, new Loc(fileName + 1, characterNumber));
     Assert.AreNotEqual(target, new Loc(fileName, characterNumber + 1));
 }
 private SequencePoint CreateSequencePoint(Loc location)
 {
     var result = new SequencePoint(this.document);
     result.StartLine = 0;
     result.StartColumn = location.Position;
     // TODO: End location
     result.EndLine = 0;
     result.EndColumn = location.End;
     return result;
 }
        void ISppfNodeVisitor.VisitBranch(int ruleIndex, SppfNode[] children, Loc location)
        {
            var rule = grammar.Productions[ruleIndex];

            var tokenName = grammar.Symbols[rule.OutcomeToken].Name;

            string label;
            if (showRules)
            {
                label = string.Format(
                        "{0} -> {1}"
            #if DEBUG
                        + " t: " + currentNode.timestamp
            #endif
                        ,
                        tokenName,
                        string.Join(" ", from s in rule.Pattern select s.Name));
            }
            else
            {
                label = tokenName
            #if DEBUG
                    + " t: " + currentNode.timestamp
            #endif
                    ;
            }

            graph.AddNode(currentNodeIdentity, label: label, shape: Shape.Ellipse);

            if (children != null && children.Length != 0)
            {
                int i = 0;
                foreach (var child in children)
                {
                    graph.AddEdge(currentNodeIdentity, child, label: "child" + ++i);
                    EnqueueNode(child);
                }
            }
        }
        public void Test()
        {
            const string document = "number.list";

            string[] expectedTokens = new string[] { " ", "123", "   ", "0"};
            int[] expectedTokenIds = new int[] { SpaceTokenId, NumberTokenId, SpaceTokenId, NumberTokenId};
            Loc[] expectedLocations = new Loc[] {
                new Loc(document, 0, 1),
                new Loc(document, 1, 4),
                new Loc(document, 4, 7),
                new Loc(document, 7, 8)
            };

            var input = new StringReader(string.Join("", expectedTokens));

            ScanActionDelegate scanAction = (ScanCursor cursor, out object value)
                =>
                {
                    value = new string(cursor.Buffer, cursor.Start, cursor.Marker - cursor.Start);
                    return cursor.Actions[0];
                };

            var logging = ExceptionLogging.Instance;
            var allTokens = new Scanner(Scan1, input, document, null, scanAction, 10, logging).ToArray();

            Assert.AreEqual(expectedTokens, TokenTexts(allTokens));
            Assert.AreEqual(expectedTokenIds, TokenIds(allTokens));
            Assert.AreEqual(expectedLocations, Locations(allTokens));

            var scanner = new Scanner(Scan1, new StringReader(" a11"), Loc.MemoryString, null, scanAction, 10, logging);
            Assert.Throws<SyntaxException>(
                () =>
                {
                    scanner.ToArray();
                });
        }
 void ISppfNodeVisitor.VisitLeaf(int token, object value, Loc location)
 {
     string label = grammar.Symbols[token].Name + " pos: " + location.Position
     #if DEBUG
         + " t: " + currentNode.timestamp
     #endif
         ;
     graph.AddNode(currentNodeIdentity, label: label, shape: Shape.Circle);
 }
            public string NestedStart()
            {
                HasParsing = Parsing != null;
                if (HasParsing)
                {
                    LastNonTermLocation = Parsing.Location;
                }

                return null;
            }
            public object BarTerm()
            {
                HasScanning = Scanning != null;
                HasLanguage = Language != null;
                if (HasScanning)
                {
                    LastTermLocation = Scanning.Location;
                }

                return null;
            }
 public SyntaxException(Loc location, HLoc hLocation, string message)
 {
     this.location = location;
     this.hLocation = hLocation;
     this.message = message;
 }