コード例 #1
0
        public IEnumerable <ITagSpan <FanucGCodeTokenTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            foreach (SnapshotSpan curSpan in spans)
            {
                ITextSnapshotLine containingLine = curSpan.Start.GetContainingLine();
                int curLoc = containingLine.Start.Position;

                var tokens = FanucGCodeScanner.Tokenise(containingLine.GetText());

                foreach (var fanucGCodeToken in tokens)
                {
                    // tag known tokens only. when all valid tokens are supported for tagging, can just have:
                    //if (fanucGCodeToken.TokenType != FanucGCodeTokenTypes.Unknown) here.
                    if (_supportedTypes.Contains(fanucGCodeToken.TokenType))
                    {
                        var tokenSpan = new SnapshotSpan(curSpan.Snapshot, new Span(curLoc + fanucGCodeToken.StartPos, fanucGCodeToken.Length));
                        if (tokenSpan.IntersectsWith(curSpan))
                        {
                            yield return(new TagSpan <FanucGCodeTokenTag>(tokenSpan,
                                                                          new FanucGCodeTokenTag(fanucGCodeToken.TokenType)));
                        }
                    }
                }
            }
        }
コード例 #2
0
        public void TestFanucLexer_CommentLexicalMode()
        {
            var tokens = FanucGCodeScanner.Tokenise("N70 ( test N50 comment #_UI[9] also #104 IF THEN )\n");
            var test   = tokens.ToList();

            var expected = new List <FanucGCodeTokenTypes>()
            {
                FanucGCodeTokenTypes.LabelPrefix,
                FanucGCodeTokenTypes.Integer,
                FanucGCodeTokenTypes.CommentStart,
                FanucGCodeTokenTypes.CommentText,
                FanucGCodeTokenTypes.CommentEnd,
                FanucGCodeTokenTypes.EndOfBlock,
            };

            CollectionAssert.AreEqual(expected, tokens.Select(t => t.TokenType));
        }
コード例 #3
0
        public void TestFanucLexer_SystemVarIdentifier()
        {
            var testInput = @"%
O9123(MyProg)
G01X[#5-20.5] Y[#_ALS[4] ]
";
            var tokens    = FanucGCodeScanner.Tokenise(testInput);
            var test      = tokens.ToList();

            var expected = new List <FanucGCodeTokenTypes>()
            {
                FanucGCodeTokenTypes.StartEndProgram,
                FanucGCodeTokenTypes.EndOfBlock,
                FanucGCodeTokenTypes.ProgramNumberPrefix,
                FanucGCodeTokenTypes.Integer,
                FanucGCodeTokenTypes.CommentStart,
                FanucGCodeTokenTypes.CommentText,
                FanucGCodeTokenTypes.CommentEnd,
                FanucGCodeTokenTypes.EndOfBlock,
                FanucGCodeTokenTypes.GCodePrefix,
                FanucGCodeTokenTypes.Integer,
                FanucGCodeTokenTypes.GCodePrefix,
                FanucGCodeTokenTypes.OpenBracket,
                FanucGCodeTokenTypes.Hash,
                FanucGCodeTokenTypes.Integer,
                FanucGCodeTokenTypes.Minus,
                FanucGCodeTokenTypes.Decimal,
                FanucGCodeTokenTypes.CloseBracket,
                FanucGCodeTokenTypes.GCodePrefix,
                FanucGCodeTokenTypes.OpenBracket,
                FanucGCodeTokenTypes.Hash,
                FanucGCodeTokenTypes.NamedVariable,
                FanucGCodeTokenTypes.OpenBracket,
                FanucGCodeTokenTypes.Integer,
                FanucGCodeTokenTypes.CloseBracket,
                FanucGCodeTokenTypes.CloseBracket,
                FanucGCodeTokenTypes.EndOfBlock,
            };

            CollectionAssert.AreEqual(expected, tokens.Select(t => t.TokenType));
        }
コード例 #4
0
        public void TestFanucLexer_NumberInBrackets()
        {
            var tokens = FanucGCodeScanner.Tokenise("G1X[#[100]]\n");
            var test   = tokens.ToList();

            var expected = new List <FanucGCodeTokenTypes>()
            {
                FanucGCodeTokenTypes.GCodePrefix,
                FanucGCodeTokenTypes.Integer,
                FanucGCodeTokenTypes.GCodePrefix,
                FanucGCodeTokenTypes.OpenBracket,
                FanucGCodeTokenTypes.Hash,
                FanucGCodeTokenTypes.OpenBracket,
                FanucGCodeTokenTypes.Integer,
                FanucGCodeTokenTypes.CloseBracket,
                FanucGCodeTokenTypes.CloseBracket,
                FanucGCodeTokenTypes.EndOfBlock,
            };

            CollectionAssert.AreEqual(expected, tokens.Select(t => t.TokenType));
        }