Several changes. Fixing comments and whitespace. Removing some unused definitions.
This commit is contained in:
parent
a1cc04575c
commit
a1c245814b
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -4,3 +4,4 @@ prompt.sh
|
||||||
prompt.txt
|
prompt.txt
|
||||||
compile_grammar.sh
|
compile_grammar.sh
|
||||||
waddle.bnf
|
waddle.bnf
|
||||||
|
waddle_flattened.bnf
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,8 @@
|
||||||
<type> ::= <primitive_type> | <inherited_type> | <array_type> | <error_type>
|
<type> ::= <primitive_type> | <inherited_type> | <array_type> | <inherited_error_type> | <callable_type_keyword>
|
||||||
|
|
||||||
|
<base_type> ::= <primitive_type> | <inherited_type> | <inherited_error_type>
|
||||||
|
|
||||||
<primitive_type> ::= <string_type_keyword> | <integer_type_keyword> | <decimal_type_keyword> | <boolean_type_keyword>
|
<primitive_type> ::= <string_type_keyword> | <integer_type_keyword> | <decimal_type_keyword> | <boolean_type_keyword>
|
||||||
|
|
||||||
<array_type> ::= <type> <array_symbol_open> <array_symbol_close>
|
<array_type> ::= <base_type> <array_symbol_open> <array_symbol_close>
|
||||||
|
|
||||||
<parameter_type> ::= <type>
|
|
||||||
| <callable_type_keyword>
|
|
||||||
| <error_type>
|
|
||||||
| "Any"
|
|
||||||
|
|
||||||
<return_type_list> ::= "[" <optional_whitespace> <type> ( <optional_whitespace> "," <optional_whitespace> <type>)* <optional_whitespace> "]" | <callable_type_keyword>
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<comment> ::= <single_line_comment> | <multi_line_comment>
|
<comment> ::= <single_line_comment> | <multi_line_comment>
|
||||||
|
|
||||||
<single_line_comment> ::= <single_line_comment_identifier> <single_line_comment_character>* <multi_line_whitespace>
|
<single_line_comment> ::= <single_line_comment_identifier> <single_line_comment_character>*
|
||||||
|
|
||||||
<multi_line_comment> ::= <multi_line_comment_open_identifier>
|
<multi_line_comment> ::= <multi_line_comment_open_identifier>
|
||||||
(<multi_line_comment_character> | <multi_line_comment>)*
|
(<multi_line_comment_character> | <multi_line_comment>)*
|
||||||
|
|
@ -8,4 +8,5 @@
|
||||||
|
|
||||||
<single_line_comment_character> ::= <letter> | <digit> | <symbol> | <single_line_whitespace>
|
<single_line_comment_character> ::= <letter> | <digit> | <symbol> | <single_line_whitespace>
|
||||||
|
|
||||||
<multi_line_comment_character> ::= <letter> | <digit> | <symbol> | <multi_line_whitespace>
|
<multi_line_comment_character> ::= <letter> | <digit> | <symbol> | <optional_whitespace>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<identifier> ::= <upper_letter> (<letter> | <digit>)*
|
<identifier> ::= <letter> (<letter> | <digit>)*
|
||||||
|
|
||||||
<interface_identifier_list> ::= <interface_identifier> ("," <interface_identifier>)*
|
<interface_identifier_list> ::= <interface_identifier> ("," <interface_identifier>)*
|
||||||
|
|
||||||
|
|
@ -14,14 +14,5 @@
|
||||||
|
|
||||||
<digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
|
<digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
|
||||||
|
|
||||||
<symbol> ::= "!" | "@" | "#" | "$" | "%" | "^" | "&" | "*" | "(" | ")" | "-" | "_" | "+" | "=" | "[" | "]" | "{" | "}" | "|" | "\" | ":" | ";" | "<" | ">" | "," | "." | "?" | "/"
|
<symbol> ::= "!" | "@" | "#" | "$" | "%" | "^" | "&" | "*" | "(" | ")" | "-" | "_" | "+" | "=" | "[" | "]" | "{" | "}" | "|" | "\\" | ":" | ";" | "<" | ">" | "," | "." | "?" | "/"
|
||||||
|
|
||||||
<whitespace> ::= <single_line_whitespace> | <multi_line_whitespace> | <comment>
|
|
||||||
|
|
||||||
<single_line_whitespace> ::= " " | "\t"
|
|
||||||
|
|
||||||
<multi_line_whitespace> ::= "\n" | "\r"
|
|
||||||
|
|
||||||
<optional_whitespace> ::= <whitespace>*
|
|
||||||
|
|
||||||
<optional_single_line_whitespace ::= (<single_line_whitespace> | <comment>)*
|
|
||||||
|
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
<arrow_keyword> ::= "->"
|
<arrow_keyword> ::= "->"
|
||||||
|
|
||||||
|
<double_quote> ::= "\""
|
||||||
|
|
||||||
|
<single_quote> ::= "'"
|
||||||
|
|
||||||
<single_line_comment_identifier> ::= "//"
|
<single_line_comment_identifier> ::= "//"
|
||||||
|
|
||||||
<multi_line_comment_open_identifier> ::= "/*"
|
<multi_line_comment_open_identifier> ::= "/*"
|
||||||
|
|
@ -40,7 +44,7 @@
|
||||||
|
|
||||||
<constructor_method_name> ::= "on_create"
|
<constructor_method_name> ::= "on_create"
|
||||||
|
|
||||||
<destructor_name> ::= "on_destroy"
|
<destructor_method_name> ::= "on_destroy"
|
||||||
|
|
||||||
<use_statement_identifier> ::= "use"
|
<use_statement_identifier> ::= "use"
|
||||||
|
|
||||||
|
|
@ -61,3 +65,4 @@
|
||||||
<context_management_keyword> ::= "using"
|
<context_management_keyword> ::= "using"
|
||||||
|
|
||||||
<exception_throw_keyword> ::= "fail"
|
<exception_throw_keyword> ::= "fail"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,16 +14,12 @@
|
||||||
|
|
||||||
<string_literal> ::= <double_quote_string> | <single_quote_string>
|
<string_literal> ::= <double_quote_string> | <single_quote_string>
|
||||||
|
|
||||||
<double_quote_string> ::= <double_quote> <double_quote_content>* <double_quote>
|
<double_quote_string> ::= <double_quote> <double_quote_character>* <double_quote>
|
||||||
<single_quote_string> ::= <single_quote> <single_quote_content>* <single_quote>
|
|
||||||
|
|
||||||
<double_quote_content> ::= <double_quote_character> <double_quote_content>
|
<single_quote_string> ::= <single_quote> <single_quote_character>* <single_quote>
|
||||||
<single_quote_content> ::= <single_quote_character> <single_quote_content>
|
|
||||||
|
|
||||||
<double_quote> ::= "\""
|
|
||||||
<single_quote> ::= "'"
|
|
||||||
|
|
||||||
<double_quote_character> ::= <letter> | <digit> | <symbol> | <whitespace>
|
<double_quote_character> ::= <letter> | <digit> | <symbol> | <whitespace>
|
||||||
|
|
||||||
<single_quote_character> ::= <letter> | <digit> | <symbol> | <whitespace>
|
<single_quote_character> ::= <letter> | <digit> | <symbol> | <whitespace>
|
||||||
|
|
||||||
<boolean_literal> ::= <true_keyword> | <false_keyword>
|
<boolean_literal> ::= <true_keyword> | <false_keyword>
|
||||||
|
|
@ -32,4 +28,13 @@
|
||||||
|
|
||||||
<array_literal> ::= <array_symbol_open> <literal_list>? <array_symbol_close>
|
<array_literal> ::= <array_symbol_open> <literal_list>? <array_symbol_close>
|
||||||
|
|
||||||
<literal_list> ::= <literal> ("," <literal>)*
|
<literal_list> ::= <optional_whitespace> <integer_literal_list> | <decimal_literal_list> | <string_literal_list> | <boolean_literal_list> <optional_whitespace>
|
||||||
|
|
||||||
|
<integer_literal_list> ::= <integer_literal> <optional_whitespace> ("," <optional_whitespace> <integer_literal>)*
|
||||||
|
|
||||||
|
<decimal_literal_list> ::= <decimal_literal> <optional_whitespace> ("," <optional_whitespace> <decimal_literal>)*
|
||||||
|
|
||||||
|
<string_literal_list> ::= <string_literal> <optional_whitespace> ("," <optional_whitespace> <string_literal>)*
|
||||||
|
|
||||||
|
<boolean_literal_list> ::= <boolean_literal> <optional_whitespace> ("," <optional_whitespace> <boolean_literal>)*
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,3 +2,4 @@
|
||||||
<public_scope_identifier>
|
<public_scope_identifier>
|
||||||
| <protected_scope_identifier>
|
| <protected_scope_identifier>
|
||||||
| <private_scope_identifier>
|
| <private_scope_identifier>
|
||||||
|
|
||||||
|
|
|
||||||
16
grammar/core/whitespace.bnf
Normal file
16
grammar/core/whitespace.bnf
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
<whitespace> ::= <single_line_whitespace> | <multi_line_whitespace>
|
||||||
|
|
||||||
|
<single_line_whitespace> ::= " " | "\t" | "\u00A0"
|
||||||
|
|
||||||
|
<multi_line_whitespace> ::= "\n" | "\r" | "\u2028" | "\u2029"
|
||||||
|
|
||||||
|
<optional_whitespace> ::= <whitespace>*
|
||||||
|
|
||||||
|
<optional_single_line_whitespace> ::= <single_line_whitespace>*
|
||||||
|
|
||||||
|
<required_single_line_whitespace> ::= <single_line_whitespace>+
|
||||||
|
|
||||||
|
<required_multi_line_whitespace> ::= <multi_line_whitespace>+
|
||||||
|
|
||||||
|
<required_whitespace> ::= <single_line_whitespace>+ | <multi_line_whitespace>+
|
||||||
|
|
||||||
|
|
@ -1,23 +1,20 @@
|
||||||
<function_declaration> ::= <optional_whitespace>
|
<function_declaration> ::= <optional_whitespace>
|
||||||
<accessibility_modifier>
|
<accessibility_modifier>
|
||||||
<function_keyword>
|
<function_keyword>
|
||||||
<optional_whitespace>
|
<required_single_line_whitespace>
|
||||||
<identifier>
|
<identifier>
|
||||||
<optional_whitespace>
|
<optional_whitespace>
|
||||||
<function_signature>
|
<function_signature>
|
||||||
<optional_whitespace>
|
<optional_whitespace>
|
||||||
"{"
|
<standard_statement_block>
|
||||||
<optional_whitespace>
|
|
||||||
<statement>*
|
|
||||||
<optional_whitespace>
|
|
||||||
"}"
|
|
||||||
|
|
||||||
<function_signature> ::= "(" <parameter_list>? ")"
|
<function_signature> ::= "(" <parameter_list>? ")" <optional_whitespace> <arrow_keyword> <optional_whitespace> <return_type_list> <optional_whitespace> <function_error_signature>?
|
||||||
<arrow_keyword> <return_type_list>
|
|
||||||
|
|
||||||
<error_type_list> ::= <error_type> ("," <error_type>)*
|
<function_error_signature> ::= <function_error_identifier> <required_single_line_whitespace> <error_type_list>
|
||||||
|
|
||||||
<error_type> ::= <identifier> ("/" <identifier>)?
|
<return_type_list> ::= "[" <optional_single_line_whitespace> <type> | <callable_type_keyword> ( <optional_single_line_whitespace> "|" <optional_single_line_whitespace> <null_keyword>)? <optional_single_line_whitespace> "]"
|
||||||
|
|
||||||
|
<error_type_list> ::= "[" <optional_single_line_whitespace> <inherited_error_type> ("," <optional_single_line_whitespace> <inherited_error_type>)* "]"
|
||||||
|
|
||||||
<parameter_list> ::= <parameter_group>?
|
<parameter_list> ::= <parameter_group>?
|
||||||
|
|
||||||
|
|
@ -30,17 +27,19 @@
|
||||||
<required_parameters> ::=
|
<required_parameters> ::=
|
||||||
<optional_whitespace>
|
<optional_whitespace>
|
||||||
( <required_parameter>
|
( <required_parameter>
|
||||||
| <required_parameter> "," <optional_whitespace> <required_parameters> )
|
| <required_parameter> "," <required_parameters> )
|
||||||
|
|
||||||
<default_parameters> ::=
|
<default_parameters> ::=
|
||||||
<optional_whitespace>
|
<optional_whitespace>
|
||||||
( <default_parameter>
|
( <default_parameter>
|
||||||
| <default_parameter> "," <default_parameters> )
|
| <default_parameter> "," <default_parameters> )
|
||||||
|
|
||||||
<required_parameter> ::= <parameter_type> <identifier>
|
<required_parameter> ::= <type> <required_single_line_whitespace> <identifier>
|
||||||
|
|
||||||
<default_parameter> ::= <parameter_type> <identifier> ".default(" <literal> ")"
|
<default_parameter> ::= <type> <required_single_line_whitespace> <identifier> ".default(" <literal> ")"
|
||||||
|
|
||||||
<lambda_declaration> ::= <function_keyword> <optional_whitespace> "(" <parameter_list>? ")"
|
<lambda_declaration> ::= <function_keyword> <optional_whitespace> "(" <parameter_list>? ")" <function_signature> <standard_statement_block>
|
||||||
<arrow_keyword> <optional_whitespace> "[" <optional_whitespace> <type> <optional_whitespace> "]"
|
|
||||||
"{" <optional_whitespace> <statement>* <optional_whitespace> "}"
|
<constructor_declaration> ::= <optional_whitespace> <accessibility_modifier> <function_keyword> <required_single_line_whitespace> <constructor_method_name> <optional_whitespace> <function_signature> <optional_whitespace> <standard_statement_block>
|
||||||
|
|
||||||
|
<destructor_declaration> ::= <optional_whitespace> <accessibility_modifier> <function_keyword> <required_single_line_whitespace> <destructor_method_name> <optional_whitespace> <function_signature> <optional_whitespace> <standard_statement_block>
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,13 @@
|
||||||
"}"
|
"}"
|
||||||
|
|
||||||
<class_body> ::= <optional_whitespace>
|
<class_body> ::= <optional_whitespace>
|
||||||
|
(<comment>*
|
||||||
(<variable_declaration>
|
(<variable_declaration>
|
||||||
| <constant_declaration>
|
| <constant_declaration>
|
||||||
| <function_declaration>
|
| <function_declaration>
|
||||||
| <constructor_declaration>
|
| <constructor_declaration>
|
||||||
| <destructor_declaration>
|
| <destructor_declaration>
|
||||||
| <optional_whitespace>)*
|
| <optional_whitespace>))*
|
||||||
<optional_whitespace>
|
<optional_whitespace>
|
||||||
|
|
||||||
<inherited_type> ::= (<parent> "/")? <child>
|
<inherited_type> ::= (<parent> "/")? <child>
|
||||||
|
|
@ -23,8 +24,6 @@
|
||||||
|
|
||||||
<child> ::= <identifier>
|
<child> ::= <identifier>
|
||||||
|
|
||||||
<type_parameter_list> ::= <identifier> ("," <identifier>)*
|
|
||||||
|
|
||||||
<variable_declaration> ::= <optional_whitespace>
|
<variable_declaration> ::= <optional_whitespace>
|
||||||
<type>
|
<type>
|
||||||
<optional_whitespace>
|
<optional_whitespace>
|
||||||
|
|
@ -35,13 +34,3 @@
|
||||||
|
|
||||||
<constant_declaration> ::= <type> <identifier> ".define(" <literal> ");"
|
<constant_declaration> ::= <type> <identifier> ".define(" <literal> ");"
|
||||||
|
|
||||||
<constructor_declaration> ::=
|
|
||||||
<accessibility_modifier> <constructor_name> "(" <parameter_list>? ")"
|
|
||||||
(<function_error_identifier> <error_type_list>)?
|
|
||||||
"{" <statement>* "}"
|
|
||||||
|
|
||||||
<destructor_declaration> ::=
|
|
||||||
<accessibility_modifier> <destructor_name> "(" <parameter_list>? ")"
|
|
||||||
(<function_error_identifier> <error_type_list>)?
|
|
||||||
"{" <statement>* "}"
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,5 +12,3 @@
|
||||||
|
|
||||||
<interface_implementation> ::= <arrow_keyword> "[" <interface_identifier_list> "]"
|
<interface_implementation> ::= <arrow_keyword> "[" <interface_identifier_list> "]"
|
||||||
|
|
||||||
<interface_method_signature> ::=
|
|
||||||
<accessibility_modifier> <function_keyword> <identifier> <function_signature>
|
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,22 @@
|
||||||
<program> ::= <use_statement>*
|
<program> ::= <use_statement>*
|
||||||
|
<optional_whitespace>
|
||||||
|
<comment>*
|
||||||
<optional_whitespace>
|
<optional_whitespace>
|
||||||
<top_level_definition>*
|
<top_level_definition>*
|
||||||
<optional_whitespace>
|
<optional_whitespace>
|
||||||
|
<comment>*
|
||||||
|
<optional_whitespace>
|
||||||
|
|
||||||
<use_statement> ::= <use_statement_identifier>
|
<use_statement> ::= <use_statement_identifier>
|
||||||
<optional_whitespace>
|
<required_single_line_whitespace>
|
||||||
<identifier>
|
<identifier> ("." <identifier>)*
|
||||||
("." <identifier>)*
|
|
||||||
<optional_whitespace> ";"
|
<optional_whitespace> ";"
|
||||||
|
|
||||||
<top_level_definition> ::= (<type_declaration>
|
<top_level_definition> ::= <type_declaration> | <interface_declaration> | <error_declaration>
|
||||||
| <interface_declaration>
|
|
||||||
| <error_declaration>)
|
|
||||||
<optional_whitespace>
|
|
||||||
|
|
||||||
import "core/keywords.bnf"
|
import "core/keywords.bnf"
|
||||||
import "core/comments.bnf"
|
import "core/comments.bnf"
|
||||||
|
import "core/whitespace.bnf"
|
||||||
import "core/base_types.bnf"
|
import "core/base_types.bnf"
|
||||||
import "core/identifiers.bnf"
|
import "core/identifiers.bnf"
|
||||||
import "core/literals.bnf"
|
import "core/literals.bnf"
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,6 @@
|
||||||
<statement> ::= <assignment_statement>
|
|
||||||
| <if_statement>
|
|
||||||
| <while_statement>
|
|
||||||
| <loop_statement>
|
|
||||||
| <reverse_loop_statement>
|
|
||||||
| <function_call_statement>
|
|
||||||
| <return_statement>
|
|
||||||
| <using_statement>
|
|
||||||
| <attempt_statement>
|
|
||||||
| <fail_statement>
|
|
||||||
|
|
||||||
<statement> ::= <optional_whitespace>
|
<statement> ::= <optional_whitespace>
|
||||||
|
<comment>*
|
||||||
|
<optional_whitespace>
|
||||||
(<assignment_statement>
|
(<assignment_statement>
|
||||||
| <if_statement>
|
| <if_statement>
|
||||||
| <while_statement>
|
| <while_statement>
|
||||||
|
|
@ -21,6 +12,8 @@
|
||||||
| <attempt_statement>
|
| <attempt_statement>
|
||||||
| <fail_statement>)
|
| <fail_statement>)
|
||||||
<optional_whitespace>
|
<optional_whitespace>
|
||||||
|
<comment>*
|
||||||
|
<optional_whitespace>
|
||||||
|
|
||||||
<assignment_statement> ::= <my_identifier> ".set(" <expression> ")" ";"
|
<assignment_statement> ::= <my_identifier> ".set(" <expression> ")" ";"
|
||||||
|
|
||||||
|
|
@ -30,7 +23,7 @@
|
||||||
<optional_whitespace>
|
<optional_whitespace>
|
||||||
<boolean_expression>
|
<boolean_expression>
|
||||||
<optional_whitespace> ")"
|
<optional_whitespace> ")"
|
||||||
"{" <statement>* "}"
|
<standard_statement_block>
|
||||||
(<elseif_statement_keyword>
|
(<elseif_statement_keyword>
|
||||||
<optional_whitespace>
|
<optional_whitespace>
|
||||||
"("
|
"("
|
||||||
|
|
@ -38,37 +31,35 @@
|
||||||
<boolean_expression>
|
<boolean_expression>
|
||||||
<optional_whitespace>
|
<optional_whitespace>
|
||||||
")"
|
")"
|
||||||
"{"
|
<standard_statement_block>
|
||||||
<statement>*
|
|
||||||
"}"
|
|
||||||
)?
|
)?
|
||||||
(<else_statement_keyword>
|
(<else_statement_keyword>
|
||||||
<optional_whitespace>
|
<optional_whitespace>
|
||||||
"{"
|
<standard_statement_block>
|
||||||
<statement>*
|
|
||||||
"}"
|
|
||||||
)?
|
)?
|
||||||
|
|
||||||
<while_statement> ::= <while_loop_keyword> "(" <expression> ")"
|
<standard_statement_block> ::= <optional_whitespace> "{" <optional_whitespace> <statement>* <optional_whitespace> "}" <optional_whitespace>
|
||||||
"{" <statement>* "}"
|
|
||||||
|
<while_statement> ::= <while_loop_keyword> "(" <expression> ")" <standard_statement_block>
|
||||||
|
|
||||||
<loop_statement> ::= <for_loop_keyword> "(" <identifier> "," <expression> "->" <expression>
|
<loop_statement> ::= <for_loop_keyword> "(" <identifier> "," <expression> "->" <expression>
|
||||||
("," <expression>)? ")"
|
("," <expression>)? ")"
|
||||||
"{" <statement>* "}"
|
<standard_statement_block>
|
||||||
|
|
||||||
<reverse_loop_statement> ::= <reverse_for_loop_keyword> "(" <identifier> "," <expression> "->" <expression>
|
<reverse_loop_statement> ::= <reverse_for_loop_keyword> "(" <identifier> "," <expression> "->" <expression>
|
||||||
("," <expression>)? ")"
|
("," <expression>)? ")"
|
||||||
"{" <statement>* "}"
|
<standard_statement_block>
|
||||||
|
|
||||||
<function_call_statement> ::= <my_identifier> "(" <argument_list>? ")" ";"
|
<function_call_statement> ::= <my_identifier> "(" <argument_list>? ")" ";"
|
||||||
|
|
||||||
<return_statement> ::= <return_statement_keyword> <expression> ";"
|
<return_statement> ::= <return_statement_keyword> <expression> ";"
|
||||||
|
|
||||||
<using_statement> ::= <context_management_keyword> <type> <identifier> ".set(" <expression> ")"
|
<using_statement> ::= <context_management_keyword> <type> <identifier> ".set(" <expression> ")"
|
||||||
"{" <statement>* "}"
|
<standard_statement_block>
|
||||||
|
|
||||||
<attempt_statement> ::= <expression> ".attempt" "{" <attempt_handler>* "}"
|
<attempt_statement> ::= <expression> ".attempt" "{" <attempt_handler>* "}"
|
||||||
|
|
||||||
<attempt_handler> ::= ("ok" | <identifier> | "error") "{" <statement>* "}"
|
<attempt_handler> ::= ("ok" | <identifier> | "error") <standard_statement_block>
|
||||||
|
|
||||||
|
<fail_statement> ::= <my_identifier> "." <exception_throw_keyword> "(" <inherited_error_type> ("(" <argument_list>? ")")? ")" ";"
|
||||||
|
|
||||||
<fail_statement> ::= <my_identifier> "." <exception_throw_keyword> "(" <error_type> ("(" <argument_list>? ")")? ")" ";"
|
|
||||||
|
|
|
||||||
|
|
@ -17,3 +17,4 @@
|
||||||
| <identifier>
|
| <identifier>
|
||||||
|
|
||||||
<argument_list> ::= <expression> ("," <expression>)*
|
<argument_list> ::= <expression> ("," <expression>)*
|
||||||
|
|
||||||
|
|
|
||||||
59
scripts/flatten.sh
Executable file
59
scripts/flatten.sh
Executable file
|
|
@ -0,0 +1,59 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Check if input file is provided
|
||||||
|
#if [ $# -eq 0 ]; then
|
||||||
|
# echo "Usage: $0 <input_file> [output_file]"
|
||||||
|
# exit 1
|
||||||
|
#fi
|
||||||
|
|
||||||
|
# Input and output file names
|
||||||
|
INPUT_FILE="./working/waddle.bnf"
|
||||||
|
OUTPUT_FILE="./working/waddle_flattened.bnf"
|
||||||
|
|
||||||
|
# Flatten multi-line BNF definitions
|
||||||
|
awk '
|
||||||
|
BEGIN {
|
||||||
|
in_definition = 0
|
||||||
|
current_line = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
/^[[:space:]]*$/ {
|
||||||
|
# Empty line
|
||||||
|
if (in_definition) {
|
||||||
|
# Remove leading/trailing whitespace and collapse internal whitespace
|
||||||
|
gsub(/^[[:space:]]+|[[:space:]]+$/, "", current_line)
|
||||||
|
gsub(/[[:space:]]+/, " ", current_line)
|
||||||
|
print current_line
|
||||||
|
current_line = ""
|
||||||
|
in_definition = 0
|
||||||
|
}
|
||||||
|
next
|
||||||
|
}
|
||||||
|
|
||||||
|
/^[[:space:]]*import/ {
|
||||||
|
# Print import line as-is
|
||||||
|
print $0
|
||||||
|
next
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
in_definition = 1
|
||||||
|
# Append current line to definition, removing leading/trailing whitespace
|
||||||
|
if (current_line == "") {
|
||||||
|
current_line = $0
|
||||||
|
} else {
|
||||||
|
current_line = current_line " " $0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
END {
|
||||||
|
# Handle last definition if exists
|
||||||
|
if (in_definition) {
|
||||||
|
gsub(/^[[:space:]]+|[[:space:]]+$/, "", current_line)
|
||||||
|
gsub(/[[:space:]]+/, " ", current_line)
|
||||||
|
print current_line
|
||||||
|
}
|
||||||
|
}
|
||||||
|
' "$INPUT_FILE" > "$OUTPUT_FILE"
|
||||||
|
|
||||||
|
echo "Flattened BNF saved to $OUTPUT_FILE"
|
||||||
Loading…
Reference in a new issue