public void SchemaParser_ShouldParseAggregationType() { var schema = @" SCHEMA IFC4; TYPE IfcPositiveInteger = integer; END_TYPE; TYPE IfcArcIndex = LIST [3:3] OF IfcPositiveInteger; END_TYPE; END_SCHEMA; "; var parser = new ExpressParser(); var result = parser.Parse(schema); Assert.IsTrue(result.Success, result.GetSummary()); var ifc = result.Schemas.Single(); Assert.AreEqual(1, ifc.Declarations.Count); var decl = ifc.Declarations.Single(); Assert.AreEqual("IfcArcIndex", decl.Name, true); Assert.Inconclusive("TODO"); //TODO: aggregation types //Assert.AreEqual("LIST [3:3] OF IfcPositiveInteger", ((TypeDeclaration)decl).UnderlyingType.Value, true); }
public void Ifc_SemanticModel_ShouldCreateSymbolTable(string path) { var parser = new ExpressParser(); using (var stream = File.Open(path, FileMode.Open, FileAccess.Read)) { var result = parser.Parse(stream); Assert.IsTrue(result.Success); var builder = new SymbolTableBuilder(result.Schemas); var symbolTable = builder.Build(); var declarations = new DeclarationSyntaxWalker(); foreach (var schema in result.Schemas) { schema.Accept(declarations); } foreach (var declaration in declarations.Declarations) { if (declaration is LocalRuleDeclaration) { continue; } var symbolInfo = symbolTable.GetSymbolInfo(declaration); Assert.IsNotNull(symbolInfo, $"Missing ISymbolInfo for {declaration.Name}({declaration.Kind})"); ValidateSymbolInfo(symbolInfo); } } }
public void SchemaParser_ShouldParseCustomType() { var schema = @" SCHEMA IFC4; TYPE IfcLabel = STRING; END_TYPE; TYPE IfcBoxAlignment = IfcLabel; END_TYPE; END_SCHEMA;"; var parser = new ExpressParser(); var result = parser.Parse(schema); Assert.IsTrue(result.Success, result.GetSummary()); var ifc = result.Schemas.Single(); Assert.AreEqual(1, ifc.Declarations.Count); var decl = ifc.Declarations.Single(); Assert.Inconclusive("TODO"); }
public static SchemaModel Load(string schemaData, string sourceIdentifier) { var parser = new ExpressParser(); var result = parser.Parse(schemaData, sourceIdentifier); if (!result) { throw new Exception("Unexpected parser error: " + parser.Errors.LastOrDefault()); } return(parser.SchemaInstance); }
private static SchemaModel GetSchema(string data, string source) { var parser = new ExpressParser(); var result = parser.Parse(data, source); if (!result) { throw new Exception("Error parsing schema file"); } return(parser.SchemaInstance); }
public void ParseIfc2x3() { var parser = new ExpressParser(); var result = parser.Parse(SchemasDefinitions.IFC2X3_TC1); Assert.IsTrue(result); var wall = parser.SchemaInstance.Get<EntityDefinition>(d => d.Name == "IfcWall").FirstOrDefault(); Assert.IsNotNull(wall, "There should be a definition of IfcWall entity."); var wallExplicitAttrs = wall.AllExplicitAttributes.ToList(); Assert.IsTrue(wallExplicitAttrs.Any(), "There should be some explicit attributes for a wall."); Assert.AreEqual(8, wallExplicitAttrs.Count, "There should be 8 explicit attributes for a wall."); }
public void SchemaParser_ShouldParseSchemaVersionId() { var input = @" SCHEMA TEST 'Test version id'; END_SCHEMA;"; var parser = new ExpressParser(); var result = parser.Parse(input); Assert.AreEqual(true, result.Success); Assert.AreEqual(1, result.Schemas.Length); Assert.AreEqual("Test version id", result.Schemas[0].SchemaVersionId); }
public void SchemaParser_ShouldParseEmptySchema() { var input = @" SCHEMA TEST; END_SCHEMA; "; var parser = new ExpressParser(); var result = parser.Parse(input); Assert.AreEqual(true, result.Success); Assert.AreEqual(1, result.Schemas.Length); Assert.AreEqual("test", result.Schemas[0].Name, true); }
public void SchemaParser_ShouldNotThrowOnInvalidFile() { var schema = @" SCHEMA IFC4; TYPE IfcArcIndex = LIST [3:3] OF REAL; END_TYPE; "; var parser = new ExpressParser(); var result = parser.Parse(schema); Assert.IsFalse(result.Success); }
public void SchemaParser_ShouldParseArrayDataType() { var schema = @" SCHEMA IFC4; TYPE IfcComplexNumber = ARRAY [1:2] OF REAL; END_TYPE; END_SCHEMA;"; var parser = new ExpressParser(); var result = parser.Parse(schema); Assert.IsTrue(result.Success, result.GetSummary()); }
public void Ifc_SchemaParser_ShouldParseIfcFile(string path) { var parser = new ExpressParser(); using (var stream = File.Open(path, FileMode.Open, FileAccess.Read)) { var result = parser.Parse(stream); foreach (var error in result.Errors) { Console.WriteLine(error.ToString()); } Assert.AreEqual(0, result.Errors.Length, result.Errors.FirstOrDefault()?.ToString()); } }
public void DeclarationCollectingPass_ShouldPassTestCasesWithoutErrors(string fileName) { var parser = new ExpressParser(); using (var stream = File.Open($@"..\..\..\..\test\{fileName}.exp", FileMode.Open, FileAccess.Read)) { var errors = new List <ParsingError>(); var tokens = Tokenizer.Tokenize(new StreamReader(stream, Encoding.ASCII)).ToArray(); var declarationPass = new DeclarationPass(tokens, errors); var syntaxPass = new SyntaxAnalysisPass(tokens, errors); var builder = new SyntaxTreeBuilder(); declarationPass.Run(builder); syntaxPass.Run(builder); foreach (var error in errors) { Console.WriteLine(error.ToString()); } Assert.AreEqual(0, errors.Count); } }
public void ExpressParser_ShouldParseNestedQueryScopes() { var input = @" SCHEMA TEST; ENTITY Test; Voids : SET [1:?] OF ARRAY [0:10] OF REAL; WHERE VoidsHaveAdvancedFaces : SIZEOF (QUERY (Vsh <* Voids | SIZEOF (QUERY (Afs <* Vsh | (NOT ('IFC4.IFCADVANCEDFACE' IN TYPEOF(Afs))) )) = 0 )) = 0; END_ENTITY; END_SCHEMA; "; var parser = new ExpressParser(); var result = parser.Parse(input); Assert.IsTrue(result.Success, result.GetSummary()); }
public void SchemaParser_ShouldParseSimpleType() { var schema = @" SCHEMA IFC4; TYPE IfcStrippedOptional = BOOLEAN; END_TYPE; END_SCHEMA;"; var parser = new ExpressParser(); var result = parser.Parse(schema); Assert.IsTrue(result.Success, result.GetSummary()); var ifc = result.Schemas.Single(); Assert.AreEqual(1, ifc.Declarations.Count); var decl = ifc.Declarations.OfType <TypeDeclaration>().Single(); Assert.AreEqual("IfcStrippedOptional", decl.Name, true); Assert.AreEqual(SyntaxNodeKind.BooleanDataType, decl.UnderlyingType.Kind); }
public void ParseIfc2x4() { var parser = new ExpressParser(); var result = parser.Parse(SchemasDefinitions.IFC4); Assert.IsTrue(result); }
static void Main(string[] args) { if (args.Length == 0) { Console.WriteLine("Usage: express2owl base_iri input_directory [single] [debug]"); Environment.Exit(-1); } string dir = args[1]; FileAttributes att = File.GetAttributes(dir); if (!Directory.Exists(dir)) { Environment.Exit(-1); } ExpressModelGenerator generator; int errors = 0; int successes = 0; bool single = false; bool debug = false; if (args.Length > 2) { single = (args[2].Equals("true")) ? true : false; if (args.Length == 4) { debug = (args[3].Equals("true")) ? true : false; } } List <Schema> schemas = new List <Schema>(); Dictionary <string, string> dict = new Dictionary <string, string>(); foreach (string inputFile in Directory.GetFiles(dir)) { if (!inputFile.EndsWith(".exp")) { continue; } string text = File.ReadAllText(inputFile); ExpressLexer lexer = new ExpressLexer(text); ExpressParser parser = new ExpressParser(lexer); ParseResult res = parser.Parse(); if (res.Errors.Count > 0) { Console.WriteLine($"[ERROR] Failed Processing {inputFile}"); foreach (ParseError err in res.Errors) { Console.WriteLine($"***** {err.Message}"); } errors++; continue; } generator = new ExpressModelGenerator(res.Root, args[0]); Schema schema = generator.GenerateSchema(); schemas.Add(schema); dict.Add(schema.Name, inputFile.Replace(".exp", ".owl")); //generator.GenerateOWl(); Console.WriteLine($"[INFO] Successfully Processed {inputFile}"); successes++; } if (single) { TextWriter writer; if (debug) { writer = Console.Out; } else { writer = new StreamWriter(dir + ".owl"); } writer.WriteLine("Prefix(owl:=<http://www.w3.org/2002/07/owl#>)"); writer.WriteLine("Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)"); writer.WriteLine("Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)"); writer.WriteLine("Prefix(xml:=<http://www.w3.org/XML/1998/namespace>)"); writer.WriteLine("Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)"); writer.WriteLine($"Prefix(:=<{args[0]}#>)\n"); writer.WriteLine($"Ontology(<{args[0]}>"); foreach (Schema s in schemas) { s.GenerateOWL(writer, true); } writer.WriteLine(")"); writer.Close(); if (debug) { Console.ReadKey(); } } else { TextWriter writer = Console.Out;; string filename; foreach (Schema s in schemas) { dict.TryGetValue(s.Name, out filename); if (filename == null) { continue; } if (!debug) { writer = new StreamWriter(filename); s.GenerateOWL(writer, false); writer.Close(); } else { s.GenerateOWL(writer, false); } } if (debug) { writer.Close(); } } Console.WriteLine($"[INFO] {errors} errors, {successes} successes"); Console.ReadKey(); Environment.Exit(0); }