Introduction

This document will eventually have a full specification for Cadl. For now, it just has the grammar below.

1 Lexical Grammar

SourceCharacter : any Unicode code point InputElement : Token Trivia Token : Keyword Identifier NumericLiteral StringLiteral Punctuator Trivia : Comment WhiteSpace Keyword : BooleanLiteral import model namespace op extends using Identifier : IdentifierName but not Keyword IdentifierName : IdentifierStart IdentifierName IdentifierContinue IdentifierStart : IdentifierContinue but not DecimalDigit IdentifierContinue : AsciiLetter DecimalDigit $ _ any assigned Unicode code point greater than U+007F that does not have any of the following property values: General_Category=Surrogate, Control or Private_Use, Noncharacter_Code_Point=True, or Pattern_White_Space=True AsciiLetter : one of A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z BooleanLiteral : true false NumericLiteral : DecimalLiteral HexIntegerLiteral BinaryIntegerLiteral DecimalLiteral : DecimalIntegerLiteral . DecimalDigits ExponentPartopt DecimalIntegerLiteral ExponentPartopt DecimalIntegerLiteral : DecimalDigits + DecimalDigits - DecimalDigits DecimalDigits : DecimalDigit DecimalDigits DecimalDigit DecimalDigit : one of 0 1 2 3 4 5 6 7 8 9 ExponentPart : e DecimalIntegerLiteral DecimalIntegerInteger : DecimalDigits + DecimalDigits - DecimalDigits HexIntegerLiteral : 0x HexDigits HexDigits : HexDigit HexDigits HexDigit HexDigit : one of 0 1 2 3 4 5 6 7 8 9 A B C D E F a b c d e f BinaryIntegerLiteral : 0b BinaryDigits BinaryDigits : BinaryDigit BinaryDigits BinaryDigit BinaryDigit : one of 0 1 StringLiteral : " StringCharactersopt " """ TripleQuotedStringCharactersopt """ StringCharacters : StringCharacter StringCharactersopt StringCharacter : SourceCharacter but not one of " or \ or LineTerminator \ EscapeCharacter TripleQuotedStringCharacters : TripleQuotedStringCharacter TripleQuotedStringCharactersopt TripleQuotedStringCharacter : SourceCharacter but not one of " or \ \ EscapeCharacter EscapeCharacter : one of " r n t \ Punctuator : one of | ? = & : , ; . < > ( ) { } [ ] @ ... WhiteSpace : <TAB> <LF> <VT> <FF> <CR> <SP> <NEL> <LRM> <RLM> <LS> <PS> Comment : MultiLineComment SingleLineComment MultiLineComment : /* MultiLineCommentCharsopt */ MultiLineCommentChars : MultiLineNotAsteriskChar MultiLineCommentCharsopt * PostAsteriskCommentCharsopt PostAsteriskCommentChars : MultiLineNotForwardSlashOrAsteriskChar MultiLineCommentCharsopt * PostAsteriskCommentCharsopt MultiLineNotAsteriskChar : SourceCharacter but not * MultiLineNotForwardSlashOrAsteriskChar : SourceCharacter but not one of / or * SingleLineComment : // SingleLineCommentCharsopt SingleLineCommentChars : SingleLineCommentChar SingleLineCommentCharsopt SingleLineCommentChar : SourceCharacter but not LineTerminator

2 Syntactic Grammar

CadlScriptItemList : CadlScriptItemListopt CadlScriptItem CadlScriptItem : BlocklessNamespaceStatement ImportStatement Statement BlocklessNamespaceStatement : DecoratorListopt namespace IdentifierOrMemberExpression ; ImportStatement : import StringLiteral ; StatementList : StatementListopt Statement Statement : ModelStatement InterfaceStatement NamespaceStatement OperationStatement UsingStatement EnumStatement AliasStatement ; UsingStatement : using IdentifierOrMemberExpression ; ModelStatement : DecoratorListopt model Identifier TemplateParametersopt ModelHeritageopt { ModelBodyopt } ModelHeritage : extends ReferenceExpression is ReferenceExpression ModelBody : ModelPropertyList ,opt ModelPropertyList ;opt ModelPropertyList : ModelProperty ModelPropertyList , ModelProperty ModelPropertyList ; ModelProperty ModelProperty : ModelSpreadProperty DecoratorListopt Identifier ?opt : Expression DecoratorListopt StringLiteral ?opt : Expression ModelSpreadProperty : ... ReferenceExpression InterfaceStatement : interface Identifier TemplateParametersopt InterfaceHeritageopt { InterfaceBodyopt } InterfaceHeritage : mixes ReferenceExpressionList InterfaceBody InterfaceMemberList ;opt InterfaceMemberList : InterfaceMember InterfaceMemberList ; InterfaceMember InterfaceMember : Identifier ( ModelPropertyListopt ) : Expression UnionStatement : DecoratorListopt union Identifier TemplateParametersopt { UnionBodyopt } UnionBody : UnionVariantList ;opt UnionVariantList : UnionVariant UnionVariantList ; UnionVariant UnionVariant : DecoratorListopt Identifier : Expression DecoratorListopt StringLiteral : Expression EnumStatement : DecoratorListopt enum Identifier { EnumBodyopt } EnumBody : EnumMemberList ,opt EnumMemberList ;opt EnumMemberList : EnumMember EnumMemberList , EnumMember EnumMemberList ; EnumMember EnumMember : DecoratorListopt Identifier EnumMemberValueopt DecoratorListopt StringLiteral EnumMemberValueopt EnumMemberValue : : StringLiteral : NumericLiteral AliasStatement : alias Identifier TemplateParametersopt = Expression TemplateParameters < IdentifierList > IdentifierList : Identifier IdentifierList , Identifier NamespaceStatement : DecoratorListopt namespace IdentifierOrMemberExpression { StatementListopt } OperationStatement : DecoratorListopt op Identifier ( ModelPropertyListopt ) : Expression ; Expression : UnionExpressionOrHigher UnionExpressionOrHigher : IntersectionExpressionOrHigher |opt UnionExpressionOrHigher | IntersectionExpressionOrHigher IntersectionExpressionOrHigher : ArrayExpressionOrHigher &opt IntersectionExpressionOrHigher & ArrayExpressionOrHigher ArrayExpressionOrHigher : PrimaryExpression ArrayExpressionOrHigher [ ] PrimaryExpression : Literal ReferenceExpression ParenthesizedExpression ModelExpression TupleExpression Literal : StringLiteral BooleanLiteral NumericLiteral ReferenceExpression : IdentifierOrMemberExpression TemplateArgumentsopt ReferenceExpressionList : ReferenceExpression ReferenceExpressionList , ReferenceExpression IdentifierOrMemberExpression : Identifier IdentifierOrMemberExpression . Identifier TemplateArguments : < ExpressionList > ParenthesizedExpression : ( Expression ) ModelExpression : { ModelBodyopt } TupleExpression : [ ExpressionList ] ExpressionList : Expression ExpressionList , Expression DecoratorList : DecoratorListopt Decorator Decorator : @ IdentifierOrMemberExpression DecoratorArgumentsopt DecoratorArguments : ( ExpressionListopt )