Пример #1
0
        public void TestParseExpression()
        {
            const string code = @"3 + 2 * 5";
            Expression   e    = BooParser.ParseExpression("test", code);

            Assert.AreEqual("3 + (2 * 5)", e.ToString());
        }
Пример #2
0
        public void RunStringTestCase(string message, string expected, string actual)
        {
            CompileUnit cu = RunCompiler(new StringInput("<actual>", actual));

            cu.Modules[0].Name = BooParser.CreateModuleName("<expected>");
            AssertEquals(message, ParseString("<expected>", expected), cu);
        }
Пример #3
0
        public ScanningLexer(int tabSize, string source)
        {
            source += " "; // No idea why but without this extra space the lexer sometimes throws an exception
            Func <BooLexer, antlr.TokenStream> makeFilter = lexer => {
                lexer.WantAllWhitespace = true;
                return(new WhitespacePreservingTokenStreamFilter(lexer, BooParserBase.EOL, BooParserBase.END, BooParserBase.ID));
            };

            lexer = BooParser.CreateFilteredBooLexer(tabSize, "Line Scanner", new StringReader(source), makeFilter);
            var sourcePos    = 0;
            var mappedPos    = 0;
            var positionList = new List <int>();

            foreach (var c in source)
            {
                if (c == '\t')
                {
                    while (mappedPos % tabSize < tabSize - 1)
                    {
                        positionList.Add(sourcePos);
                        mappedPos++;
                    }
                }
                positionList.Add(sourcePos++);
                mappedPos++;
            }
            positionList.Add(sourcePos); // to map the <EOL> token
            positionMap = positionList.ToArray();
        }
Пример #4
0
        public void RunTestCase(string expectedFile, string actualFile)
        {
            CompileUnit cu = RunCompiler(new FileInput(GetTestCasePath(actualFile)));

            cu.Modules[0].Name = BooParser.CreateModuleName(expectedFile);
            AssertEquals("[required]", ParseTestCase(expectedFile), cu);
        }
Пример #5
0
 public static Boo.Lang.Ast.Module ParseTestCase(string sample)
 {
     using (StreamReader reader = File.OpenText(GetTestCasePath(sample)))
     {
         return(BooParser.ParseModule(sample, reader, new ParserErrorHandler(OnError)));
     }
 }
Пример #6
0
        public override string GetNamespace(string fileName, string definedSymbols)
        {
            try
            {
                return(BooParser.ParseFile(fileName).Modules.First().Namespace.Name);
            }
            catch {}

            return(base.GetNamespace(fileName, definedSymbols));
        }
Пример #7
0
        void EnsureClosureEndSourceLocation(string code, int line, int column)
        {
            CompileUnit     cu  = BooParser.ParseString("closures", code);
            Expression      e   = ((ExpressionStatement)cu.Modules[0].Globals.Statements[0]).Expression;
            BlockExpression cbe = (BlockExpression)((BinaryExpression)e).Right;
            SourceLocation  esl = cbe.Body.EndSourceLocation;

            Assert.AreEqual(line, esl.Line);
            Assert.AreEqual(column, esl.Column);
        }
Пример #8
0
 public override string GetNamespace(string fileName)
 {
     try
     {
         return(((IEnumerable <Module>)BooParser.ParseFile(fileName).get_Modules()).First <Module>().get_Namespace().get_Name());
     }
     catch
     {
     }
     return(base.GetNamespace(fileName));
 }
Пример #9
0
 public override string GetNamespace(string fileName)
 {
     try
     {
         return(BooParser.ParseFile(fileName).Modules.First <Module>().Namespace.Name);
     }
     catch
     {
     }
     return(base.GetNamespace(fileName));
 }
Пример #10
0
        void Register(string prog)
        {
            DefaultProjectContent pc = new DefaultProjectContent();

            lastPC = pc;
            HostCallback.GetCurrentProjectContent = delegate { return(pc); };
            pc.ReferencedContents.Add(AssemblyParserService.DefaultProjectContentRegistry.Mscorlib);
            pc.ReferencedContents.Add(AssemblyParserService.DefaultProjectContentRegistry.GetProjectContentForReference("System.Windows.Forms", typeof(System.Windows.Forms.Form).Module.FullyQualifiedName));
            pc.ReferencedContents.Add(booLangPC);
            ICompilationUnit cu = new BooParser().Parse(pc, fileName, new StringTextBuffer(prog));

            ParserService.RegisterParseInformation(fileName, cu);
            cu.Classes.ForEach(pc.AddClassToNamespaceList);
        }
Пример #11
0
        public override string GetNamespace(string fileName, string definedSymbols)
        {
            string result;

            try
            {
                result = BooParser.ParseFile(fileName).get_Modules().First <Module>().get_Namespace().get_Name();
                return(result);
            }
            catch
            {
            }
            result = base.GetNamespace(fileName, definedSymbols);
            return(result);
        }
Пример #12
0
        private void MapTokens(int tabSize, string source)
        {
            var endLine  = 0;
            var endIndex = 0;

            var tokens = BooParser.CreateBooLexer(tabSize, "code stream", new StringReader(source));

            antlr.IToken token;
            while ((token = NextToken(tokens)).Type != BooLexer.EOF)
            {
                Tuple <int, int> endPoint;
                switch (token.Type)
                {
                case BooLexer.INDENT:
                case BooLexer.DEDENT:
                case BooLexer.EOL:
                case BooLexer.ESEPARATOR:
                    continue;

                case BooLexer.SINGLE_QUOTED_STRING:
                case BooLexer.DOUBLE_QUOTED_STRING:
                    endPoint = CalculateEndpoint(token, endLine, endIndex, 1);
                    break;

                case BooLexer.TRIPLE_QUOTED_STRING:
                    endPoint = CalculateEndpoint(token, endLine, endIndex, 3);
                    break;

                default:
                    endPoint = CalculateEndpoint(token, endLine, endIndex, 0);
                    break;
                }

                endLine  = endPoint.Item1;
                endIndex = endPoint.Item2;
            }

            var sIndex = positionMap[token.getLine() - 1][token.getColumn() - 1];
            var sLine  = token.getLine() - 1;

            if (sLine > endLine || sLine == endLine && sIndex > endIndex)
            {
                whitespaces.Add(new TextSpan {
                    iStartLine = endLine, iStartIndex = endIndex, iEndLine = sLine, iEndIndex = sIndex
                });
            }
        }
Пример #13
0
        static Module Parse(string fileName, string fileContent)
        {
            BooParsingStep step = new BooParsingStep();

            StringBuilder errors = new StringBuilder();
            Module        module = BooParser.ParseModule(4, new CompileUnit(), fileName,
                                                         new StringReader(fileContent),
                                                         delegate(antlr.RecognitionException e) {
                errors.AppendLine(e.ToString());
            });

            if (errors.Length > 0)
            {
                throw new FormsDesignerLoadException("Syntax errors in " + fileName + ":\r\n" + errors.ToString());
            }
            return(module);
        }
Пример #14
0
        public void TestSimpleClasses()
        {
            string fname = GetTestCasePath("simple_classes.boo");

            Boo.Lang.Compiler.Ast.Module module = BooParser.ParseFile(fname).Modules[0];
            Assert.AreEqual("Foo.Bar", module.Namespace.Name);

            Assert.IsNotNull(module.Members);
            Assert.AreEqual(2, module.Members.Count);

            TypeMember cd = module.Members[0];

            Assert.IsTrue(cd is ClassDefinition);
            Assert.AreEqual("Customer", cd.Name);
            Assert.AreEqual("Foo.Bar.Customer", cd.FullName);
            Assert.AreSame(module.Namespace, cd.EnclosingNamespace);

            cd = module.Members[1];
            Assert.AreEqual("Person", cd.Name);
        }
Пример #15
0
        public void TestSimple()
        {
            string      fname = GetTestCasePath("simple.boo");
            CompileUnit cu    = BooParser.ParseFile(fname);

            Assert.IsNotNull(cu);

            Boo.Lang.Compiler.Ast.Module module = cu.Modules[0];
            Assert.IsNotNull(module);
            Assert.AreEqual("simple", module.Name);
            Assert.AreEqual("module doc string", module.Documentation);
            Assert.AreEqual("Empty.simple", module.FullName);
            Assert.AreEqual(fname, module.LexicalInfo.FileName);

            Assert.IsNotNull(module.Namespace);

            Assert.AreEqual("Empty", module.Namespace.Name);
            Assert.AreEqual(4, module.Namespace.LexicalInfo.Line);
            Assert.AreEqual(1, module.Namespace.LexicalInfo.Column);
            Assert.AreEqual(fname, module.Namespace.LexicalInfo.FileName);
        }
Пример #16
0
        public ScanningLexer(int tabSize, string source)
        {
            source += " "; // No idea why but without this extra space the lexer sometimes throws an exception
            lexer   = BooParser.CreateBooLexer(tabSize, "Line Scanner", new StringReader(source));
            var sourcePos    = 0;
            var mappedPos    = 0;
            var positionList = new List <int>();

            foreach (var c in source)
            {
                if (c == '\t')
                {
                    while (mappedPos % tabSize < tabSize - 1)
                    {
                        positionList.Add(sourcePos);
                        mappedPos++;
                    }
                }
                positionList.Add(sourcePos++);
                mappedPos++;
            }
            positionList.Add(sourcePos); // to map the <EOL> token
            positionMap = positionList.ToArray();
        }
 static string GetExpectedOutput(string path)
 {
     return(BooParser.ParseFile(path).Modules [0].Documentation);
 }
 private Assembly compile(string code)
 {
     return(Compilation.compile(BooParser.ParseString("code", code), GetType().Assembly));
 }
Пример #19
0
 CompileUnit ParseTestCase(string fname)
 {
     return(BooParser.ParseFile(GetTestCasePath(fname)));
 }
Пример #20
0
 CompileUnit ParseString(string name, string text)
 {
     return(BooParser.ParseReader(name, new StringReader(text)));
 }
Пример #21
0
        private void MapTokens(int tabSize, string source)
        {
            var endLine  = 0;
            var endIndex = 0;

            var tokens = BooParser.CreateBooLexer(tabSize, "code stream", new StringReader(source));

            antlr.IToken token;
            while ((token = NextToken(tokens)).Type != BooLexer.EOF)
            {
                int length;

                switch (token.Type)
                {
                case BooLexer.INDENT:
                case BooLexer.DEDENT:
                case BooLexer.EOL:
                    continue;

                case BooLexer.SINGLE_QUOTED_STRING:
                case BooLexer.DOUBLE_QUOTED_STRING:
                    length = token.getText().Length + 2;
                    break;

                case BooLexer.TRIPLE_QUOTED_STRING:
                    length = token.getText().Length + 6;
                    break;

                default:
                    length = token.getText().Length;
                    break;
                }

                var startIndex = positionMap[token.getLine() - 1][token.getColumn() - 1];
                var startLine  = token.getLine() - 1;

                if (startLine > endLine || startLine == endLine && startIndex > endIndex)
                {
                    whitespaces.Add(new TextSpan {
                        iStartLine = endLine, iStartIndex = endIndex, iEndLine = startLine, iEndIndex = startIndex
                    });
                }

                endIndex = positionMap[token.getLine() - 1][token.getColumn() - 1 + length];
                endLine  = startLine;

                var cluster = new MappedToken(
                    startLine * lineSize + startIndex,
                    endIndex - startIndex);

                if (tokenMap.Count > 0 &&
                    tokenMap[tokenMap.Count() - 1].Index >= cluster.Index)
                {
                    throw new ArgumentException("Token Mapping order");
                }
                tokenMap.Add(cluster);
            }

            var sIndex = positionMap[token.getLine() - 1][token.getColumn() - 1];
            var sLine  = token.getLine() - 1;

            if (sLine > endLine || sLine == endLine && sIndex > endIndex)
            {
                whitespaces.Add(new TextSpan {
                    iStartLine = endLine, iStartIndex = endIndex, iEndLine = sLine, iEndIndex = sIndex
                });
            }
        }
Пример #22
0
 protected virtual Boo.Lang.Compiler.Ast.Module ParseTestCase(string fname)
 {
     return(BooParser.ParseFile(GetTestCasePath(fname)).Modules[0]);
 }
Пример #23
0
 private static CompileUnit Parse(string fileName, string code)
 {
     return(BooParser.ParseString(fileName, code.ReIndent()));
 }