Create a keywords.bnf file to hold much of the hardcoded strings (much, but not all) present in the rest of the bnf files
This commit is contained in:
parent
30ea8a2740
commit
07c27f3cdd
|
|
@ -1,14 +1,12 @@
|
|||
<type> ::= <primitive_type> | <complex_type> | <array_type> | <error_type>
|
||||
<type> ::= <primitive_type> | <inherited_type> | <array_type> | <error_type>
|
||||
|
||||
<primitive_type> ::= "String" | "Integer" | "Decimal" | "Boolean"
|
||||
<primitive_type> ::= <string_type_keyword> | <integer_type_keyword> | <decimal_type_keyword> | <boolean_type_keyword>
|
||||
|
||||
<complex_type> ::= <identifier> ["/" <identifier>]
|
||||
|
||||
<array_type> ::= <type> "<>"
|
||||
<array_type> ::= <type> <array_symbol_open> <array_symbol_close>
|
||||
|
||||
<parameter_type> ::= <type>
|
||||
| "Runnable"
|
||||
| <callable_type_keyword>
|
||||
| <error_type>
|
||||
| "Any"
|
||||
|
||||
<return_type_list> ::= "[" <type> ("," <type>)* "]" | "Runnable"
|
||||
<return_type_list> ::= "[" <type> ("," <type>)* "]" | <callable_type_keyword>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
<interface_identifier> ::= <identifier>
|
||||
|
||||
<my_identifier> ::= "my." <identifier>
|
||||
<my_identifier> ::= <instance_identifier> <identifier>
|
||||
|
||||
<letter> ::= <upper_letter> | <lower_letter>
|
||||
|
||||
|
|
@ -13,3 +13,8 @@
|
|||
<lower_letter> ::= "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"
|
||||
|
||||
<digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
|
||||
|
||||
<symbol> ::= "!" | "@" | "#" | "$" | "%" | "^" | "&" | "*" | "(" | ")" | "-" | "_" | "+" | "=" | "[" | "]" | "{" | "}" | "|" | "\" | ":" | ";" | "<" | ">" | "," | "." | "?" | "/"
|
||||
|
||||
<whitespace> ::= " " | "\t" | "\n" | "\r"
|
||||
|
||||
|
|
|
|||
57
grammar/core/keywords.bnf
Normal file
57
grammar/core/keywords.bnf
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<function_keyword> ::= "fn"
|
||||
|
||||
<arrow_keyword> ::= "->"
|
||||
|
||||
<string_type_keyword> ::= "String"
|
||||
|
||||
<integer_type_keyword> ::= "Integer"
|
||||
|
||||
<decimal_type_keyword> ::= "Decimal"
|
||||
|
||||
<boolean_type_keyword> ::= "Boolean"
|
||||
|
||||
<callable_type_keyword> ::= "Runnable"
|
||||
|
||||
<true_keyword> ::= "True"
|
||||
|
||||
<false_keyword> ::= "False"
|
||||
|
||||
<null_keyword> ::= "Null"
|
||||
|
||||
<array_symbol_open> ::= "<"
|
||||
|
||||
<array_symbol_close> ::= ">"
|
||||
|
||||
<instance_identifier> ::= "my."
|
||||
|
||||
<public_scope_identifier> ::= "+"
|
||||
|
||||
<protected_scope_identifier> ::= ""
|
||||
|
||||
<private_scope_identifier> ::= "-"
|
||||
|
||||
<function_error_identifier> ::= "fails with"
|
||||
|
||||
<constructor_method_name> ::= "on_create"
|
||||
|
||||
<destructor_name> ::= "on_destroy"
|
||||
|
||||
<use_statement_identifier> ::= "use"
|
||||
|
||||
<if_statement_keyword> ::= "if"
|
||||
|
||||
<elseif_statement_keyword> ::= "orif"
|
||||
|
||||
<else_statement_keyword> ::= "otherwise"
|
||||
|
||||
<while_loop_keyword> ::= "while"
|
||||
|
||||
<for_loop_keyword> ::= "loop"
|
||||
|
||||
<reverse_for_loop_keyword> ::= "rloop"
|
||||
|
||||
<return_statement_keyword> ::= "rtn"
|
||||
|
||||
<context_management_keyword> ::= "using"
|
||||
|
||||
<exception_throw_keyword> ::= "fail"
|
||||
|
|
@ -12,13 +12,24 @@
|
|||
<decimal_literal> ::= <digit>+ "." <digit>+
|
||||
| "-" <digit>+ "." <digit>+
|
||||
|
||||
<string_literal> ::= '"' [^\"]* '"'
|
||||
| "'" [^']* "'"
|
||||
<string_literal> ::= <double_quote_string> | <single_quote_string>
|
||||
|
||||
<boolean_literal> ::= "True" | "False"
|
||||
<double_quote_string> ::= <double_quote> <double_quote_content>* <double_quote>
|
||||
<single_quote_string> ::= <single_quote> <single_quote_content>* <single_quote>
|
||||
|
||||
<null_literal> ::= "Null"
|
||||
<double_quote_content> ::= <double_quote_character> <double_quote_content>
|
||||
<single_quote_content> ::= <single_quote_character> <single_quote_content>
|
||||
|
||||
<array_literal> ::= "<" <literal_list>? ">"
|
||||
<double_quote> ::= "\""
|
||||
<single_quote> ::= "'"
|
||||
|
||||
<double_quote_character> ::= <letter> | <digit> | <symbol> | <whitespace>
|
||||
<single_quote_character> ::= <letter> | <digit> | <symbol> | <whitespace>
|
||||
|
||||
<boolean_literal> ::= <true_keyword> | <false_keyword>
|
||||
|
||||
<null_literal> ::= <null_keyword>
|
||||
|
||||
<array_literal> ::= <array_symbol_open> <literal_list>? <array_symbol_close>
|
||||
|
||||
<literal_list> ::= <literal> ("," <literal>)*
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<accessibility_modifier> ::=
|
||||
"-"
|
||||
| ""
|
||||
| "+"
|
||||
<public_scope_identifier>
|
||||
| <protected_scope_identifier>
|
||||
| <private_scope_identifier>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<error_declaration> ::= <inherited_error_type>
|
||||
"{" <error_body>? "}"
|
||||
|
||||
<inherited_error_type> ::= [<parent_error> "/"]? <child_error>
|
||||
<inherited_error_type> ::= (<parent_error> "/")? <child_error>
|
||||
|
||||
<parent_error> ::= <identifier>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
<function_declaration> ::= <accessibility_modifier>"fn" <identifier>
|
||||
<function_declaration> ::= <accessibility_modifier> <function_keyword> <identifier>
|
||||
<function_signature>
|
||||
["fails" "with" <error_type_list>]?
|
||||
(<function_error_identifier> <error_type_list>)?
|
||||
"{" <statement>* "}"
|
||||
|
||||
<function_signature> ::= "(" <parameter_list>? ")"
|
||||
"->" <return_type_list>
|
||||
<arrow_keyword> <return_type_list>
|
||||
|
||||
<error_type_list> ::= <error_type> ("," <error_type>)*
|
||||
|
||||
<error_type> ::= <identifier> ["/" <identifier>]?
|
||||
<error_type> ::= <identifier> ("/" <identifier>)?
|
||||
|
||||
<parameter_list> ::=
|
||||
<parameter_group>?
|
||||
|
|
@ -30,6 +30,6 @@
|
|||
|
||||
<default_parameter> ::= <parameter_type> <identifier> ".default(" <literal> ")"
|
||||
|
||||
<lambda_declaration> ::= "fn" "(" <parameter_list>? ")"
|
||||
"->" "[" <type> "]"
|
||||
<lambda_declaration> ::= <function_keyword> "(" <parameter_list>? ")"
|
||||
<arrow_keyword> "[" <type> "]"
|
||||
"{" <statement>* "}"
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
| <constructor_declaration>
|
||||
| <destructor_declaration>)*
|
||||
|
||||
<inherited_type> ::= [<parent> "/"]? <child>
|
||||
<inherited_type> ::= (<parent> "/")? <child>
|
||||
|
||||
<parent> ::= <identifier>
|
||||
|
||||
|
|
@ -17,17 +17,17 @@
|
|||
<type_parameter_list> ::= <identifier> ("," <identifier>)*
|
||||
|
||||
<variable_declaration> ::= <type> <identifier>
|
||||
[".set(" <expression> ")"]? ";"
|
||||
(".set(" <expression> ")")? ";"
|
||||
|
||||
<constant_declaration> ::= <type> <identifier> ".define(" <literal> ");"
|
||||
|
||||
<constructor_declaration> ::=
|
||||
<accessibility_modifier> "on_create" "(" <parameter_list>? ")"
|
||||
["fails" "with" <error_type_list>]?
|
||||
<accessibility_modifier> <constructor_name> "(" <parameter_list>? ")"
|
||||
(<function_error_identifier> <error_type_list>)?
|
||||
"{" <statement>* "}"
|
||||
|
||||
<destructor_declaration> ::=
|
||||
<accessibility_modifier> "on_destroy" "(" <parameter_list>? ")"
|
||||
["fails" "with" <error_type_list>]?
|
||||
<accessibility_modifier> <destructor_name> "(" <parameter_list>? ")"
|
||||
(<function_error_identifier> <error_type_list>)?
|
||||
"{" <statement>* "}"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<interface_declaration> ::= "@" [<interface_parent> "/"]? <interface_child>
|
||||
<interface_declaration> ::= "@" (<interface_parent> "/")? <interface_child>
|
||||
"{" <interface_body> "}"
|
||||
|
||||
<interface_parent> ::= <identifier>
|
||||
|
|
@ -8,9 +8,9 @@
|
|||
<interface_body> ::= <interface_method_declaration>*
|
||||
|
||||
<interface_method_declaration> ::=
|
||||
<accessibility_modifier> "fn" <identifier> <function_signature> ";"
|
||||
<accessibility_modifier> <function_keyword> <identifier> <function_signature> ";"
|
||||
|
||||
<interface_implementation> ::= "->" <interface_identifier_list>
|
||||
<interface_implementation> ::= <arrow_keyword> "[" <interface_identifier_list> "]"
|
||||
|
||||
<interface_method_signature> ::=
|
||||
<accessibility_modifier>"fn" <identifier> <function_signature>
|
||||
<accessibility_modifier> <function_keyword> <identifier> <function_signature>
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
<program> ::= <use_statement>* <top_level_definition>*
|
||||
|
||||
<use_statement> ::= "use" <identifier> ("." <identifier>)* ";"
|
||||
<use_statement> ::= <use_statement_identifier> <identifier> ("." <identifier>)* ";"
|
||||
|
||||
<top_level_definition> ::=
|
||||
<type_declaration>
|
||||
| <interface_declaration>
|
||||
| <error_declaration>
|
||||
|
||||
import "core/keywords.bnf"
|
||||
import "core/base_types.bnf"
|
||||
import "core/identifiers.bnf"
|
||||
import "core/literals.bnf"
|
||||
|
|
|
|||
|
|
@ -11,31 +11,31 @@
|
|||
|
||||
<assignment_statement> ::= <my_identifier> ".set(" <expression> ")" ";"
|
||||
|
||||
<if_statement> ::= "if" "(" <boolean_expression> ")"
|
||||
<if_statement> ::= <if_statement_keyword> "(" <boolean_expression> ")"
|
||||
"{" <statement>* "}"
|
||||
["orif" "(" <boolean_expression> ")" "{" <statement>* "}"]?
|
||||
["otherwise" "{" <statement>* "}"]?
|
||||
(<elseif_statement_keyword> "(" <boolean_expression> ")" "{" <statement>* "}")?
|
||||
(<else_statement_keyword> "{" <statement>* "}")?
|
||||
|
||||
<while_statement> ::= "while" "(" <expression> ")"
|
||||
<while_statement> ::= <while_loop_keyword> "(" <expression> ")"
|
||||
"{" <statement>* "}"
|
||||
|
||||
<loop_statement> ::= "loop" "(" <identifier> "," <expression> "->" <expression>
|
||||
["," <expression>]? ")"
|
||||
<loop_statement> ::= <for_loop_keyword> "(" <identifier> "," <expression> "->" <expression>
|
||||
("," <expression>)? ")"
|
||||
"{" <statement>* "}"
|
||||
|
||||
<reverse_loop_statement> ::= "rloop" "(" <identifier> "," <expression> "->" <expression>
|
||||
["," <expression>]? ")"
|
||||
<reverse_loop_statement> ::= <reverse_for_loop_keyword> "(" <identifier> "," <expression> "->" <expression>
|
||||
("," <expression>)? ")"
|
||||
"{" <statement>* "}"
|
||||
|
||||
<function_call_statement> ::= <my_identifier> "(" <argument_list>? ")" ";"
|
||||
|
||||
<return_statement> ::= "rtn" <expression> ";"
|
||||
<return_statement> ::= <return_statement_keyword> <expression> ";"
|
||||
|
||||
<using_statement> ::= "using" <type> <identifier> ".set(" <expression> ")"
|
||||
<using_statement> ::= <context_management_keyword> <type> <identifier> ".set(" <expression> ")"
|
||||
"{" <statement>* "}"
|
||||
|
||||
<attempt_statement> ::= <expression> ".attempt" "{" <attempt_handler>* "}"
|
||||
|
||||
<attempt_handler> ::= ("ok" | <identifier> | "error") "{" <statement>* "}"
|
||||
|
||||
<fail_statement> ::= <my_identifier> ".fail(" <error_type> ["(" <argument_list>? ")"]? ")" ";"
|
||||
<fail_statement> ::= <my_identifier> "." <exception_throw_keyword> "(" <error_type> ("(" <argument_list>? ")")? ")" ";"
|
||||
|
|
|
|||
|
|
@ -20,13 +20,13 @@
|
|||
| <my_identifier> ".lte(" <expression> ")"
|
||||
| <my_identifier> ".and(" <boolean_expression> ")"
|
||||
| <my_identifier> ".or(" <boolean_expression> ")"
|
||||
| "Boolean.and(" <boolean_expression> "," <boolean_expression> ")"
|
||||
| "Boolean.or(" <boolean_expression> "," <boolean_expression> ")"
|
||||
| "Boolean.not(" <boolean_expression> ")"
|
||||
| "Boolean.eq(" <boolean_expression> "," <boolean_expression> ")"
|
||||
| "Boolean.is(" <boolean_expression> "," <boolean_expression> ")"
|
||||
| "Boolean.gt(" <boolean_expression> "," <boolean_expression> ")"
|
||||
| "Boolean.lt(" <boolean_expression> "," <boolean_expression> ")"
|
||||
| "Boolean.gte(" <boolean_expression> "," <boolean_expression> ")"
|
||||
| "Boolean.lte(" <boolean_expression> "," <boolean_expression> ")"
|
||||
| <boolean_type_keyword> ".and(" <boolean_expression> "," <boolean_expression> ")"
|
||||
| <boolean_type_keyword> ".or(" <boolean_expression> "," <boolean_expression> ")"
|
||||
| <boolean_type_keyword> ".not(" <boolean_expression> ")"
|
||||
| <boolean_type_keyword> ".eq(" <boolean_expression> "," <boolean_expression> ")"
|
||||
| <boolean_type_keyword> ".is(" <boolean_expression> "," <boolean_expression> ")"
|
||||
| <boolean_type_keyword> ".gt(" <boolean_expression> "," <boolean_expression> ")"
|
||||
| <boolean_type_keyword> ".lt(" <boolean_expression> "," <boolean_expression> ")"
|
||||
| <boolean_type_keyword> ".gte(" <boolean_expression> "," <boolean_expression> ")"
|
||||
| <boolean_type_keyword> ".lte(" <boolean_expression> "," <boolean_expression> ")"
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue