Implement proper whitespace functionality. Implement single line and multi line comments

This commit is contained in:
Funky Waddle 2025-11-28 03:28:36 -06:00
parent 07c27f3cdd
commit a1cc04575c
9 changed files with 145 additions and 47 deletions

View file

@ -9,4 +9,4 @@
| <error_type> | <error_type>
| "Any" | "Any"
<return_type_list> ::= "[" <type> ("," <type>)* "]" | <callable_type_keyword> <return_type_list> ::= "[" <optional_whitespace> <type> ( <optional_whitespace> "," <optional_whitespace> <type>)* <optional_whitespace> "]" | <callable_type_keyword>

11
grammar/core/comments.bnf Normal file
View file

@ -0,0 +1,11 @@
<comment> ::= <single_line_comment> | <multi_line_comment>
<single_line_comment> ::= <single_line_comment_identifier> <single_line_comment_character>* <multi_line_whitespace>
<multi_line_comment> ::= <multi_line_comment_open_identifier>
(<multi_line_comment_character> | <multi_line_comment>)*
<multi_line_comment_close_identifier>
<single_line_comment_character> ::= <letter> | <digit> | <symbol> | <single_line_whitespace>
<multi_line_comment_character> ::= <letter> | <digit> | <symbol> | <multi_line_whitespace>

View file

@ -16,5 +16,12 @@
<symbol> ::= "!" | "@" | "#" | "$" | "%" | "^" | "&" | "*" | "(" | ")" | "-" | "_" | "+" | "=" | "[" | "]" | "{" | "}" | "|" | "\" | ":" | ";" | "<" | ">" | "," | "." | "?" | "/" <symbol> ::= "!" | "@" | "#" | "$" | "%" | "^" | "&" | "*" | "(" | ")" | "-" | "_" | "+" | "=" | "[" | "]" | "{" | "}" | "|" | "\" | ":" | ";" | "<" | ">" | "," | "." | "?" | "/"
<whitespace> ::= " " | "\t" | "\n" | "\r" <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>)*

View file

@ -2,6 +2,12 @@
<arrow_keyword> ::= "->" <arrow_keyword> ::= "->"
<single_line_comment_identifier> ::= "//"
<multi_line_comment_open_identifier> ::= "/*"
<multi_line_comment_close_identifier> ::= "*/"
<string_type_keyword> ::= "String" <string_type_keyword> ::= "String"
<integer_type_keyword> ::= "Integer" <integer_type_keyword> ::= "Integer"

View file

@ -1,7 +1,16 @@
<function_declaration> ::= <accessibility_modifier> <function_keyword> <identifier> <function_declaration> ::= <optional_whitespace>
<accessibility_modifier>
<function_keyword>
<optional_whitespace>
<identifier>
<optional_whitespace>
<function_signature> <function_signature>
(<function_error_identifier> <error_type_list>)? <optional_whitespace>
"{" <statement>* "}" "{"
<optional_whitespace>
<statement>*
<optional_whitespace>
"}"
<function_signature> ::= "(" <parameter_list>? ")" <function_signature> ::= "(" <parameter_list>? ")"
<arrow_keyword> <return_type_list> <arrow_keyword> <return_type_list>
@ -10,26 +19,28 @@
<error_type> ::= <identifier> ("/" <identifier>)? <error_type> ::= <identifier> ("/" <identifier>)?
<parameter_list> ::= <parameter_list> ::= <parameter_group>?
<parameter_group>?
<parameter_group> ::= <parameter_group> ::= <optional_whitespace>
<required_parameters> ( <required_parameters>
| <required_parameters> "," <default_parameters> | <required_parameters> "," <default_parameters>
| <default_parameters> | <default_parameters> )
<optional_whitespace>
<required_parameters> ::= <required_parameters> ::=
<required_parameter> <optional_whitespace>
| <required_parameter> "," <required_parameters> ( <required_parameter>
| <required_parameter> "," <optional_whitespace> <required_parameters> )
<default_parameters> ::= <default_parameters> ::=
<default_parameter> <optional_whitespace>
| <default_parameter> "," <default_parameters> ( <default_parameter>
| <default_parameter> "," <default_parameters> )
<required_parameter> ::= <parameter_type> <identifier> <required_parameter> ::= <parameter_type> <identifier>
<default_parameter> ::= <parameter_type> <identifier> ".default(" <literal> ")" <default_parameter> ::= <parameter_type> <identifier> ".default(" <literal> ")"
<lambda_declaration> ::= <function_keyword> "(" <parameter_list>? ")" <lambda_declaration> ::= <function_keyword> <optional_whitespace> "(" <parameter_list>? ")"
<arrow_keyword> "[" <type> "]" <arrow_keyword> <optional_whitespace> "[" <optional_whitespace> <type> <optional_whitespace> "]"
"{" <statement>* "}" "{" <optional_whitespace> <statement>* <optional_whitespace> "}"

View file

@ -1,12 +1,21 @@
<type_declaration> ::= <inherited_type> <type_declaration> ::= <inherited_type>
<optional_whitespace>
<interface_implementation>? <interface_implementation>?
"{" <class_body> "}" <optional_whitespace>
"{"
<optional_whitespace>
<class_body>
<optional_whitespace>
"}"
<class_body> ::= (<variable_declaration> <class_body> ::= <optional_whitespace>
(<variable_declaration>
| <constant_declaration> | <constant_declaration>
| <function_declaration> | <function_declaration>
| <constructor_declaration> | <constructor_declaration>
| <destructor_declaration>)* | <destructor_declaration>
| <optional_whitespace>)*
<optional_whitespace>
<inherited_type> ::= (<parent> "/")? <child> <inherited_type> ::= (<parent> "/")? <child>
@ -16,8 +25,13 @@
<type_parameter_list> ::= <identifier> ("," <identifier>)* <type_parameter_list> ::= <identifier> ("," <identifier>)*
<variable_declaration> ::= <type> <identifier> <variable_declaration> ::= <optional_whitespace>
(".set(" <expression> ")")? ";" <type>
<optional_whitespace>
<identifier>
(".set(" <optional_whitespace> <expression> <optional_whitespace> ")")?
<optional_whitespace>
";"
<constant_declaration> ::= <type> <identifier> ".define(" <literal> ");" <constant_declaration> ::= <type> <identifier> ".define(" <literal> ");"

View file

@ -1,13 +1,21 @@
<program> ::= <use_statement>* <top_level_definition>* <program> ::= <use_statement>*
<optional_whitespace>
<top_level_definition>*
<optional_whitespace>
<use_statement> ::= <use_statement_identifier> <identifier> ("." <identifier>)* ";" <use_statement> ::= <use_statement_identifier>
<optional_whitespace>
<identifier>
("." <identifier>)*
<optional_whitespace> ";"
<top_level_definition> ::= <top_level_definition> ::= (<type_declaration>
<type_declaration>
| <interface_declaration> | <interface_declaration>
| <error_declaration> | <error_declaration>)
<optional_whitespace>
import "core/keywords.bnf" import "core/keywords.bnf"
import "core/comments.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"

View file

@ -9,12 +9,45 @@
| <attempt_statement> | <attempt_statement>
| <fail_statement> | <fail_statement>
<statement> ::= <optional_whitespace>
(<assignment_statement>
| <if_statement>
| <while_statement>
| <loop_statement>
| <reverse_loop_statement>
| <function_call_statement>
| <return_statement>
| <using_statement>
| <attempt_statement>
| <fail_statement>)
<optional_whitespace>
<assignment_statement> ::= <my_identifier> ".set(" <expression> ")" ";" <assignment_statement> ::= <my_identifier> ".set(" <expression> ")" ";"
<if_statement> ::= <if_statement_keyword> "(" <boolean_expression> ")" <if_statement> ::= <if_statement_keyword>
<optional_whitespace>
"("
<optional_whitespace>
<boolean_expression>
<optional_whitespace> ")"
"{" <statement>* "}" "{" <statement>* "}"
(<elseif_statement_keyword> "(" <boolean_expression> ")" "{" <statement>* "}")? (<elseif_statement_keyword>
(<else_statement_keyword> "{" <statement>* "}")? <optional_whitespace>
"("
<optional_whitespace>
<boolean_expression>
<optional_whitespace>
")"
"{"
<statement>*
"}"
)?
(<else_statement_keyword>
<optional_whitespace>
"{"
<statement>*
"}"
)?
<while_statement> ::= <while_loop_keyword> "(" <expression> ")" <while_statement> ::= <while_loop_keyword> "(" <expression> ")"
"{" <statement>* "}" "{" <statement>* "}"

View file

@ -1,14 +1,20 @@
<expression> ::= <my_identifier> <expression> ::= <optional_whitespace>
(
<my_identifier>
| <literal> | <literal>
| <object_method_call> | <object_method_call>
| <constant_declaration> | <constant_declaration>
| <type_conversion_expression> | <type_conversion_expression>
| "(" <expression> ")" | "(" <expression> ")"
| <lambda_declaration> | <lambda_declaration>
)
<optional_whitespace>
<type_conversion_expression> ::= <my_identifier> ".as(" <type> ")" <type_conversion_expression> ::= <my_identifier> ".as(" <optional_whitespace> <type> <optional_whitespace> ")"
<boolean_expression> ::= <boolean_expression> ::=
<optional_whitespace>
(
<boolean_literal> <boolean_literal>
| "(" <boolean_expression> ")" | "(" <boolean_expression> ")"
| <my_identifier> ".eq(" <expression> ")" | <my_identifier> ".eq(" <expression> ")"
@ -29,4 +35,6 @@
| <boolean_type_keyword> ".lt(" <boolean_expression> "," <boolean_expression> ")" | <boolean_type_keyword> ".lt(" <boolean_expression> "," <boolean_expression> ")"
| <boolean_type_keyword> ".gte(" <boolean_expression> "," <boolean_expression> ")" | <boolean_type_keyword> ".gte(" <boolean_expression> "," <boolean_expression> ")"
| <boolean_type_keyword> ".lte(" <boolean_expression> "," <boolean_expression> ")" | <boolean_type_keyword> ".lte(" <boolean_expression> "," <boolean_expression> ")"
)
<optional_whitespace>