public static IEnumerable <ASTRestriction> CreateRestrictions(IParser parser, TokenType root) { var depth = root == TokenType.KW_Alias ? 1 : 2; var annotations = ASTAnnotation.Parse(parser); parser.TryConsume(TokenType.And, out Token? t); while (!(t is null)) { var word = parser.Consume(TokenType.Word); var key = word.Value.Trim(); var numberValue = parser.TryConsume(TokenType.Number); var stringValue = parser.TryConsume(TokenType.String); var patternValue = parser.TryConsume(TokenType.Pattern); if (numberValue != null) { yield return(new ASTRestriction(key, numberValue.Value, annotations, numberValue, depth)); } else if (stringValue != null) { yield return(new ASTRestriction(key, stringValue.Value, annotations, stringValue, depth)); } else if (patternValue != null) { yield return(new ASTRestriction(key, patternValue.Value, annotations, patternValue, depth)); } annotations = ASTAnnotation.Parse(parser); parser.TryConsume(TokenType.And, out t); } }
public ASTTypeField(IParser parser) { this.Restrictions = new List <ASTRestriction>(); this.Annotations = ASTAnnotation.Parse(parser).ToList(); this.Name = parser.Consume(TokenType.Identifier).Value; Token Separator = parser.Consume(TokenType.Separator); this.Type = ASTTypeDefinition.ParseType(parser).ToList(); this.Restrictions = ASTRestriction.CreateRestrictions(parser).ToList(); parser.Consume(TokenType.EndStatement); }
public static IEnumerable <ASTOption> Parse(IParser parser) { var annotations = ASTAnnotation.Parse(parser); parser.TryConsume(TokenType.Or, out Token t); while (!(t is null)) { var value = parser.Consume(TokenType.String); yield return(new ASTOption(value.Value.Substring(1, value.Value.Length - 2), annotations)); annotations = ASTAnnotation.Parse(parser); parser.TryConsume(TokenType.Or, out t); } }
public static ASTTypeField Parse(IParser parser) { var result = new ASTTypeField(); result.Restrictions = new List <ASTRestriction>(); result.Annotations = ASTAnnotation.Parse(parser).ToList(); result.Name = parser.Consume(TokenType.Identifier).Value; Token Separator = parser.Consume(TokenType.Separator); result.Type = ASTTypeDefinition.ParseType(parser).ToList(); result.Restrictions = ASTRestriction.CreateRestrictions(parser, TokenType.KW_Type).ToList(); parser.Consume(TokenType.EndStatement); return(result); }
public static IEnumerable <ASTRestriction> CreateRestrictions(IParser parser) { var annotations = ASTAnnotation.Parse(parser); parser.TryConsume(TokenType.And, out Token t); while (!(t is null)) { var word = parser.Consume(TokenType.Word); var value = parser.Consume(TokenType.Number); yield return(new ASTRestriction(word.Value, value.Value.ToString(), annotations)); annotations = ASTAnnotation.Parse(parser); parser.TryConsume(TokenType.And, out t); } }
public static IEnumerable <ASTDataOption> Parse(IParser parser) { var annotations = ASTAnnotation.Parse(parser); parser.TryConsume(TokenType.Or, out Token? t); while (!(t is null)) { var id = parser.Consume(TokenType.Identifier); var parameters = parser.ConsumeWhile(TokenType.GenericParameter); ASTDataOption r = new ASTDataOption(); r.Name = id.Value; r.Parameters = parameters.Select(p => p.Value).ToList(); r.Annotations = annotations; yield return(r); annotations = ASTAnnotation.Parse(parser); parser.TryConsume(TokenType.Or, out t); } }