private JSchema?MapTypeField(ASTTypeField field)
        {
            var _mod  = field.Types.First().Value;
            var _type = field.Types.Last().Value;

            return(MapDefinition(_mod, _type, field));
        }
        public void BasicParserTest()
        {
            var code      = @"
type Person =
    @ The First Name of the Person
    FirstName: String;
";
            var tokens    = new Lexer().Lex(code);
            var parseTree = new Parser(tokens).Parse();

            Assert.NotNull(parseTree);

            List <IASTNode> list = parseTree.ToList();

            Assert.Single(list);

            ASTType t = list[0] as ASTType;

            Assert.Equal("Person", t.Name);
            Assert.Empty(t.Parameters);
            Assert.Single(t.Fields);


            ASTTypeField field = t.Fields[0];

            Assert.Single(field.Annotations);
            Assert.True(field.Annotations[0] is ASTAnnotation);
            Assert.Equal("The First Name of the Person", field.Annotations[0].Value);

            Assert.Equal("FirstName", field.Name);
            Assert.Equal(Helpers.ToTypeDefinition(new [] { "String" }), field.Type);
        }
        public void FieldRestrictionsAnnotations()
        {
            var code      = @"
type Person =
    FirstName: String
        & min 2

        @ Should not be 30
        & max 30
    ;
";
            var tokens    = new Lexer().Lex(code);
            var parseTree = new Parser(tokens).Parse().ToList();

            Assert.NotNull(parseTree);

            Assert.Single(parseTree);
            ASTType t = (ASTType)parseTree[0];

            Assert.Single(t.Fields);
            Assert.Equal(2, t.Fields[0].Restrictions.Count);

            ASTTypeField field = t.Fields[0];

            Assert.Equal(2, field.Restrictions.Count);
            Assert.Equal("Should not be 30", field.Restrictions[1].Annotations.First().Value);
        }
        public override string VisitASTTypeField(ASTTypeField astTypeField)
        {
            var(first, last) = (astTypeField.Types.First().Value, astTypeField.Types.Last().Value);
            var _type = (first, last) switch
            {
                ("String", _) => "string",
                _ => "string"
            };

            return($@"    public {_type} {astTypeField.Name};");
        }
Example #5
0
        public void MultipleFieldsParserTest()
        {
            var code      = @"
type Person =
    @ The First Name of the Person
    @ A second Annotation is always cool to add
    FirstName: String;
    LastName: String;
    @ Age as a number is weird ofc!
    Age: Number;
";
            var tokens    = new Lexer().Lex(code);
            var parseTree = new Parser(tokens).Parse();

            Assert.NotNull(parseTree);

            List <IASTNode> list = parseTree.ToList();

            Assert.Single(list);

            ASTType t = list[0] as ASTType;

            Assert.Equal("Person", t.Name);
            Assert.Empty(t.Parameters);
            Assert.Equal(3, t.Fields.Count());


            List <ASTTypeField> fields = t.Fields.ToList();
            ASTTypeField        field  = fields.First();

            Assert.Equal(2, field.Annotations.Count());
            Assert.True(field.Annotations.First() is ASTAnnotation);
            Assert.Equal("The First Name of the Person", field.Annotations.First().Value);
            Assert.Equal("A second Annotation is always cool to add", field.Annotations.ToList()[1].Value);

            Assert.Equal("FirstName", field.Name);
            Assert.Equal("String", field.Type.First().Value);


            ASTTypeField lastNameField = fields[1];

            Assert.Equal("LastName", lastNameField.Name);
            Assert.Equal("String", lastNameField.Type.First().Value);
            Assert.Empty(lastNameField.Annotations);

            ASTTypeField ageField = fields[2];

            Assert.Equal("Age", ageField.Name);
            Assert.Equal(new List <ASTTypeDefinition>()
            {
                new ASTTypeDefinition("Number")
            }, ageField.Type);
            Assert.Single(ageField.Annotations);
        }
        public override string VisitASTTypeField(ASTTypeField astTypeField)
        {
            string typeDef      = string.Join(" ", astTypeField.Type.Select(Visit));
            string restrictions = string.Join("\n", astTypeField.Restrictions.Select(Visit));

            if (astTypeField.Restrictions.Count() > 0)
            {
                return($"    {astTypeField.Name}: {typeDef}\n{restrictions}\n    ;");
            }
            else
            {
                return($"    {astTypeField.Name}: {typeDef};");
            }
        }
Example #7
0
        public override string VisitASTTypeField(ASTTypeField astTypeField)
        {
            var _mod  = astTypeField.Type.First().Value;
            var _type = astTypeField.Type.Last().Value;

            return($@"
<tr>
    <td>{astTypeField.Name}</td>
    <td>{string.Join(" ", astTypeField.Type.Select(t => t.Value).ToList())}</td>
    <td>{_mod != "Maybe"}</td>
    <td>{string.Join(" ", astTypeField.Annotations.Select(a => a.Value).ToList())}</td>
</tr>
");
        }
 public T Visit(IASTNode node)
 {
     return(node switch
     {
         ASTType n => VisitASTType(n),
         ASTTypeField n => VisitASTTypeField(n),
         ASTTypeDefinition n => VisitASTTypeDefinition(n),
         ASTRestriction n => VisitASTRestriction(n),
         ASTAlias n => VisitASTAlias(n),
         ASTData n => VisitASTData(n),
         ASTAnnotation n => VisitASTAnnotation(n),
         ASTDirective n => VisitASTDirective(n),
         ASTChoice n => VisitASTChoice(n),
         ASTOption n => VisitASTOption(n),
         ASTChapter n => VisitASTChapter(n),
         ASTParagraph n => VisitASTParagraph(n),
         _ => VisitDefault(node),
     });
Example #9
0
        public override string VisitASTTypeField(ASTTypeField astTypeField)
        {
            var _mod  = astTypeField.Types.First().Value;
            var _type = astTypeField.Types.Last().Value;

            var restrictions = String.Join(Environment.NewLine, astTypeField.Restrictions.Select(r => $"{r.Key} {r.Value}"));

            return($@"
<tr>
    <td>{astTypeField.Name}</td>
    <td>{string.Join(" ", astTypeField.Types.Select(t => t.Value).ToList())}</td>
    <td>{_mod != "Maybe"}</td>
    <td>{restrictions}</td>
    <td>
        From module: <a href=""/index.html?path=preview&module={astTypeField.Module}"" target='_parent'>{astTypeField.Module}</a>
        <br />
        {string.Join(" ", astTypeField.Annotations.Select(a => a.Value).ToList())}
    </td>
</tr>
");
        }
Example #10
0
 public override string VisitASTTypeField(ASTTypeField astTypeField)
 {
     return("");
 }
Example #11
0
 public override T VisitASTTypeField(ASTTypeField astTypeField) => d;
Example #12
0
 public override XmlSchemaObject?VisitASTTypeField(ASTTypeField astTypeField)
 {
     return(Mapper.Element(astTypeField));
 }
        public override string VisitASTTypeField(ASTTypeField astTypeField)
        {
            var t = (astTypeField.Types.First().Value, astTypeField.Types.Last().Value);

            return($@"    public {CSharpHelpers.ToCSharpKeyword(t)} {astTypeField.Name} {{ get; set; }}");
        }
Example #14
0
 public override IEnumerable <string> VisitASTTypeField(ASTTypeField astTypeField)
 {
     yield return(astTypeField.Name);
 }