private ICgFile CreateContent(IPsiModule module, string text)
        {
            var generatedLexer = new CgLexerGenerated(new StringBuffer(text));
            var file           = new CgParser(generatedLexer.ToCachingLexer(), myIntern).ParseFile();

            if (file == null)
            {
                throw new ElementFactoryException("Cannot create IFile");
            }
            SandBox.CreateSandBoxFor(file, module);
            return(file.Children().OfType <ICgFile>().First());
        }
        private INTriplesFile CreateNTriplesFile(string text, bool restoreWhitespaces = false)
        {
            var node = this.CreateParser(text).ParseNTriplesFile(false, restoreWhitespaces) as INTriplesFile;

            if (node == null)
            {
                throw new ElementFactoryException(string.Format("Cannot create file '{0}'", text));
            }

            SandBox.CreateSandBoxFor(node, this.myModule);
            return(node);
        }
        public IJsonNewLiteralExpression CreateStringLiteral(string literal)
        {
            var parser = CreateParser($"\"{literal}\"");
            var node   = parser.ParseLiteral();

            if (node == null)
            {
                throw new ElementFactoryException(string.Format("Cannot create expression '{0}'", literal));
            }
            SandBox.CreateSandBoxFor(node, myModule, myLanguageService.LanguageType);
            return(node);
        }
예제 #4
0
        private static ICSharpFile ParseFile(IPsiSourceFile psiSourceFile, IPsiModule primaryPsiModule)
        {
            var languageService =
                CSharpLanguage.Instance.LanguageService().NotNull("CSharp language service not available");
            ILexer lexer        = languageService.CreateCachingLexer(psiSourceFile.Document.Buffer);
            var    csharpParser = (ICSharpParser)languageService.CreateParser(lexer, primaryPsiModule, psiSourceFile);

            csharpParser.SetChameleonExpansionMode(true);
            var psiFile = (ICSharpFile)csharpParser.ParseFile();

            SandBox.CreateSandBoxFor(psiFile, primaryPsiModule);
            return(psiFile);
        }
예제 #5
0
        public override IRuleDeclaration CreateRuleDeclaration(string name, bool hasBraceParameters = false)
        {
            string braceParameters = "";

            if (hasBraceParameters)
            {
                braceParameters = " {ROLE, getter} ";
            }
            var node = CreateParser(name + braceParameters + "\n" + ":" + "\n" + ";").ParsePsiFile(false) as IPsiFile;

            if (node == null)
            {
                throw new ElementFactoryException(string.Format("Cannot create expression '{0}'", name + braceParameters + "\n" + ":" + "\n" + ";"));
            }
            SandBox.CreateSandBoxFor(node, myModule);
            var ruleDeclaration = node.FirstChild as IRuleDeclaration;

            if (ruleDeclaration != null)
            {
                return(ruleDeclaration);
            }
            throw new ElementFactoryException(string.Format("Cannot create expression '{0}'", name));
        }
예제 #6
0
        public override IRuleDeclaration CreateRuleDeclaration(string name, bool hasBraceParameters, IList <Pair <string, string> > variableParameters)
        {
            if (variableParameters.Count == 0)
            {
                return(CreateRuleDeclaration(name, hasBraceParameters));
            }

            string braceParameters = "";

            if (hasBraceParameters)
            {
                braceParameters = " {ROLE, getter} ";
            }

            string variableParametersString = " [";

            foreach (var variableParameter in variableParameters)
            {
                variableParametersString = variableParametersString + variableParameter.Second + " " + variableParameter.First + ",";
            }
            variableParametersString = variableParametersString.Substring(0, variableParametersString.Length - 1) + "]";

            var node = CreateParser(name + braceParameters + variableParametersString + "\n" + ":" + "\n" + ";").ParsePsiFile(false) as IPsiFile;

            if (node == null)
            {
                throw new ElementFactoryException(string.Format("Cannot create expression '{0}'", name + braceParameters + variableParametersString + "\n" + ":" + "\n" + ";"));
            }
            SandBox.CreateSandBoxFor(node, myModule);
            var ruleDeclaration = node.FirstChild as IRuleDeclaration;

            if (ruleDeclaration != null)
            {
                return(ruleDeclaration);
            }
            throw new ElementFactoryException(string.Format("Cannot create expression '{0}'", name));
        }
        private ITreeNode CreateExpression(string format, string name)
        {
            ITreeNode node = CreateParser(name).ParseLexFile(false) as ILexFile;

            if (node == null)
            {
                throw new ElementFactoryException(string.Format("Cannot create expression '{0}'", format));
            }
            SandBox.CreateSandBoxFor(node, myModule);

            var child = node;

            while (child.FirstChild != null)
            {
                child = child.FirstChild;
            }

            if (child is IIdentifier)
            {
                return(child);
            }

            throw new ElementFactoryException(string.Format("Cannot create expression '{0}'" + name, format));
        }