Open mingodad opened 1 month ago
Comparing with the EBNF
generated from https://github.com/alex-pinkus/tree-sitter-swift with https://github.com/mingodad/plgh/blob/main/json2ebnf.js the grammar here seems to be missing several pieces (or the other way around).
//
// From tree-sitter-swift-alex-pinkus/src/grammar.json
//
//
// EBNF to generate railroad diagram at
// (IPV6) https://www.bottlecaps.de/rr/ui
// (IPV4) https://rr.red-dove.com/ui
//
source_file ::=
shebang_line? ( _top_level_statement ( _semi _top_level_statement )* _semi? )?
_semi ::=
_implicit_semi
| _explicit_semi
shebang_line ::=
'#!' [^#x0D#x0A]*
comment ::=
'//' '.'*
simple_identifier ::=
/* [_\p{XID_Start}\p{Emoji}&&[^0-9#x23*]]('\p{EMod}'|'\x{FE0F}\x{20E3}'?)?([_\p{XID_Continue}\p{Emoji}\x{200D}]('\p{EMod}'|'\x{FE0F}\x{20E3}'?)?)*
|*/ '`'[^#x0D#x0A` ]*'`'
| '\$'[0-9]+
//| ( '$' [_\p{XID_Start}\p{Emoji}&&[^0-9#x23*]]('\p{EMod}'|'\x{FE0F}\x{20E3}'?)?([_\p{XID_Continue}\p{Emoji}\x{200D}]('\p{EMod}'|'\x{FE0F}\x{20E3}'?)?)* )
| _contextual_simple_identifier
_contextual_simple_identifier ::=
'actor'
| 'async'
| 'each'
| 'lazy'
| 'repeat'
| 'package'
| _parameter_ownership_modifier
identifier ::=
simple_identifier ( _dot simple_identifier )*
_basic_literal ::=
integer_literal
| hex_literal
| oct_literal
| bin_literal
| real_literal
| boolean_literal
| _string_literal
| regex_literal
| 'nil'
real_literal ::=
( ( [0-9]+ ( '_'+ [0-9]+ )* ) ( [eE] [+-]? ( [0-9]+ ( '_'+ [0-9]+ )* ) ) | ( [0-9]+ ( '_'+ [0-9]+ )* )? '.' ( [0-9]+ ( '_'+ [0-9]+ )* ) ( [eE] [+-]? ( [0-9]+ ( '_'+ [0-9]+ )* ) )? )
integer_literal ::=
( [1-9]? ( [0-9]+ ( '_'+ [0-9]+ )* ) )
hex_literal ::=
( '0' [xX] ( [0-9a-fA-F]+ ( '_'+ [0-9a-fA-F]+ )* ) )
oct_literal ::=
( '0' [oO] ( [0-7]+ ( '_'+ [0-7]+ )* ) )
bin_literal ::=
( '0' [bB] ( [01]+ ( '_'+ [01]+ )* ) )
boolean_literal ::=
'true'
| 'false'
_string_literal ::=
line_string_literal
| multi_line_string_literal
| raw_string_literal
line_string_literal ::=
'"' ( _line_string_content | _interpolation )* '"'
_line_string_content ::=
line_str_text
| str_escaped_char
line_str_text ::=
[^\"]+
str_escaped_char ::=
_escaped_identifier
| _uni_character_literal
_uni_character_literal ::=
'\\' 'u' '\{'[0-9a-fA-F]+'\}'
multi_line_string_literal ::=
'"""' ( _multi_line_string_content | _interpolation )* '"""'
raw_string_literal ::=
( raw_str_part raw_str_interpolation raw_str_continuing_indicator? )* raw_str_end_part
raw_str_interpolation ::=
raw_str_interpolation_start _interpolation_contents ')'
raw_str_interpolation_start ::=
"#*("
_multi_line_string_content ::=
multi_line_str_text
| str_escaped_char
| '"'
_interpolation ::=
'\(' _interpolation_contents ')'
_interpolation_contents ::=
value_argument ( ',' value_argument )*
_escaped_identifier ::=
'\'[0\tnr"'#x0A]
multi_line_str_text ::=
[^\"]+
regex_literal ::=
_extended_regex_literal
| _multiline_regex_literal
| _oneline_regex_literal
_extended_regex_literal ::=
'#\/'(('\/'[^#x23])|[^#x0A])+'\/#'
_multiline_regex_literal ::=
'#\/#x0A' ('\/'[^#x23]|[^/])*?'#x0A\/#'
_oneline_regex_literal ::=
'/' [^ #x09#x0A]?[^/#x0A]*[^ #x09#x0A/] '/'
type_annotation ::=
':' _possibly_implicitly_unwrapped_type
_possibly_implicitly_unwrapped_type ::=
_type '!'?
_type ::=
type_modifiers? _unannotated_type
_unannotated_type ::=
user_type | tuple_type | function_type | array_type | dictionary_type | optional_type | metatype | opaque_type | existential_type | protocol_composition_type | type_parameter_pack | type_pack_expansion
user_type ::=
_simple_user_type ( _dot _simple_user_type )*
_simple_user_type ::=
simple_identifier type_arguments?
tuple_type ::=
'(' ( tuple_type_item ( ',' tuple_type_item )* )? ')'
| _parenthesized_type
tuple_type_item ::=
_tuple_type_item_identifier? parameter_modifiers? _type
_tuple_type_item_identifier ::=
wildcard_pattern? simple_identifier ':'
function_type ::=
( tuple_type | _unannotated_type ) _async_keyword? throws? _arrow_operator _type
array_type ::=
'[' _type ']'
dictionary_type ::=
'[' _type ':' _type ']'
optional_type ::=
( user_type | tuple_type | array_type | dictionary_type ) _immediate_quest+
metatype ::=
_unannotated_type '.' ( 'Type' | 'Protocol' )
_quest ::=
'?'
_immediate_quest ::=
'?'
opaque_type ::=
'some' _unannotated_type
existential_type ::=
'any' _unannotated_type
type_parameter_pack ::=
'each' _unannotated_type
type_pack_expansion ::=
'repeat' _unannotated_type
protocol_composition_type ::=
_unannotated_type ( '&' _unannotated_type )+
_expression ::=
simple_identifier | _unary_expression | _binary_expression | ternary_expression | _primary_expression | if_statement | switch_statement | assignment | value_parameter_pack | value_pack_expansion | _expression _immediate_quest
_unary_expression ::=
postfix_expression
| call_expression
| constructor_expression
| navigation_expression
| prefix_expression
| as_expression
| selector_expression
| open_start_range_expression
| open_end_range_expression
postfix_expression ::=
_expression _postfix_unary_operator
constructor_expression ::=
( array_type | dictionary_type | user_type ) constructor_suffix
_parenthesized_type ::=
'(' ( opaque_type | existential_type | dictionary_type ) ')'
navigation_expression ::=
( _navigable_type_expression | _expression | _parenthesized_type ) navigation_suffix
_navigable_type_expression ::=
user_type
| array_type
| dictionary_type
open_start_range_expression ::=
_range_operator _expression
_range_operator ::=
_open_ended_range_operator
| _three_dot_operator
open_end_range_expression ::=
_expression _three_dot_operator
prefix_expression ::=
_prefix_unary_operator ( _expression | ( 'async' | 'if' | 'switch' ) )
as_expression ::=
_expression as_operator _type
selector_expression ::=
'#selector' '(' ( 'getter:' | 'setter:' )? _expression ')'
_binary_expression ::=
multiplicative_expression
| additive_expression
| range_expression
| infix_expression
| nil_coalescing_expression
| check_expression
| equality_expression
| comparison_expression
| conjunction_expression
| disjunction_expression
| bitwise_operation
multiplicative_expression ::=
_expression _multiplicative_operator _expression
additive_expression ::=
_expression _additive_operator _expression
range_expression ::=
_expression _range_operator _expr_hack_at_ternary_binary_suffix
infix_expression ::=
_expression custom_operator _expr_hack_at_ternary_binary_suffix
nil_coalescing_expression ::=
_expression _nil_coalescing_operator _expr_hack_at_ternary_binary_suffix
check_expression ::=
_expression _is_operator _type
comparison_expression ::=
_expression _comparison_operator _expr_hack_at_ternary_binary_suffix
equality_expression ::=
_expression _equality_operator _expr_hack_at_ternary_binary_suffix
conjunction_expression ::=
_expression _conjunction_operator _expr_hack_at_ternary_binary_suffix
disjunction_expression ::=
_expression _disjunction_operator _expr_hack_at_ternary_binary_suffix
bitwise_operation ::=
_expression _bitwise_binary_operator _expr_hack_at_ternary_binary_suffix
custom_operator ::=
[\/]+[*]+
| _custom_operator
navigation_suffix ::=
_dot ( simple_identifier | integer_literal )
call_suffix ::=
value_arguments | _fn_call_lambda_arguments | value_arguments _fn_call_lambda_arguments
constructor_suffix ::=
_constructor_value_arguments | _fn_call_lambda_arguments | _constructor_value_arguments _fn_call_lambda_arguments
_constructor_value_arguments ::=
'(' ( value_argument ( ',' value_argument )* )? ')'
_fn_call_lambda_arguments ::=
lambda_literal ( simple_identifier ':' lambda_literal )*
type_arguments ::=
'<' _type ( ',' _type )* '>'
value_arguments ::=
( '(' ( value_argument ( ',' value_argument )* )? ')' | '[' ( value_argument ( ',' value_argument )* )? ']' )
value_argument_label ::=
simple_identifier | 'if' | 'switch'
value_argument ::=
type_modifiers? ( ( value_argument_label ':' )+ | ( value_argument_label ':' )? _expression )
try_expression ::=
try_operator ( _expression | _binary_expression | call_expression | ternary_expression )
await_expression ::=
_await_operator ( _expression | call_expression | ternary_expression )
_await_operator ::=
'await'
ternary_expression ::=
_expression _quest _expression ':' _expr_hack_at_ternary_binary_suffix
_expr_hack_at_ternary_binary_suffix ::=
_expression | expr_hack_at_ternary_binary_call
expr_hack_at_ternary_binary_call ::=
_expression expr_hack_at_ternary_binary_call_suffix
expr_hack_at_ternary_binary_call_suffix ::=
value_arguments
call_expression ::=
_expression call_suffix
_primary_expression ::=
tuple_expression
| _basic_literal
| lambda_literal
| _special_literal
| _playground_literal
| array_literal
| dictionary_literal
| self_expression
| super_expression
| try_expression
| await_expression
| _referenceable_operator
| key_path_expression
| key_path_string_expression
| _three_dot_operator
tuple_expression ::=
'(' ( simple_identifier ':' )? _expression ( ',' ( simple_identifier ':' )? _expression )* ')'
array_literal ::=
'[' ( _expression ( ',' _expression )* )? ','? ']'
dictionary_literal ::=
'[' ( ':' | _dictionary_literal_item ( ',' _dictionary_literal_item )* ) ','? ']'
_dictionary_literal_item ::=
_expression ':' _expression
_special_literal ::=
'#file'
| '#fileID'
| '#filePath'
| '#line'
| '#column'
| '#function'
| '#dsohandle'
_playground_literal ::=
( '#colorLiteral' | '#fileLiteral' | '#imageLiteral' ) '(' simple_identifier ':' _expression ( ',' simple_identifier ':' _expression )* ')'
lambda_literal ::=
( '{' | '^{' ) _lambda_type_declaration? statements? '}'
_lambda_type_declaration ::=
attribute* capture_list lambda_function_type? 'in'
capture_list ::=
'[' capture_list_item ( ',' capture_list_item )* ']'
capture_list_item ::=
self_expression
| ownership_modifier? simple_identifier ( _equal_sign _expression )?
lambda_function_type ::=
( lambda_function_type_parameters | '(' lambda_function_type_parameters? ')' ) _async_keyword? throws? ( _arrow_operator _possibly_implicitly_unwrapped_type )?
lambda_function_type_parameters ::=
lambda_parameter ( ',' lambda_parameter )*
lambda_parameter ::=
( self_expression | simple_identifier | simple_identifier? simple_identifier ':' parameter_modifiers? _possibly_implicitly_unwrapped_type )
self_expression ::=
'self'
super_expression ::=
'super'
_else_options ::=
_block
| if_statement
if_statement ::=
'if' _if_condition_sequence_item ( ',' _if_condition_sequence_item )* _block ( else _else_options )?
_if_condition_sequence_item ::=
_if_let_binding
| _expression
| availability_condition
_if_let_binding ::=
_direct_or_indirect_binding ( _equal_sign _expression )? where_clause?
guard_statement ::=
'guard' _if_condition_sequence_item ( ',' _if_condition_sequence_item )* else _block
switch_statement ::=
'switch' _expression '{' switch_entry* '}'
switch_entry ::=
modifiers? ( 'case' switch_pattern ( where_keyword _expression )? ( ',' switch_pattern )* | default_keyword ) ':' statements 'fallthrough'?
switch_pattern ::=
_binding_pattern_with_expr
do_statement ::=
'do' _block catch_block*
catch_block ::=
catch_keyword _binding_pattern_no_expr? where_clause? _block
where_clause ::=
where_keyword _expression
key_path_expression ::=
'\\' ( _simple_user_type | array_type | dictionary_type )? ( '.' _key_path_component )*
key_path_string_expression ::=
'#keyPath' '(' _expression ')'
_key_path_component ::=
simple_identifier _key_path_postfixes* | _key_path_postfixes+
_key_path_postfixes ::=
'?'
| bang
| 'self'
| '[' ( value_argument ( ',' value_argument )* )? ']'
try_operator ::=
'try' ( _try_operator_type | _fake_try_bang )
_try_operator_type ::=
'!'
| '?'
_assignment_and_operator ::=
'+='
| '-='
| '*='
| '/='
| '%='
| _equal_sign
_equality_operator ::=
'!='
| '!=='
| _eq_eq
| '==='
_comparison_operator ::=
'<'
| '>'
| '<='
| '>='
_three_dot_operator ::=
'...'
_open_ended_range_operator ::=
'..<'
_is_operator ::=
'is'
_additive_operator ::=
_plus_then_ws
| _minus_then_ws
| '+'
| '-'
_multiplicative_operator ::=
'*'
| '/'
| '%'
as_operator ::=
_as
| _as_quest
| _as_bang
_prefix_unary_operator ::=
'++' | '--' | '-' | '+' | bang | '&' | '~' | _dot | custom_operator
_bitwise_binary_operator ::=
'&'
| '|'
| '^'
| '<<'
| '>>'
_postfix_unary_operator ::=
'++'
| '--'
| bang
directly_assignable_expression ::=
_expression
statements ::=
_local_statement ( _semi _local_statement )* _semi?
_local_statement ::=
_expression
| _local_declaration
| _labeled_statement
| control_transfer_statement
_top_level_statement ::=
_expression
| _global_declaration
| _labeled_statement
| _throw_statement
_block ::=
'{' statements? '}'
_labeled_statement ::=
statement_label? ( for_statement | while_statement | repeat_while_statement | do_statement | if_statement | guard_statement | switch_statement )
statement_label ::=
[a-zA-Z_][a-zA-Z_0-9]*':'
for_statement ::=
'for' try_operator? _await_operator? _binding_pattern_no_expr type_annotation? 'in' _for_statement_collection where_clause? _block
_for_statement_collection ::=
_expression
| for_statement_await
for_statement_await ::=
_await_operator _expression
while_statement ::=
'while' _if_condition_sequence_item ( ',' _if_condition_sequence_item )* '{' statements? '}'
repeat_while_statement ::=
'repeat' '{' statements? '}' _implicit_semi* 'while' _if_condition_sequence_item ( ',' _if_condition_sequence_item )*
control_transfer_statement ::=
_throw_statement
| _optionally_valueful_control_keyword _expression?
_throw_statement ::=
throw_keyword _expression
throw_keyword ::=
'throw'
_optionally_valueful_control_keyword ::=
'return'
| 'continue'
| 'break'
| 'yield'
assignment ::=
directly_assignable_expression _assignment_and_operator _expression
value_parameter_pack ::=
'each' _expression
value_pack_expansion ::=
'repeat' _expression
availability_condition ::=
( '#available' | '#unavailable' ) '(' _availability_argument ( ',' _availability_argument )* ')'
_availability_argument ::=
identifier integer_literal ( '.' integer_literal )*
| '*'
_global_declaration ::=
import_declaration
| property_declaration
| typealias_declaration
| function_declaration
| init_declaration
| class_declaration
| protocol_declaration
| operator_declaration
| precedence_group_declaration
| associatedtype_declaration
| macro_declaration
_type_level_declaration ::=
import_declaration
| property_declaration
| typealias_declaration
| function_declaration
| init_declaration
| class_declaration
| protocol_declaration
| deinit_declaration
| subscript_declaration
| operator_declaration
| precedence_group_declaration
| associatedtype_declaration
_local_declaration ::=
_local_property_declaration
| _local_typealias_declaration
| _local_function_declaration
| _local_class_declaration
_local_property_declaration ::=
_locally_permitted_modifiers? _modifierless_property_declaration
_local_typealias_declaration ::=
_locally_permitted_modifiers? _modifierless_typealias_declaration
_local_function_declaration ::=
_locally_permitted_modifiers? _modifierless_function_declaration
_local_class_declaration ::=
_locally_permitted_modifiers? _modifierless_class_declaration
import_declaration ::=
modifiers? 'import' _import_kind? identifier
_import_kind ::=
'typealias'
| 'struct'
| 'class'
| 'enum'
| 'protocol'
| 'let'
| 'var'
| 'func'
protocol_property_declaration ::=
modifiers? _binding_kind_and_pattern type_annotation? type_constraints? protocol_property_requirements
protocol_property_requirements ::=
'{' ( getter_specifier | setter_specifier )* '}'
property_declaration ::=
modifiers? _modifierless_property_declaration
_modifierless_property_declaration ::=
_possibly_async_binding_pattern_kind _single_modifierless_property_declaration ( ',' _single_modifierless_property_declaration )*
_single_modifierless_property_declaration ::=
_no_expr_pattern_already_bound type_annotation? type_constraints? ( _expression_with_willset_didset | _expression_without_willset_didset | willset_didset_block | computed_property )?
_expression_with_willset_didset ::=
_equal_sign _expression willset_didset_block
_expression_without_willset_didset ::=
_equal_sign _expression
willset_didset_block ::=
'{' willset_clause didset_clause? '}'
| '{' didset_clause willset_clause? '}'
willset_clause ::=
modifiers? 'willSet' ( '(' simple_identifier ')' )? _block
didset_clause ::=
modifiers? 'didSet' ( '(' simple_identifier ')' )? _block
typealias_declaration ::=
modifiers? _modifierless_typealias_declaration
_modifierless_typealias_declaration ::=
'typealias' simple_identifier type_parameters? _equal_sign _type
function_declaration ::=
_bodyless_function_declaration function_body
_modifierless_function_declaration ::=
_modifierless_function_declaration_no_body function_body
_bodyless_function_declaration ::=
modifiers? 'class'? _modifierless_function_declaration_no_body
_modifierless_function_declaration_no_body ::=
_non_constructor_function_decl type_parameters? _function_value_parameters _async_keyword? throws? ( _arrow_operator _possibly_implicitly_unwrapped_type )? type_constraints?
function_body ::=
_block
macro_declaration ::=
_macro_head simple_identifier type_parameters? _macro_signature macro_definition? type_constraints?
_macro_head ::=
modifiers? 'macro'
_macro_signature ::=
_function_value_parameters ( _arrow_operator _unannotated_type )?
macro_definition ::=
_equal_sign ( _expression | external_macro_definition )
external_macro_definition ::=
'#externalMacro' value_arguments
class_declaration ::=
modifiers? _modifierless_class_declaration
_modifierless_class_declaration ::=
( 'class' | 'struct' | 'actor' ) simple_identifier type_parameters? ( ':' _inheritance_specifiers )? type_constraints? class_body | 'extension' _unannotated_type type_parameters? ( ':' _inheritance_specifiers )? type_constraints? class_body | 'indirect'? 'enum' simple_identifier type_parameters? ( ':' _inheritance_specifiers )? type_constraints? enum_class_body
class_body ::=
'{' _class_member_declarations? '}'
_inheritance_specifiers ::=
_annotated_inheritance_specifier ( ( ',' | '&' ) _annotated_inheritance_specifier )*
inheritance_specifier ::=
( user_type | function_type )
_annotated_inheritance_specifier ::=
attribute* inheritance_specifier
type_parameters ::=
'<' type_parameter ( ',' type_parameter )* type_constraints? '>'
type_parameter ::=
type_parameter_modifiers? _type_parameter_possibly_packed ( ':' _type )?
_type_parameter_possibly_packed ::=
simple_identifier
| type_parameter_pack
type_constraints ::=
where_keyword type_constraint ( ',' type_constraint )*
type_constraint ::=
inheritance_constraint
| equality_constraint
inheritance_constraint ::=
attribute* _constrained_type ':' _possibly_implicitly_unwrapped_type
equality_constraint ::=
attribute* _constrained_type ( _equal_sign | _eq_eq ) _type
_constrained_type ::=
identifier
| _unannotated_type ( '.' simple_identifier ( '.' simple_identifier )* )?
_class_member_separator ::=
_semi
| multiline_comment
_class_member_declarations ::=
_type_level_declaration ( _class_member_separator _type_level_declaration )* _class_member_separator?
_function_value_parameters ::=
( '(' ( _function_value_parameter ( ',' _function_value_parameter )* )? ')' )+
_function_value_parameter ::=
attribute? parameter ( _equal_sign _expression )?
parameter ::=
simple_identifier? simple_identifier ':' parameter_modifiers? _possibly_implicitly_unwrapped_type _three_dot_operator?
_non_constructor_function_decl ::=
'func' ( simple_identifier | _referenceable_operator )
_referenceable_operator ::=
custom_operator
| _comparison_operator
| _additive_operator
| _multiplicative_operator
| _equality_operator
| _comparison_operator
| _assignment_and_operator
| '++'
| '--'
| bang
| '~'
| '|'
| '^'
| '<<'
| '>>'
| '&'
_equal_sign ::=
_eq_custom
_eq_eq ::=
_eq_eq_custom
_dot ::=
_dot_custom
_arrow_operator ::=
_arrow_operator_custom
_conjunction_operator ::=
_conjunction_operator_custom
_disjunction_operator ::=
_disjunction_operator_custom
_nil_coalescing_operator ::=
_nil_coalescing_operator_custom
_as ::=
_as_custom
_as_quest ::=
_as_quest_custom
_as_bang ::=
_as_bang_custom
bang ::=
_bang_custom
| '!'
_async_keyword ::=
_async_keyword_custom
_async_modifier ::=
'async'
throws ::=
_throws_keyword
| _rethrows_keyword
enum_class_body ::=
'{' ( enum_entry | _type_level_declaration )* '}'
enum_entry ::=
modifiers? 'indirect'? 'case' simple_identifier _enum_entry_suffix? ( ',' simple_identifier _enum_entry_suffix? )* ';'?
_enum_entry_suffix ::=
enum_type_parameters
| _equal_sign _expression
enum_type_parameters ::=
'(' ( ( wildcard_pattern? simple_identifier ':' )? _type ( _equal_sign _expression )? ( ',' ( wildcard_pattern? simple_identifier ':' )? _type ( _equal_sign _expression )? )* )? ')'
protocol_declaration ::=
modifiers? 'protocol' simple_identifier type_parameters? ( ':' _inheritance_specifiers )? type_constraints? protocol_body
protocol_body ::=
'{' _protocol_member_declarations? '}'
_protocol_member_declarations ::=
_protocol_member_declaration ( _semi _protocol_member_declaration )* _semi?
_protocol_member_declaration ::=
( _bodyless_function_declaration function_body? )
| init_declaration
| deinit_declaration
| protocol_property_declaration
| typealias_declaration
| associatedtype_declaration
| subscript_declaration
init_declaration ::=
modifiers? 'class'? 'init' ( _quest | bang )? type_parameters? _function_value_parameters _async_keyword? throws? type_constraints? function_body?
deinit_declaration ::=
modifiers? 'deinit' function_body
subscript_declaration ::=
modifiers? 'subscript' type_parameters? _function_value_parameters ( _arrow_operator _possibly_implicitly_unwrapped_type )? type_constraints? computed_property
computed_property ::=
'{' ( statements | ( computed_getter | computed_setter | computed_modify )* ) '}'
computed_getter ::=
attribute* getter_specifier _block?
computed_modify ::=
attribute* modify_specifier _block?
computed_setter ::=
attribute* setter_specifier ( '(' simple_identifier ')' )? _block?
getter_specifier ::=
mutation_modifier? 'get' _getter_effects?
setter_specifier ::=
mutation_modifier? 'set'
modify_specifier ::=
mutation_modifier? '_modify'
_getter_effects ::=
( _async_keyword | throws )+
operator_declaration ::=
( 'prefix' | 'infix' | 'postfix' ) 'operator' _referenceable_operator ( ':' simple_identifier )? deprecated_operator_declaration_body?
deprecated_operator_declaration_body ::=
'{' ( simple_identifier | _basic_literal )* '}'
precedence_group_declaration ::=
'precedencegroup' simple_identifier '{' precedence_group_attributes? '}'
precedence_group_attributes ::=
precedence_group_attribute+
precedence_group_attribute ::=
simple_identifier ':' ( simple_identifier | boolean_literal )
associatedtype_declaration ::=
modifiers? 'associatedtype' simple_identifier ( ':' _type )? type_constraints? ( _equal_sign _type )?
attribute ::=
'@' user_type ( '(' _attribute_argument ( ',' _attribute_argument )* ')' )?
_attribute_argument ::=
simple_identifier ':' _expression
| _expression
| ( simple_identifier ':' )+
| simple_identifier+ integer_literal ( '.' integer_literal )*
_universally_allowed_pattern ::=
wildcard_pattern
| _tuple_pattern
| _type_casting_pattern
| _case_pattern
_bound_identifier ::=
simple_identifier
_binding_pattern_no_expr ::=
( _universally_allowed_pattern | _binding_pattern | _bound_identifier ) _quest?
_no_expr_pattern_already_bound ::=
( _universally_allowed_pattern | _bound_identifier ) _quest?
_binding_pattern_with_expr ::=
( _universally_allowed_pattern | _binding_pattern | _expression ) _quest?
_non_binding_pattern_with_expr ::=
( _universally_allowed_pattern | _expression ) _quest?
_direct_or_indirect_binding ::=
( _binding_kind_and_pattern | 'case' _binding_pattern_no_expr ) type_annotation?
value_binding_pattern ::=
( 'var' | 'let' )
_possibly_async_binding_pattern_kind ::=
_async_modifier? value_binding_pattern
_binding_kind_and_pattern ::=
_possibly_async_binding_pattern_kind _no_expr_pattern_already_bound
wildcard_pattern ::=
'_'
_tuple_pattern_item ::=
simple_identifier ':' _binding_pattern_with_expr
| _binding_pattern_with_expr
_tuple_pattern ::=
'(' _tuple_pattern_item ( ',' _tuple_pattern_item )* ')'
_case_pattern ::=
'case'? user_type? _dot simple_identifier _tuple_pattern?
_type_casting_pattern ::=
'is' _type
| _binding_pattern_no_expr _as _type
_binding_pattern ::=
'case'? value_binding_pattern _no_expr_pattern_already_bound
modifiers ::=
_non_local_scope_modifier | _locally_permitted_modifiers+
_locally_permitted_modifiers ::=
( attribute | _locally_permitted_modifier )+
parameter_modifiers ::=
parameter_modifier+
_modifier ::=
_non_local_scope_modifier
| _locally_permitted_modifier
_non_local_scope_modifier ::=
member_modifier
| visibility_modifier
| function_modifier
| mutation_modifier
| property_modifier
| parameter_modifier
_locally_permitted_modifier ::=
ownership_modifier
| inheritance_modifier
| property_behavior_modifier
property_behavior_modifier ::=
'lazy'
type_modifiers ::=
attribute+
member_modifier ::=
'override'
| 'convenience'
| 'required'
| 'nonisolated'
visibility_modifier ::=
( 'public' | 'private' | 'internal' | 'fileprivate' | 'open' | 'package' ) ( '(' 'set' ')' )?
type_parameter_modifiers ::=
attribute+
function_modifier ::=
'infix'
| 'postfix'
| 'prefix'
mutation_modifier ::=
'mutating'
| 'nonmutating'
property_modifier ::=
'static'
| 'dynamic'
| 'optional'
| 'class'
| 'distributed'
inheritance_modifier ::=
'final'
parameter_modifier ::=
'inout'
| '@escaping'
| '@autoclosure'
| _parameter_ownership_modifier
ownership_modifier ::=
'weak'
| 'unowned'
| 'unowned(safe)'
| 'unowned(unsafe)'
_parameter_ownership_modifier ::=
'borrowing'
| 'consuming'
use_site_target ::=
( 'property' | 'get' | 'set' | 'receiver' | 'param' | 'setparam' | 'delegate' ) ':'
directive ::=
'#if' '.'* | '#elseif' '.'* | '#else' '.'* | '#endif' '.'* | '#sourceLocation'([^#x0D#x0A]*)
diagnostic ::=
'#error'([^#x0D#x0A]*) | '#warning'([^#x0D#x0A]*)
unused_for_backward_compatibility ::=
'unused1'
| 'unused2'
Location
https://github.com/swiftlang/swift-book/blob/main/TSPL.docc/ReferenceManual/SummaryOfTheGrammar.md
Description
Using an
EBNF
understood by https://github.com/GuntherRademacher/rr we can have a nice navigable railroad diagram (see a manual conversion that already works, although still need some work on it).Motivation
No response
Alternatives Considered
No response