Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grammar railroad diagram #1320

Open
mingodad opened this issue Jan 10, 2023 · 0 comments
Open

Grammar railroad diagram #1320

mingodad opened this issue Jan 10, 2023 · 0 comments

Comments

@mingodad
Copy link

I'm trying to translate this project parser to a CocoR parser (https://github.com/mingodad/CocoR*) and I'm following the parser code (see bellow what I've got so far). Just in case someone want to help create a better EBNF description of this project parser.

I've done a experimental tool to convert CocoR grammars to a kind of EBNF understood by https://www.bottlecaps.de/rr/ui to generate railroad diagrams see bellow the converted to allow view it at https://www.bottlecaps.de/rr/ui the order of the rules could be changed to a better view of the railroad diagrams. Copy and paste the EBNF bellow on https://www.bottlecaps.de/rr/ui tab Edit Grammar then switch to the tab View Diagram.

//
// EBNF generated by CocoR parser generator to be viewed with https://www.bottlecaps.de/rr/ui
//

//
// productions
//

Jakt ::=  parse_namespace
parse_namespace ::=  parse_trait | "type" | "use" | parse_import | parse_attribute_list | parse_function | parsed_record | Namespace Identifier LCurly RCurly | Extern ( parse_function | parse_struct | parse_class )
parse_trait ::=  Trait Identifier parse_generic_parameters? LCurly parse_function* RCurly
parse_import ::=  parse_module_import | parse_extern_import
parse_attribute_list ::=  LSquare parse_attribute parse_attribute* RSquare
parse_function ::=  ( Function | Comptime ) Identifier parse_generic_parameters? parse_function_parameters ( Arrow parse_typename )?
parsed_record ::=  parse_struct | parse_class | Enum | Boxed
parse_struct ::=  Struct Identifier parse_generic_parameters? ( Implements parse_trait_list )? parse_struct_class_body
parse_class ::=  Class Identifier parse_generic_parameters? ( Implements parse_trait_list )? ( Colon parse_typename )? parse_struct_class_body
parse_generic_parameters ::=  LessThan Identifier ( Requires parse_trait_list )? ( Comma Identifier ( Requires parse_trait_list )? )* GreaterThan
parse_trait_list ::=  LParen Identifier ( LessThan parse_typename ( Comma parse_typename )* GreaterThan )?
parse_typename ::=  Ampersand? ( parse_type_shorthand | parse_type_longhand ) QuestionMark?
parse_module_import ::=  Import Identifier parse_call? ( LCurly Identifier ( ColonColon Identifier )* RCurly )? ( As Identifier )?
parse_extern_import ::=  Extern ( "C" | "c" ) QuotedString ( As Identifier )?
parse_call ::=  parse_generic_parameters? LParen ( parse_argument_label? parse_expression ( Comma parse_argument_label parse_expression )* )? RParen
parse_attribute ::=  Identifier LParen ( Identifier | QuotedString ) ( Colon ( Identifier | QuotedString ) ( Comma ( Identifier | QuotedString ) )* )? RParen ( Equal ( Identifier | QuotedString ) )?
parse_function_parameters ::=  LParen ( Anon | Mut | This | parse_variable_declaration ) ( Comma ( Anon | Mut | This | parse_variable_declaration ) )* RParen
parse_struct_class_body ::=  LCurly ( Public | Private | Restricted ) ( Virtual | Override ) ( LSquare RSquare )? ( parse_method | parse_field ) RCurly
parse_method ::=  ( Function | Comptime ) parse_function
parse_field ::=  parse_variable_declaration | parse_expression
parse_variable_declaration ::=  Identifier ( Colon parse_typename )?
parse_expression ::=  parse_operand? parse_operator parse_operand
parse_type_shorthand ::=  parse_type_shorthand_array_or_dictionary | parse_type_shorthand_set | parse_type_shorthand_tuple
parse_type_longhand ::=  ( Raw parse_typename | Weak parse_typename ) Identifier parse_type_list? ( ColonColon Identifier ( ColonColon Identifier )* parse_type_list? )? | Function parse_function_parameters ( Arrow parse_typename )?
parse_type_shorthand_array_or_dictionary ::=  LSquare ( Colon parse_typename )? RSquare
parse_type_shorthand_set ::=  LCurly parse_typename LCurly
parse_type_shorthand_tuple ::=  LParen parse_typename ( Comma parse_typename )* RParen
parse_type_list ::=  LessThan parse_typename ( Comma parse_typename )* GreaterThan
parse_operand ::=  parse_operand_base parse_operand_postfix_operator?
parse_operator ::=  QuestionMarkQuestionMark | Plus | Minus | Asterisk | ForwardSlash | PercentSign | And | Or | DoubleEqual | NotEqual | LessThan | LessThanOrEqual | GreaterThan | Ampersand | AmpersandAmpersand | Pipe | PipePipe | Caret | LeftShift | RightShift | LeftArithmeticShift | RightArithmeticShift | Equal | LeftShiftEqual | RightShiftEqual | AmpersandEqual | PipeEqual | CaretEqual | PlusEqual | MinusEqual | AsteriskEqual | ForwardSlashEqual | PercentSignEqual | QuestionMarkQuestionMarkEqual
parse_operand_base ::=  Dot | Try ( parse_try_block | parse_expression ) Catch Identifier | LCurly parse_expression RCurly | QuotedString | SingleQuotedString | SingleQuotedByteString | Number | True | False | This | Not parse_operand | Tilde parse_operand | Identifier parse_call? | LParen parse_expression ( Comma parse_expression )* RParen | ( PlusPlus | MinusMinus | Minus ) parse_operand | parse_array_or_dictionary_literal | parse_match_expression | parse_set_literal | parse_ampersand | parse_asterisk | parse_lambda | parse_range
parse_operand_postfix_operator ::=  DotDot parse_operand | ExclamationPoint | PlusPlus | MinusMinus | As ( ExclamationPoint | QuestionMark )? parse_typename | Is parse_typename | parse_postfix_colon_colon | ( QuestionMark | Dot ) ( parse_number | Identifier parse_call? ) | LSquare parse_expression RSquare
parse_try_block ::=  LCurly parse_statement RCurly Catch Identifier parse_block
Number ::=  intLit | floatLit
parse_array_or_dictionary_literal ::=  LSquare parse_expression ( Colon parse_expression )? ( Comma parse_expression ( Colon parse_expression )? )* RSquare
parse_match_expression ::=  Match parse_expression parse_match_cases
parse_set_literal ::=  LCurly parse_expression ( Comma parse_expression )* RCurly
parse_ampersand ::=  Ampersand ( Raw | Mut ) parse_operand
parse_asterisk ::=  Asterisk parse_operand
parse_lambda ::=  Function parse_captures? parse_function_parameters ( Arrow parse_typename )? ( FatArrow parse_expression | parse_block )
parse_range ::=  DotDot parse_operand
parse_postfix_colon_colon ::=  ColonColon Identifier parse_call?
parse_number ::=  Number
parse_argument_label ::=  Identifier Colon
parse_match_cases ::=  LCurly parse_match_patterns FatArrow parse_block ( parse_match_patterns FatArrow parse_block )* RCurly
parse_match_patterns ::=  "default" | parse_match_pattern
parse_block ::=  LCurly parse_statement Semicolon? RCurly
parse_match_pattern ::=  True | False | Number | QuotedString | SingleQuotedString | SingleQuotedByteString | Identifier
parse_captures ::=  LSquare ( Ampersand Mut? Identifier | Identifier | This ) ( Comma ( Ampersand Mut? Identifier | Identifier | This ) )* RSquare
parse_statement ::=  Cpp parse_block | Defer parse_statement | Unsafe parse_block | Break | Continue | Loop parse_block | Throw parse_expression | While parse_expression parse_block | Yield parse_expression | Return parse_expression? | ( Let | Mut ) ( parse_destructuring_assignment | parse_variable_declaration ) Equal parse_expression | parse_if_statement | parse_for_statement | parse_block | parse_guard_statement
parse_destructuring_assignment ::=  LParen Identifier ( Comma Identifier )* RParen
parse_if_statement ::=  If parse_expression parse_block ( Else parse_block )?
parse_for_statement ::=  For ( Identifier | parse_destructuring_assignment ) In parse_expression parse_block
parse_guard_statement ::=  Guard parse_expression Else parse_block

//
// tokens
//

And ::= "and"
Anon ::= "anon"
As ::= "as"
Boxed ::= "boxed"
Break ::= "break"
Catch ::= "catch"
Class ::= "class"
Continue ::= "continue"
Cpp ::= "cpp"
Defer ::= "defer"
Else ::= "else"
Enum ::= "enum"
Extern ::= "extern"
False ::= "false"
For ::= "for"
Function ::= "function"
Comptime ::= "comptime"
If ::= "if"
Import ::= "import"
In ::= "in"
Is ::= "is"
Let ::= "let"
Loop ::= "loop"
Match ::= "match"
Mut ::= "mut"
Namespace ::= "namespace"
Not ::= "not"
Or ::= "or"
Override ::= "override"
Private ::= "private"
Public ::= "public"
Raw ::= "raw"
Return ::= "return"
Restricted ::= "restricted"
Struct ::= "struct"
This ::= "this"
Throw ::= "throw"
Throws ::= "throws"
True ::= "true"
Try ::= "try"
Unsafe ::= "unsafe"
Virtual ::= "virtual"
Weak ::= "weak"
While ::= "while"
Yield ::= "yield"
Guard ::= "guard"
Requires ::= "requires"
Implements ::= "implements"
Trait ::= "trait"
UZ ::= "uz"
U8 ::= "u8"
U16 ::= "u16"
U32 ::= "u32"
U64 ::= "u64"
I8 ::= "i8"
I16 ::= "i16"
I32 ::= "i32"
I64 ::= "i64"
F32 ::= "f32"
F64 ::= "f64"
LParen ::= "("
RParen ::= ")"
LSquare ::= "["
RSquare ::= "]"
LCurly ::= "{"
RCurly ::= "}"
LessThan ::= "<"
LessThanOrEqual ::= "<="
LeftShift ::= "<<"
LeftArithmeticShift ::= "<<<"
LeftShiftEqual ::= "<<="
GreaterThan ::= ">"
GreaterThanOrEqual ::= ">="
RightShift ::= ">>"
RightArithmeticShift ::= ">>>"
RightShiftEqual ::= ">>="
Dot ::= "."
DotDot ::= ".."
Comma ::= ","
Tilde ::= "~"
Semicolon ::= ";"
Colon ::= ":"
ColonColon ::= "::"
QuestionMark ::= "?"
QuestionMarkQuestionMark ::= "??"
QuestionMarkQuestionMarkEqual ::= "??="
Plus ::= "+"
PlusPlus ::= "++"
PlusEqual ::= "+="
Minus ::= "-"
MinusMinus ::= "--"
MinusEqual ::= "-="
Arrow ::= "->"
Asterisk ::= "*"
AsteriskEqual ::= "*="
ForwardSlash ::= "/"
ForwardSlashEqual ::= "/="
Caret ::= "^"
CaretEqual ::= "^="
Pipe ::= "|"
PipePipe ::= "||"
PipeEqual ::= "|="
PercentSign ::= "%"
PercentSignEqual ::= "%="
ExclamationPoint ::= "!"
NotEqual ::= "!="
Ampersand ::= "&"
AmpersandEqual ::= "&="
AmpersandAmpersand ::= "&&"
Dollar ::= "$"
Equal ::= "="
DoubleEqual ::= "=="
FatArrow ::= "=>"

CocoR parser to try at https://mingodad.github.io/CocoR-Typescript/playground

COMPILER Jakt

/*-------------------------------------------------------------------------*/

CHARACTERS
  tab           = '\u0009'. /*  9 = tabulator */
  lf            = '\u000a'. /* 10 = line feed */
  cr            = '\u000d'. /* 13 = carriage return */

  zero          = '0'.
  zeroToThree   = zero + "123" .
  octalDigit    = zero + "1234567" .
  nonZeroDigit  = "123456789".
  digit         = '0' + nonZeroDigit .
  hexDigit      = digit + "ABCDEFabcdef" .
  letter        = 'A' .. 'Z' + 'a' .. 'z' + '_' + '$'.

  char          = ANY - "'" - '\\' - cr - lf.
  stringChar    = ANY - "\"" - '\\' - cr - lf.

TOKENS
  Identifier         = letter { letter | digit }.
  /*-------------------------------------------------------------------------*/
  intLit =
  (  zero | nonZeroDigit { digit }
  | ( "0x" | "0X" ) hexDigit { hexDigit }
  | '0' octalDigit { octalDigit }
  ) [ "l" | "L" ].
  /*-------------------------------------------------------------------------*/
  floatLit =
    "." digit {digit}
    [("e" | "E") ["+" | "-"] digit {digit}]
    [ "F" | "f" | "D" | "d" ]
  | digit {digit}
    ( "." {digit}
      [("e" | "E" ) ["+" | "-"] digit {digit} ]
      [ "F" | "f" | "D" | "d" ]
    | ("e" | "E") ["+" | "-"] digit {digit}
      [ "F" | "f" | "D" | "d" ]
    | "F" | "f" | "D" | "d"
    ).
  /*-------------------------------------------------------------------------*/
  SingleQuotedString =
    "'" ( char
        | "\\" ( "b" | "t" | "n" | "f" | "r" | "\"" | "\'" | "\\"
               | "u" { "u" } hexDigit hexDigit hexDigit hexDigit
               | zeroToThree [ octalDigit ] [ octalDigit ]
               | octalDigit [ octalDigit ]
               )
        )
    "'".
  SingleQuotedByteString =
    "b'" ( char
        | "\\" ( "b" | "t" | "n" | "f" | "r" | "\"" | "\'" | "\\"
               | "u" { "u" } hexDigit hexDigit hexDigit hexDigit
               | zeroToThree [ octalDigit ] [ octalDigit ]
               | octalDigit [ octalDigit ]
               )
        )
    "'".
  /*-------------------------------------------------------------------------*/
  QuotedString =
    "\"" { stringChar
         | "\\" ( "b" | "t" | "n" | "f" | "r" | "\"" | "\'" | "\\"
                | "u" { "u" } hexDigit hexDigit hexDigit hexDigit
                | zeroToThree [ octalDigit ] [ octalDigit ]
                | octalDigit [ octalDigit ]
                )
         }
    "\"".

  /*----- keyword names needed in LL(1) resolvers -----*/

	//\("[^"]+"\)\s+=>\s+Token::\([^(]+\)(span) -> \2 = \1 .
	And = "and" .
	Anon = "anon" .
	As = "as" .
	Boxed = "boxed" .
	Break = "break" .
	Catch = "catch" .
	Class = "class" .
	Continue = "continue" .
	Cpp = "cpp" .
	Defer = "defer" .
	Else = "else" .
	Enum = "enum" .
	Extern = "extern" .
	False = "false" .
	For = "for" .
	Function = "function" .
	Comptime = "comptime" .
	If = "if" .
	Import = "import" .
	In = "in" .
	Is = "is" .
	Let = "let" .
	Loop = "loop" .
	Match = "match" .
	Mut = "mut" .
	Namespace = "namespace" .
	Not = "not" .
	Or = "or" .
	Override = "override" .
	Private = "private" .
	Public = "public" .
	Raw = "raw" .
	Return = "return" .
	Restricted = "restricted" .
	Struct = "struct" .
	This = "this" .
	Throw = "throw" .
	Throws = "throws" .
	True = "true" .
	Try = "try" .
	Unsafe = "unsafe" .
	Virtual = "virtual" .
	Weak = "weak" .
	While = "while" .
	Yield = "yield" .
	Guard = "guard" .
	Requires = "requires" .
	Implements = "implements" .
	Trait = "trait" .

  /*----- types --------------*/
	//\(\S+\)\s+=>\s+\("[^"]+"\) -> \1 = \2 .
        UZ = "uz" .
        U8 = "u8" .
        U16 = "u16" .
        U32 = "u32" .
        U64 = "u64" .
        I8 = "i8" .
        I16 = "i16" .
        I32 = "i32" .
        I64 = "i64" .
        F32 = "f32" .
        F64 = "f64" .

  /*----- operators and special characters needed in LL(1) resolvers --------------*/
	//b\('[^']+'\)\s+=>\s+Token::\([^(]+\).+ -> \2 = \1 .
	LParen = '(' .
	RParen = ')' .
	LSquare = '[' .
	RSquare = ']' .
	LCurly = '{' .
	RCurly = '}' .
	LessThan = '<' .
	LessThanOrEqual = "<=" .
	LeftShift = "<<" .
	LeftArithmeticShift = "<<<" .
	LeftShiftEqual = "<<=" .
	GreaterThan = '>' .
	GreaterThanOrEqual = ">=" .
	RightShift = ">>" .
	RightArithmeticShift = ">>>" .
	RightShiftEqual = ">>=" .
	Dot = '.' .
	DotDot = ".." .
	Comma = ',' .
	Tilde = '~' .
	Semicolon = ';' .
	Colon = ':' .
	ColonColon = "::" .
	QuestionMark = '?' .
	QuestionMarkQuestionMark = "??" .
	QuestionMarkQuestionMarkEqual = "??=" .
	Plus = '+' .
	PlusPlus = "++" .
	PlusEqual = "+=" .
	Minus = '-' .
	MinusMinus = "--" .
	MinusEqual = "-=" .
	Arrow = "->" .
	Asterisk = '*' .
	AsteriskEqual = "*=" .
	ForwardSlash = '/' .
	ForwardSlashEqual = "/=" .
	Caret = '^' .
	CaretEqual = "^=" .
	Pipe = '|' .
	PipePipe = "||" .
	PipeEqual = "|=" .
	PercentSign = '%' .
	PercentSignEqual = "%=" .
	ExclamationPoint = '!' .
	NotEqual = "!=" .
	Ampersand = '&' .
	AmpersandEqual = "&=" .
	AmpersandAmpersand = "&&" .
	Dollar = '$' .
	Equal = '=' .
	DoubleEqual = "==" .
	FatArrow = "=>" .

COMMENTS FROM "/*" TO "*/"
COMMENTS FROM "//" TO lf

IGNORE lf + cr + tab

/*---------------------------------------------------------------------------*/

PRODUCTIONS

Jakt =
	parse_namespace
	.

parse_namespace =
	parse_trait
	| "type"
	| "use"
	| parse_import
	| parse_attribute_list
	| parse_function
	| parsed_record
	| Namespace Identifier LCurly RCurly
	| Extern (parse_function | parse_struct | parse_class)
	.

parse_trait =
	Trait Identifier [parse_generic_parameters] LCurly {parse_function} RCurly
	.

parse_trait_list =
	LParen Identifier [LessThan parse_typename {Comma parse_typename} GreaterThan]
	.

parse_import =
	parse_module_import
	| parse_extern_import
	.

parse_extern_import =
	Extern ("C" | "c") QuotedString [As Identifier]
	.

parse_module_import =
	Import Identifier [parse_call] [LCurly Identifier {ColonColon Identifier} RCurly] [As Identifier]
	.

parse_attribute_list =
	LSquare parse_attribute {parse_attribute} RSquare
	.

parse_attribute =
	Identifier LParen (Identifier | QuotedString) [Colon (Identifier | QuotedString) {Comma (Identifier | QuotedString)}] RParen
		[Equal (Identifier | QuotedString)]
	.

parse_function =
	(Function | Comptime) Identifier [parse_generic_parameters] parse_function_parameters [Arrow parse_typename]
	.

parsed_record =
	parse_struct | parse_class | Enum | Boxed
	.

parse_struct =
	Struct Identifier [parse_generic_parameters] [Implements parse_trait_list] parse_struct_class_body
	.

parse_class =
	Class Identifier [parse_generic_parameters] [Implements parse_trait_list] [Colon parse_typename] parse_struct_class_body
	.

parse_struct_class_body =
	LCurly
		(Public | Private | Restricted) (Virtual | Override) [LSquare RSquare]  (parse_method | parse_field)
	RCurly
	.

parse_field =
	/*Identifier*/ parse_variable_declaration | parse_expression
	.

parse_method =
	(Function | Comptime) parse_function
	.

parse_generic_parameters =
	LessThan Identifier [Requires parse_trait_list] {Comma Identifier [Requires parse_trait_list]} GreaterThan
	.

parse_function_parameters =
	LParen (Anon | Mut | This | parse_variable_declaration) {Comma (Anon | Mut | This | parse_variable_declaration)} RParen
	.

parse_typename =
	[Ampersand] (parse_type_shorthand | parse_type_longhand) [QuestionMark]
	.

parse_type_shorthand =
	parse_type_shorthand_array_or_dictionary
	| parse_type_shorthand_set
	| parse_type_shorthand_tuple
	.

parse_type_shorthand_array_or_dictionary =
	LSquare [Colon parse_typename] RSquare
	.

parse_type_shorthand_set =
	LCurly parse_typename LCurly
	.

parse_type_shorthand_tuple =
	LParen parse_typename {Comma parse_typename} RParen
	.

parse_type_longhand =
	(
		Raw parse_typename
		| Weak parse_typename
	) Identifier [parse_type_list] [ColonColon Identifier {ColonColon Identifier} [parse_type_list]]
	| Function parse_function_parameters [Arrow parse_typename]
	.

parse_type_list =
	LessThan parse_typename {Comma parse_typename} GreaterThan
	.

parse_variable_declaration =
	Identifier [Colon parse_typename]
	.

parse_expression =
	[parse_operand] parse_operator parse_operand
	.

parse_operand =
	parse_operand_base [parse_operand_postfix_operator]
	.

parse_operand_base =
	Dot
	| Try (parse_try_block | parse_expression) Catch Identifier
	| LCurly parse_expression RCurly
	| QuotedString
	| SingleQuotedString
	| SingleQuotedByteString
	| Number
	| True
	| False
	| This
	| Not parse_operand
	| Tilde parse_operand
	| Identifier [parse_call]
	| LParen parse_expression {Comma parse_expression} RParen
	| (
		PlusPlus
		| MinusMinus
		| Minus
	) parse_operand
	| parse_array_or_dictionary_literal
	| parse_match_expression
	| parse_set_literal
	| parse_ampersand
	| parse_asterisk
	| parse_lambda
	| parse_range
	.

parse_operator =
	QuestionMarkQuestionMark
	| Plus
	| Minus
	| Asterisk
	| ForwardSlash
	| PercentSign
	| And
	| Or
	| DoubleEqual
	| NotEqual
	| LessThan
	| LessThanOrEqual
	| GreaterThan
	| Ampersand
	| AmpersandAmpersand
	| Pipe
	| PipePipe
	| Caret
	| LeftShift
	| RightShift
	| LeftArithmeticShift
	| RightArithmeticShift
	| Equal
	| LeftShiftEqual
	| RightShiftEqual
	| AmpersandEqual
	| PipeEqual
	| CaretEqual
	| PlusEqual
	| MinusEqual
	| AsteriskEqual
	| ForwardSlashEqual
	| PercentSignEqual
	| QuestionMarkQuestionMarkEqual
	.

parse_operand_postfix_operator =
	DotDot parse_operand
	| ExclamationPoint
	| PlusPlus
	| MinusMinus
	| As [ExclamationPoint | QuestionMark] parse_typename
	| Is parse_typename
	| parse_postfix_colon_colon
	| (QuestionMark | Dot) ( parse_number | Identifier [parse_call] )
	| LSquare parse_expression RSquare
	.

parse_postfix_colon_colon =
	ColonColon Identifier [parse_call]
	.

parse_call =
	[parse_generic_parameters] LParen [[parse_argument_label] parse_expression {Comma parse_argument_label parse_expression}]  RParen
	.

parse_argument_label =
	Identifier Colon
	.

parse_array_or_dictionary_literal =
	LSquare parse_expression [Colon parse_expression] {Comma parse_expression [Colon parse_expression]} RSquare
	.

parse_match_expression =
	Match parse_expression parse_match_cases
	.

parse_match_cases =
	LCurly parse_match_patterns FatArrow parse_block {parse_match_patterns FatArrow parse_block} RCurly
	.

parse_match_patterns =
	"default"
	| parse_match_pattern
	.

parse_match_pattern =
	True
        | False
        | Number
        | QuotedString
        | SingleQuotedString
        | SingleQuotedByteString
        | Identifier
	.

parse_set_literal =
	LCurly parse_expression {Comma parse_expression} RCurly
	.

parse_ampersand =
	Ampersand (Raw | Mut) parse_operand
	.

parse_asterisk =
	Asterisk parse_operand
	.

parse_lambda =
	Function [parse_captures] parse_function_parameters [Arrow parse_typename] (FatArrow parse_expression | parse_block)
	.

parse_captures =
	LSquare (Ampersand [Mut] Identifier | Identifier | This) {Comma (Ampersand [Mut] Identifier | Identifier | This)} RSquare
	.

parse_range =
	DotDot parse_operand
	.

parse_statement =
	Cpp parse_block
	| Defer parse_statement
	| Unsafe parse_block
	| Break
	| Continue
	| Loop parse_block
	| Throw parse_expression
	| While parse_expression parse_block
	| Yield parse_expression
	| Return [parse_expression]
	| (Let | Mut) (parse_destructuring_assignment | parse_variable_declaration) Equal parse_expression
	| parse_if_statement
	| parse_for_statement
	| parse_block
	| parse_guard_statement
	.

parse_block =
	LCurly parse_statement [Semicolon] RCurly
	.

parse_destructuring_assignment =
	LParen Identifier {Comma Identifier} RParen
	.

parse_if_statement =
	If parse_expression parse_block [Else parse_block]
	.

parse_for_statement =
	For (Identifier | parse_destructuring_assignment) In parse_expression parse_block
	.

parse_guard_statement =
	Guard parse_expression Else parse_block
	.

parse_try_block =
	LCurly parse_statement RCurly Catch Identifier parse_block
	.

parse_number =
	Number
	.

Number =
	intLit | floatLit
	.

END Jakt.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant