Ejemplo n.º 1
0
        public static IEnumerable <FanucGCodeTextSpan> Tokenise(string testInput)
        {
            AntlrInputStream  inputStream       = new AntlrInputStream(testInput);
            FanucGCodeLexer   fanucLexer        = new FanucGCodeLexer(inputStream);
            CommonTokenStream commonTokenStream = new CommonTokenStream(fanucLexer);

            commonTokenStream.Fill();
            var tokens = commonTokenStream.GetTokens();

            return(tokens.Where(t => t.Type != FanucGCodeLexer.Eof).Select(t => new FanucGCodeTextSpan
            {
                StartPos = t.StartIndex,
                Length = (t.StopIndex - t.StartIndex) + 1,
                TokenType = (FanucGCodeTokenTypes)t.Type
            }));
        }
Ejemplo n.º 2
0
        public List <FanucGCodeParseError> CheckSyntax(string gcodeContent, bool programContext = false)
        {
            AntlrInputStream  inputStream       = new AntlrInputStream(gcodeContent);
            FanucGCodeLexer   fanucLexer        = new FanucGCodeLexer(inputStream);
            CommonTokenStream commonTokenStream = new CommonTokenStream(fanucLexer);

            FanucGCodeParser fanucParser = new FanucGCodeParser(commonTokenStream);

            _parseErrors = new List <FanucGCodeParseError>();

            fanucParser.RemoveErrorListeners();
            fanucParser.AddErrorListener(this);

            if (programContext)
            {
                // this line triggers the actual parse.
                var progContext = fanucParser.program();
            }
            else
            {
                var blocksContext = fanucParser.programContent();

                Debug.WriteLine($"Checking syntax of '{gcodeContent.Trim()}'");
                Debug.WriteLine($"Which has parse tree:\n{blocksContext.ToStringTree(fanucParser)}");
            }

            /*FanucTargetVisitor visitor = new FanucTargetVisitor();
             * visitor.Visit(progContext);
             *
             * Console.WriteLine(visitor.Output.ToString());
             */

            foreach (var error in _parseErrors)
            {
                Debug.WriteLine(error.ToString());
            }

            return(_parseErrors);
        }