private void ParseMappingExtras(MapParserContext context, MapLexer lexer, ExpressiveMapping mapping) { // Consume the preamble lexer.Consume(TokenKind.LeftCurly); lexer.Consume(TokenKind.Keyword, "note"); // Grab the note, and attach it to the mapping var note = lexer.Consume(TokenKind.String); mapping.Notes.Add(note); // Consume the postamble lexer.Consume(TokenKind.Semicolon); lexer.Consume(TokenKind.RightCurly); }
private void BuildExamples(ExpressiveMapping map, MappingReportAttribute viewAttribute) { var builder = new StringBuilder(); foreach (var attributeExample in map.TargetAttribute.Examples) { builder.Clear(); var haveExpressionExample = BuildExampleExpression(builder, map.Expression, attributeExample.Key); // Build the example entry and add it viewAttribute.Examples.Add(new MappingReportExample { MapId = map.Id, ExampleId = attributeExample.Key, Target = attributeExample.Value, Expression = haveExpressionExample ? builder.ToString() : null }); } }
private void ParseStatement(MapParserContext context, MapLexer lexer) { // Constructs: // examples ... // ignore ... // with ... // { statements } if (lexer.Token.Kind == TokenKind.Keyword) { if (lexer.Token.Text == "with") { ParseWith(context, lexer); return; } else if (lexer.Token.Text == "name") { ParseName(context, lexer); return; } else if (lexer.Token.Text == "examples") { ParseExamples(context, lexer); return; } else if (lexer.Token.Text == "ignore") { ParseIgnore(context, lexer); return; } else { throw new ParserException($"Unexpected keyword '{lexer.Token.Text}'.", lexer.Token); } } else if (lexer.Token.Kind == TokenKind.LeftCurly) { lexer.Consume(TokenKind.LeftCurly); while (lexer.Token.Kind != TokenKind.RightCurly) { ParseStatement(context, lexer); } lexer.Consume(TokenKind.RightCurly); return; } // Constructs: // ident = model(ident); // ident:ident = ident:ident; var lhs = CompoundIdentifier.Parse(lexer); lexer.Consume(TokenKind.Equals); var rhs = expressionParser.Parse(lexer, context); // A little special handling for the model function if (rhs.FunctionName == "model") { var model = rhs.Arguments.First().Model; if (model == null) { throw new ParserException("The 'model' function requires a model argument."); } context.AddModelAlias(lhs.Parts.First(), model); lexer.Consume(TokenKind.Semicolon); } else { var target = context.Resolve(lhs); var mapCount = context.MapList.Maps.Where(x => x.TargetAttribute.Equals(target)).Count(); var mapping = new ExpressiveMapping(IdNames.Substring(mapCount, 1), target, rhs); context.MapList.Maps.Add(mapping); if (lexer.Token.Kind == TokenKind.LeftCurly) { ParseMappingExtras(context, lexer, mapping); } else { lexer.Consume(TokenKind.Semicolon); } } }