static List <IConceptInfo> DslModelFromConcepts(IEnumerable <ConceptSyntaxNode> rawConcepts) { var conceptInfos = ConceptInfoHelper.ConvertNodesToConceptInfos(rawConcepts); var dslModel = NewDslModel(new StubDslParser(rawConcepts), conceptInfos); return(dslModel.Concepts.ToList()); }
public List <string> GetCompletionKeywordsAtPosition(LineChr lineChr) { var analysisResult = GetAnalysis(lineChr); if (analysisResult.IsInsideComment || analysisResult.IsAfterAnyErrorLine(lineChr)) { return(new List <string>()); } var typingToken = analysisResult.GetTokenBeingTypedAtCursor(lineChr); if (analysisResult.KeywordToken != null && analysisResult.KeywordToken != typingToken) { var fullAnalysis = GetAnalysis(); return(fullAnalysis.NonKeywordWords); } var lastParent = analysisResult.ConceptContext.LastOrDefault(); var validConcepts = lastParent == null ? rhetosAppContext.ConceptInfoTypes.ToList() : conceptQueries.ValidConceptsForParent(lastParent.GetType()); var keywords = validConcepts .Select(concept => ConceptInfoHelper.GetKeyword(concept)) .Where(keyword => keyword != null) .Distinct() .OrderBy(keyword => keyword) .ToList(); return(keywords); }
public void GetErrorDescription() { var simpleConceptInfo = new SimpleConceptInfo { Name = "s", Data = "d" }; var refConceptInfo = new RefConceptInfo { Name = "r", Reference = simpleConceptInfo }; var refRefConceptInfo = new RefRefConceptInfo { Name = "rr", Reference = refConceptInfo }; Assert.AreEqual("Rhetos.Dsl.Test.ConceptInfoHelperTest+RefRefConceptInfo Name=rr Reference=r.s", refRefConceptInfo.GetErrorDescription()); refRefConceptInfo.Name = null; Assert.AreEqual("Rhetos.Dsl.Test.ConceptInfoHelperTest+RefRefConceptInfo Name=<null> Reference=r.s", refRefConceptInfo.GetErrorDescription()); refRefConceptInfo.Name = "rr"; refRefConceptInfo.Reference = null; Assert.AreEqual("Rhetos.Dsl.Test.ConceptInfoHelperTest+RefRefConceptInfo Name=rr Reference=<null>", refRefConceptInfo.GetErrorDescription()); refRefConceptInfo.Reference = refConceptInfo; simpleConceptInfo.Name = null; TestUtility.AssertContains(refRefConceptInfo.GetErrorDescription(), new[] { refRefConceptInfo.GetType().FullName, "Name=rr", "Reference=", "null" }); simpleConceptInfo.Name = "s"; Assert.AreEqual("<null>", ConceptInfoHelper.GetErrorDescription(null)); Assert.AreEqual(typeof(SimpleConceptInfo).FullName + " Name=s Data=<null>", new SimpleConceptInfo { Name = "s", Data = null }.GetErrorDescription()); }
public void CheckSemantics(IDslModel existingConcepts) { if (!(Dependency_ImplementationView is ExtensibleSubtypeSqlViewInfo)) { throw new DslSyntaxException(this, "This concept cannot be used together with '" + Dependency_ImplementationView.GetUserDescription() + "'. Use either " + ConceptInfoHelper.GetKeywordOrTypeName(typeof(SubtypeImplementsPropertyInfo)) + " or " + Dependency_ImplementationView.GetKeywordOrTypeName() + "."); } }
public void CheckSemantics(IDslModel existingConcepts) { if (!(PropertyInfo.DataStructure is BrowseDataStructureInfo)) { throw new DslSyntaxException($"'{this.GetKeywordOrTypeName()}' cannot be used" + $" on {PropertyInfo.DataStructure.GetKeywordOrTypeName()} ({PropertyInfo.GetUserDescription()})." + $" It may only be used on {ConceptInfoHelper.GetKeywordOrTypeName(typeof(BrowseDataStructureInfo))}."); } }
public IConceptInfo ParseNextConcept(TokenReader tokenReader, Stack <IConceptInfo> context, MultiDictionary <string, IConceptParser> conceptParsers) { var newContext = context == null ? null : new Stack <ConceptSyntaxNode>(context.Select(ci => _syntax.CreateConceptSyntaxNode(ci)).Reverse()); var parsedNode = this.Invoke(nameof(ParseNextConcept), tokenReader, newContext, conceptParsers).Item1; return(ConceptInfoHelper.ConvertNodeToConceptInfo(parsedNode)); }
public TConceptInfo QuickParse(string dsl, Stack <IConceptInfo> context) { var contextNodes = new Stack <ConceptSyntaxNode>(context .Select(ci => DslSyntax.CreateConceptSyntaxNode(ci)).Reverse()); tokenReader = GenericParserTest.TestTokenReader(dsl); ConceptSyntaxNode node = GenericParser.Parse(tokenReader, contextNodes, out var warnings).Value; return((TConceptInfo)ConceptInfoHelper.ConvertNodeToConceptInfo(node)); }
public void ParsePosition() { var simpleParser = new GenericParserHelper <SimpleConceptInfo>("abc"); var tokenReader = TestTokenReader("simple abc def", 1); var node = simpleParser.GenericParser.Parse(tokenReader, new Stack <ConceptSyntaxNode>(), out var warnings).Value; SimpleConceptInfo ci = (SimpleConceptInfo)ConceptInfoHelper.ConvertNodeToConceptInfo(node); Assert.AreEqual("def", ci.Name); TestUtility.AssertContains(tokenReader.ReportPosition(), "column 15,"); }
public void CheckSemantics(System.Collections.Generic.IEnumerable <IConceptInfo> concepts) { if (!(PropertyInfo.DataStructure is BrowseDataStructureInfo)) { throw new DslSyntaxException(string.Format( "'{0}' cannot be use on {1} ({2}). It may only be used on {3}.", this.GetKeywordOrTypeName(), PropertyInfo.DataStructure.GetKeywordOrTypeName(), PropertyInfo.GetUserDescription(), ConceptInfoHelper.GetKeywordOrTypeName(typeof(BrowseDataStructureInfo)))); } }
public void InternalCheck() { if (!(Target.DataStructure is EntityInfo)) { throw new FrameworkException(string.Format( "{0} can only be used on properties of {1}. {2} is a member of {3}.", this.GetKeywordOrTypeName(), ConceptInfoHelper.GetKeywordOrTypeName(typeof(EntityInfo)), Target.GetUserDescription(), Target.DataStructure.GetKeywordOrTypeName())); } }
public void GenerateDependenciesTest() { var dependent = new SimpleConceptInfo("dd"); dependent.GetKeyProperties(); var existingConcepts = new DslModelMock { new EntityInfo { Module = new ModuleInfo { Name = "a" }, Name = "b" }, new DataStructureInfo { Module = new ModuleInfo { Name = "c" }, Name = "d" }, new SqlViewInfo { Module = new ModuleInfo { Name = "e" }, Name = "f" }, new SqlFunctionInfo { Module = new ModuleInfo { Name = "g" }, Name = "h" }, }; var tests = new Dictionary <string, string> { { "select a.b from c.d, x.y", "SqlDependsOnDataStructureInfo c.d" }, { "select * from a.b, c.d, e.f, g.h", "SqlDependsOnDataStructureInfo a.b, SqlDependsOnDataStructureInfo c.d, " + "SqlDependsOnSqlViewInfo e.f, SqlDependsOnSqlFunctionInfo g.h" }, { "with x.y as (select * from a.b) select * from x.y", "SqlDependsOnDataStructureInfo a.b" } }; foreach (var test in tests) { Console.WriteLine("Test: " + test.Key); var dependencies = SqlAnalysis.GenerateDependencies(dependent, existingConcepts, test.Key); foreach (dynamic dependency in dependencies) { Assert.AreEqual("dd", dependency.Dependent.ToString()); } var actual = TestUtility.Dump(dependencies, dep => dep.GetType().Name + " " + ConceptInfoHelper.GetKeyProperties(((dynamic)dep).DependsOn)); Assert.AreEqual(test.Value, actual, "Input: " + test.Key); } }
public void AlternativeInitializationConcept_Embedded() { string dsl = "SIMPLE s d { ALTER1 { ALTER2 d2; } }"; var syntax = new IConceptInfo[] { new SimpleConceptInfo(), new AlternativeConcept1(), new AlternativeConcept2() }; var parsedNodes = new TestDslParser(dsl, syntax).GetConcepts(); var parsedConcepts = ConceptInfoHelper.ConvertNodesToConceptInfos(parsedNodes); // IAlternativeInitializationConcept should be parsed, but not yet initialized. Assert.AreEqual("Rhetos.Dsl.Test.DslParserTest+SimpleConceptInfo Name=s Data=d", parsedConcepts.OfType <SimpleConceptInfo>().Single().GetErrorDescription()); Assert.AreEqual("Rhetos.Dsl.Test.DslParserTest+AlternativeConcept1 Parent=s Name=<null> RefToParent=<null>", parsedConcepts.OfType <AlternativeConcept1>().Single().GetErrorDescription()); Assert.AreEqual("Rhetos.Dsl.Test.DslParserTest+AlternativeConcept2 Alter1=s.<null> Name=<null> Data=d2", parsedConcepts.OfType <AlternativeConcept2>().Single().GetErrorDescription()); Assert.AreEqual("alter1, alter2, SIMPLE", TestUtility.DumpSorted(parsedNodes, c => c.Concept.GetKeywordOrTypeName())); }
public void CheckSemantics(IDslModel existingConcepts) { var properties = existingConcepts.FindByReference <PropertyInfo>(p => p.DataStructure, this); var propertyWithoutSelector = properties .FirstOrDefault(p => !existingConcepts.FindByReference <BrowseFromPropertyInfo>(bfp => bfp.PropertyInfo, p).Any()); if (propertyWithoutSelector != null) { throw new DslSyntaxException( string.Format("Browse property {0} does not have a source selected. Probably missing '{1}'.", propertyWithoutSelector.GetUserDescription(), ConceptInfoHelper.GetKeywordOrTypeName(typeof(BrowseFromPropertyInfo)))); } }
public void ParseEnclosed() { var enclosedParser = new GenericParserHelper <EnclosedConceptInfo>("enclosed"); var stack = new Stack <ConceptSyntaxNode>(); stack.Push(enclosedParser.DslSyntax.CreateConceptSyntaxNode(new SimpleConceptInfo { Name = "a" })); var tokenReader = TestTokenReader("simple a { enclosed b; }", 3); var node = enclosedParser.GenericParser.Parse(tokenReader, stack, out var warnings).Value; var ci = (EnclosedConceptInfo)ConceptInfoHelper.ConvertNodeToConceptInfo(node); Assert.AreEqual("a", ci.Parent.Name); Assert.AreEqual("b", ci.Name); TestUtility.AssertContains(tokenReader.ReportPosition(), "before: \";"); }
public void TestMethod1() { var ic = new InitializationConcept { RhetosVersion = "1.2.3" }; Assert.AreEqual("InitializationConcept '1.2.3'", ic.GetKey()); Assert.AreEqual("InitializationConcept '1.2.3'", ic.GetShortDescription()); Assert.AreEqual("InitializationConcept '1.2.3'", ic.GetUserDescription()); Assert.AreEqual("'1.2.3'", ic.GetKeyProperties()); Assert.AreEqual("Rhetos.Dsl.InitializationConcept '1.2.3'", ic.GetFullDescription()); Assert.AreEqual(null, ic.GetKeyword()); Assert.AreEqual("InitializationConcept", ic.GetKeywordOrTypeName()); Assert.AreEqual(0, ic.GetDirectDependencies().Count()); Assert.AreEqual(0, ic.GetAllDependencies().Count()); Assert.AreEqual("Rhetos.Dsl.InitializationConcept RhetosVersion=1.2.3", ic.GetErrorDescription()); Assert.AreEqual(null, ConceptInfoHelper.GetKeyword(typeof(InitializationConcept))); Assert.AreEqual("InitializationConcept", ConceptInfoHelper.GetKeywordOrTypeName(typeof(InitializationConcept))); }
public void CheckSemantics(IDslModel existingConcepts) { if (ReferenceFromMe.DataStructure != Source) { throw new DslSyntaxException("'" + this.GetUserDescription() + "' must use a reference property that is a member of it's own data structure. Try using FilterByLinkedItems instead."); } var availableFilters = existingConcepts.FindByReference <FilterByInfo>(f => f.Source, ReferenceFromMe.Referenced) .Select(f => f.Parameter).OrderBy(f => f).ToList(); if (!availableFilters.Contains(Parameter)) { throw new DslSyntaxException(this, string.Format( "There is no {0} '{1}' on {2}. Available {0} filters are: {3}.", ConceptInfoHelper.GetKeywordOrTypeName(typeof(FilterByInfo)), Parameter, ReferenceFromMe.Referenced.GetUserDescription(), string.Join(", ", availableFilters.Select(parameter => "'" + parameter + "'")))); } }
private int GetActiveParameterForValidConcept(Type conceptType) { var activeParameter = 0; // we have parsed some members successfully for this concept type if (LastTokenParsed.ContainsKey(conceptType)) { activeParameter = ConceptInfoType.IndexOfParameter(conceptType, LastMemberReadAttempt[conceptType]); // if we have just typed a keyword OR have stopped typing a parameter (by pressing space, etc.), we need to advance to next parameter // keyword scenario is possible in nested concepts, where we already have valid parameters and are just typing a keyword var lineChr = new LineChr(Line, Chr); var atLastParsed = GetTokenAtPosition(lineChr) == LastTokenParsed[conceptType] || GetTokenLeftOfPosition(lineChr) == LastTokenParsed[conceptType]; var atKeyword = string.Equals(ConceptInfoHelper.GetKeyword(conceptType), LastTokenParsed[conceptType].Value, StringComparison.InvariantCultureIgnoreCase); if (atKeyword || !atLastParsed) { activeParameter++; } } return(activeParameter); }
public static string SignatureDescription(Type type) { var keys = new List <string>(); var parameters = new List <string>(); foreach (var member in GetParameters(type)) { if (member.IsKey) { keys.Add(ConceptMemberDescription(member)); } else { parameters.Add(ConceptMemberDescription(member)); } } var keyword = ConceptInfoHelper.GetKeywordOrTypeName(type); var keysDesc = string.Join(".", keys.Select(key => $"<{key}>")); var paramDesc = string.Join(" ", parameters.Select(parameter => $"<{parameter}>")); return($"{keyword} {keysDesc} {paramDesc}"); }
public void CheckSemantics(IDslModel concepts) { if (Module.Name != Source.Module.Name) { throw new DslSyntaxException( string.Format("Browse should be created in same module as referenced entity. Expecting {0} instead of {1}.", Source.Module, Module)); } var properties = concepts.FindByReference <PropertyInfo>(p => p.DataStructure, this); var propertyWithoutSelector = properties .Where(p => concepts.FindByReference <BrowseFromPropertyInfo>(bfp => bfp.PropertyInfo, p).Count() == 0) .FirstOrDefault(); if (propertyWithoutSelector != null) { throw new DslSyntaxException( string.Format("Browse property {0} does not have a source selected. Probably missing '{1}'.", propertyWithoutSelector.GetUserDescription(), ConceptInfoHelper.GetKeywordOrTypeName(typeof(BrowseFromPropertyInfo)))); } }
public void GenerateDependenciesTestToObject() { var dependent = new SimpleConceptInfo("dd"); dependent.GetKeyProperties(); var existingConcepts = new DslModelMock { new EntityInfo { Module = new ModuleInfo { Name = "a" }, Name = "b" }, new DataStructureInfo { Module = new ModuleInfo { Name = "c" }, Name = "d" }, new SqlViewInfo { Module = new ModuleInfo { Name = "e" }, Name = "f" }, new SqlFunctionInfo { Module = new ModuleInfo { Name = "g" }, Name = "h" }, new EntityInfo { Module = new ModuleInfo { Name = "x" }, Name = "y" }, new SqlViewInfo { Module = new ModuleInfo { Name = "x" }, Name = "y" }, new SqlFunctionInfo { Module = new ModuleInfo { Name = "x" }, Name = "y" }, }; var tests = new Dictionary <string, string> { { "a.a", "" }, { "b.b", "" }, { "a.b.a", "" }, { "a.a.b", "" }, { "a", "" }, { "b", "" }, { "a.b", "SqlDependsOnDataStructureInfo a.b" }, { "c.d", "SqlDependsOnDataStructureInfo c.d" }, { "e.f", "SqlDependsOnSqlViewInfo e.f" }, { "g.h", "" }, { "g.h(SYSDATETIME())", "SqlDependsOnSqlFunctionInfo g.h" }, { "x.y(SYSDATETIME())", "SqlDependsOnSqlFunctionInfo x.y" }, { "x.y", "SqlDependsOnDataStructureInfo x.y, SqlDependsOnSqlViewInfo x.y" }, }; foreach (var test in tests) { Console.WriteLine("Test: " + test.Key); var dependencies = SqlAnalysis.GenerateDependenciesToObject(dependent, existingConcepts, test.Key); foreach (dynamic dependency in dependencies) { Assert.AreEqual("dd", dependency.Dependent.ToString()); } var actual = TestUtility.Dump(dependencies, dep => dep.GetType().Name + " " + ConceptInfoHelper.GetKeyProperties(((dynamic)dep).DependsOn)); Assert.AreEqual(test.Value, actual, "Input: " + test.Key); } }