- Refactor statement parsing with proper precedence handling - Improve block structure parsing with indent/dedent support - Enhance control flow parsing (conditionals, loops) - Add print command support - Improve function declaration parsing - Update scanner for better string and comment handling - Add comprehensive test corpus - Better handling of newlines and statement boundaries
338 lines
6.6 KiB
Plaintext
338 lines
6.6 KiB
Plaintext
==================
|
|
Variable Declarations
|
|
==================
|
|
var x
|
|
var y = 10
|
|
var name = "Hello"
|
|
var flag = true
|
|
------------------
|
|
(source_file
|
|
(variable_declaration (identifier))
|
|
(variable_declaration (identifier) (number))
|
|
(variable_declaration (identifier) (string))
|
|
(variable_declaration (identifier) (boolean))
|
|
)
|
|
|
|
==================
|
|
Function Declaration
|
|
==================
|
|
func test()
|
|
return 5
|
|
|
|
func add(a, b)
|
|
return a + b
|
|
------------------
|
|
(source_file
|
|
(function_declaration
|
|
(identifier)
|
|
(block
|
|
(return_statement (number))
|
|
)
|
|
)
|
|
(function_declaration
|
|
(identifier)
|
|
(parameter_list (identifier) (identifier))
|
|
(block
|
|
(return_statement
|
|
(binary_expression (identifier) (identifier))
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
==================
|
|
For Loops
|
|
==================
|
|
for i = 1..10
|
|
var x = i
|
|
|
|
for item : array
|
|
print item
|
|
------------------
|
|
(source_file
|
|
(for_loop
|
|
(identifier)
|
|
(number)
|
|
(number)
|
|
(block
|
|
(variable_declaration (identifier) (identifier))
|
|
)
|
|
)
|
|
(for_loop
|
|
(identifier)
|
|
(identifier)
|
|
(block
|
|
(command (identifier) (identifier))
|
|
)
|
|
)
|
|
)
|
|
|
|
==================
|
|
Arrays
|
|
==================
|
|
var arr = []
|
|
var nums = [1, 2, 3]
|
|
var names = ["a", "b"]
|
|
------------------
|
|
(source_file
|
|
(variable_declaration (identifier) (array))
|
|
(variable_declaration (identifier) (array (array_elements (number) (number) (number))))
|
|
(variable_declaration (identifier) (array (array_elements (string) (string))))
|
|
)
|
|
|
|
==================
|
|
Member Access and Method Calls
|
|
==================
|
|
var x = loc.stars
|
|
var y = math.Sqrt(9)
|
|
arr.Add(5)
|
|
------------------
|
|
(source_file
|
|
(variable_declaration
|
|
(identifier)
|
|
(member_expression (identifier) (identifier))
|
|
)
|
|
(variable_declaration
|
|
(identifier)
|
|
(call_expression
|
|
(member_expression (identifier) (identifier))
|
|
(argument_list (number))
|
|
)
|
|
)
|
|
(expression_statement
|
|
(call_expression
|
|
(member_expression (identifier) (identifier))
|
|
(argument_list (number))
|
|
)
|
|
)
|
|
)
|
|
|
|
==================
|
|
Conditionals with Else
|
|
==================
|
|
?hp < 10
|
|
activate potion
|
|
:?hp < 20
|
|
equip shield
|
|
:
|
|
equip sword
|
|
------------------
|
|
(source_file
|
|
(conditional
|
|
(binary_expression (identifier) (number))
|
|
(block
|
|
(command (identifier) (identifier))
|
|
)
|
|
)
|
|
(else_clause
|
|
(binary_expression (identifier) (number))
|
|
(block
|
|
(command (identifier) (identifier))
|
|
)
|
|
)
|
|
(else_clause
|
|
(block
|
|
(command (identifier) (identifier))
|
|
)
|
|
)
|
|
)
|
|
|
|
==================
|
|
Equipment Commands
|
|
==================
|
|
equip sword
|
|
equipL poison wand
|
|
equipR vigor shield *7 +5
|
|
------------------
|
|
(source_file
|
|
(command (identifier) (identifier))
|
|
(command (identifier) (identifier) (identifier))
|
|
(command (identifier) (identifier) (identifier) (star_level (number)) (enchantment_level (number)))
|
|
)
|
|
|
|
==================
|
|
Activate and Loadout
|
|
==================
|
|
activate potion
|
|
activate R
|
|
loadout 1
|
|
------------------
|
|
(source_file
|
|
(command (identifier) (identifier))
|
|
(command (identifier) (identifier))
|
|
(command (identifier) (number))
|
|
)
|
|
|
|
==================
|
|
Import and New
|
|
==================
|
|
import UI/MindstoneButton
|
|
var obj = new Components/Vector
|
|
------------------
|
|
(source_file
|
|
(import_statement (module_path))
|
|
(variable_declaration
|
|
(identifier)
|
|
(new_statement (module_path))
|
|
)
|
|
)
|
|
|
|
==================
|
|
Binary Operations
|
|
==================
|
|
var result = a + b * c
|
|
var check = x > 5 & y < 10
|
|
------------------
|
|
(source_file
|
|
(variable_declaration
|
|
(identifier)
|
|
(binary_expression
|
|
(identifier)
|
|
(binary_expression (identifier) (identifier))
|
|
)
|
|
)
|
|
(variable_declaration
|
|
(identifier)
|
|
(binary_expression
|
|
(binary_expression (identifier) (number))
|
|
(binary_expression (identifier) (number))
|
|
)
|
|
)
|
|
)
|
|
|
|
==================
|
|
Update Expressions
|
|
==================
|
|
i++
|
|
--j
|
|
var x = count++
|
|
------------------
|
|
(source_file
|
|
(expression_statement (update_expression (identifier)))
|
|
(expression_statement (update_expression (identifier)))
|
|
(variable_declaration (identifier) (update_expression (identifier)))
|
|
)
|
|
|
|
==================
|
|
Assignment Operations
|
|
==================
|
|
x += 5
|
|
y *= 2
|
|
count -= 1
|
|
------------------
|
|
(source_file
|
|
(expression_statement (assignment_expression (identifier) (number)))
|
|
(expression_statement (assignment_expression (identifier) (number)))
|
|
(expression_statement (assignment_expression (identifier) (number)))
|
|
)
|
|
|
|
==================
|
|
Return, Break, Continue
|
|
==================
|
|
func test()
|
|
for i = 1..10
|
|
?i = 5
|
|
break
|
|
?i = 3
|
|
continue
|
|
return i
|
|
------------------
|
|
(source_file
|
|
(function_declaration
|
|
(identifier)
|
|
(block
|
|
(for_loop
|
|
(identifier)
|
|
(number)
|
|
(number)
|
|
(block
|
|
(conditional
|
|
(binary_expression (identifier) (number))
|
|
(block (break_statement))
|
|
)
|
|
(conditional
|
|
(binary_expression (identifier) (number))
|
|
(block (continue_statement))
|
|
)
|
|
)
|
|
)
|
|
(return_statement (identifier))
|
|
)
|
|
)
|
|
)
|
|
|
|
==================
|
|
Comments
|
|
==================
|
|
// Single line comment
|
|
var x = 5 // inline comment
|
|
/* Block
|
|
comment */
|
|
var y = 10
|
|
------------------
|
|
(source_file
|
|
(comment)
|
|
(variable_declaration (identifier) (number))
|
|
(comment)
|
|
(block_comment)
|
|
(variable_declaration (identifier) (number))
|
|
)
|
|
|
|
==================
|
|
Real Example from Manual
|
|
==================
|
|
?loc=rocky
|
|
equip shovel
|
|
?loc=cave
|
|
loadout 1
|
|
?foe=bolesh
|
|
equip grap
|
|
equip hammer *7
|
|
?loc=halls
|
|
equipL poison wand
|
|
equipR vigor wand
|
|
?loc.stars > 5
|
|
equip vigor staff +13
|
|
?hp < 10
|
|
activate potion
|
|
------------------
|
|
(source_file
|
|
(conditional
|
|
(binary_expression (identifier) (identifier))
|
|
(block (command (identifier) (identifier)))
|
|
)
|
|
(conditional
|
|
(binary_expression (identifier) (identifier))
|
|
(block
|
|
(command (identifier) (number))
|
|
(conditional
|
|
(binary_expression (identifier) (identifier))
|
|
(block
|
|
(command (identifier) (identifier))
|
|
(command (identifier) (identifier) (star_level (number)))
|
|
)
|
|
)
|
|
)
|
|
)
|
|
(conditional
|
|
(binary_expression (identifier) (identifier))
|
|
(block
|
|
(command (identifier) (identifier) (identifier))
|
|
(command (identifier) (identifier) (identifier))
|
|
(conditional
|
|
(binary_expression
|
|
(member_expression (identifier) (identifier))
|
|
(number)
|
|
)
|
|
(block
|
|
(command (identifier) (identifier) (identifier) (enchantment_level (number)))
|
|
)
|
|
)
|
|
)
|
|
)
|
|
(conditional
|
|
(binary_expression (identifier) (number))
|
|
(block (command (identifier) (identifier)))
|
|
)
|
|
)
|