diff --git a/lang-parser b/lang-parser index 82f3a4e..ca9eac9 160000 --- a/lang-parser +++ b/lang-parser @@ -1 +1 @@ -Subproject commit 82f3a4edebad870fbf7d28bfd06bcc67731d5837 +Subproject commit ca9eac9857bb2e8276408fe4c0460d171485c569 diff --git a/src/build_visitor.cpp b/src/build_visitor.cpp index 1e9e59a..1062437 100644 --- a/src/build_visitor.cpp +++ b/src/build_visitor.cpp @@ -872,6 +872,13 @@ void BuildVisitor::Visit(BinaryOperatorExpression* node) { node->operator_name = parse_node.ChildByFieldName("operator_name").GetValue(); + { // remove operator prescendence markers + size_t operator_size = 0; + for (; operator_size < node->operator_name.size() && node->operator_name[operator_size] != '.'; ++operator_size) {} + + node->operator_name = node->operator_name.substr(0, operator_size); + } + current_node_ = parse_node.ChildByFieldName("right_expression"); Visit(node->right_expression); diff --git a/tests/arrays.lang b/tests/arrays.lang index 8fce315..c7d7689 100644 --- a/tests/arrays.lang +++ b/tests/arrays.lang @@ -3,7 +3,7 @@ def test_arrays = { var arr1 = ,1 ,2 ,3 const arr2 = Int._array: 32 var arr3 = String._array: 11 - const arr4 = 'a'..'z' + const arr4 = 'a'--'z' const n = 100 var @arr5 <- Int.@_new_array: 10 diff --git a/tests/default_constructors.lang b/tests/default_constructors.lang index ca9b513..51a19c6 100644 --- a/tests/default_constructors.lang +++ b/tests/default_constructors.lang @@ -1,6 +1,6 @@ namespace Employee { decl gen_employee : Unit -> Employee - def gen_employee : a = { + def gen_employee = { return $Employee & name = "John" diff --git a/tests/flow_control.lang b/tests/flow_control.lang index 160f8c3..4424be7 100644 --- a/tests/flow_control.lang +++ b/tests/flow_control.lang @@ -1,33 +1,32 @@ decl flow_control_test : Unit -> Unit def flow_control_test = { - if ((a < b) || (a == b)) && (b < c) then IO.print: x + if (a < b ||. a == b) && (b < c) then IO.print: x elif x < 0 then { - ; ++x + ; x += 1 ; IO.print: y } else { return {} } - while (a > 0) && (!array.is_empty:) do { - ; --a + while (a > 0) && not: (array.is_empty:) do { + ; a -= 1 ; array.pop: } - while x < 10 do - x += x + 3 + while x < 10 do x +=. x + 3 - for i in 0..y do { + for i in 0--y do { ; IO.print: i } - for & i & j in (& 0..y & 0..k) do { + for & i & j in & 0--y & 0--k do { // ?? ; IO.print: 1 ; IO.print: 2 ; IO.print: 128 } loop { - ; ++y + ; y += 1 if y > 100 then break } diff --git a/tests/functions.lang b/tests/functions.lang index 0f33512..e4f4acb 100644 --- a/tests/functions.lang +++ b/tests/functions.lang @@ -20,7 +20,7 @@ def find_prefix_hashes : str = { var hashes = (Array 'H).new: (str.size: + 1) ; hashes`0 = 'H.of: str`0 - for i in 1..hashes.size: do { + for i in 1--hashes.size: do { ; hashes`i = hashes`(i - 1) ; hashes`i.append: str`i } @@ -37,8 +37,8 @@ def find_substring : str substr = { const str_hashes = find_prefix_hashes Hash: str const substr_hash = Hash.of: substr - for i in 0..(str_hashes.size: - substr.size:) do { - const part_hash = Hash.diff: str_hashes`(i + substr->size:) str_hashes`i + for i in 0--(str_hashes.size: - substr.size:) do { + const part_hash = Hash.diff: str_hashes`(i + substr.size:) str_hashes`i if part_hash == substr_hash then { ; result.push: i diff --git a/tests/match.lang b/tests/match.lang index a45fb83..1d7ef33 100644 --- a/tests/match.lang +++ b/tests/match.lang @@ -1,8 +1,12 @@ +================================================================================ +Match +================================================================================ + decl fruit_cost : Fruit -> Int def fruit_cost : fruit = { - return (match fruit with - | $Banana -> 11 - | $Apple | $Orange -> 7) + return (match fruit with + | $Banana -> 11 + | $Apple | $Orange -> 7) } decl amount_to_string : Int -> Bool -> String @@ -10,8 +14,253 @@ def amount_to_string : x is_zero_separated = { const ans = match x with | 0 ? is_zero_separated -> "Zero" | 0 | 1 | 2 | 3 | 4 -> "Few" - | x ? (5..9).contains: x -> "Several" - | x ? (10..19).contains: x -> "Pack" + | x ? (5--9).contains: x -> "Several" + | x ? (10--19).contains: x -> "Pack" | _ -> "Lots" return ans } + +-------------------------------------------------------------------------------- + +(source_file + (source_statement + (namespace_statement + (function_declaration + (extended_name + (name_identifier)) + (function_type + (scoped_any_type + (type_expression + (parametrized_type + (type_identifier)))) + (scoped_any_type + (type_expression + (parametrized_type + (type_identifier)))))))) + (source_statement + (namespace_statement + (function_definition_statement + (function_definition + (extended_name + (name_identifier)) + (extended_name + (name_identifier))) + (superexpression + (expression + (prefixed_expression + (block + (block_statement + (prefixed_expression + (return_expression + (expression + (subexpression + (subexpression_token + (scoped_statement + (superexpression + (flow_control + (match + (expression + (subexpression + (subexpression_token + (name_expression + (extended_name + (name_identifier)))))) + (match_case + (pattern + (type_constructor_pattern + (type_expression + (parametrized_type + (type_identifier))))) + (expression + (subexpression + (subexpression_token + (literal + (number_literal)))))) + (match_case + (pattern + (type_constructor_pattern + (type_expression + (parametrized_type + (type_identifier)))))) + (match_case + (pattern + (type_constructor_pattern + (type_expression + (parametrized_type + (type_identifier))))) + (expression + (subexpression + (subexpression_token + (literal + (number_literal))))))))))))))))))))))) + (source_statement + (namespace_statement + (function_declaration + (extended_name + (name_identifier)) + (function_type + (scoped_any_type + (type_expression + (parametrized_type + (type_identifier)))) + (scoped_any_type + (type_expression + (parametrized_type + (type_identifier)))) + (scoped_any_type + (type_expression + (parametrized_type + (type_identifier)))))))) + (source_statement + (namespace_statement + (function_definition_statement + (function_definition + (extended_name + (name_identifier)) + (extended_name + (name_identifier)) + (extended_name + (name_identifier))) + (superexpression + (expression + (prefixed_expression + (block + (block_statement + (variable_definition_statement + (any_name + (annotated_name + (extended_name + (name_identifier)))) + (superexpression + (flow_control + (match + (expression + (subexpression + (subexpression_token + (name_expression + (extended_name + (name_identifier)))))) + (match_case + (pattern + (literal + (number_literal))) + (expression + (subexpression + (subexpression_token + (name_expression + (extended_name + (name_identifier)))))) + (expression + (subexpression + (subexpression_token + (literal + (string_literal)))))) + (match_case + (pattern + (literal + (number_literal)))) + (match_case + (pattern + (literal + (number_literal)))) + (match_case + (pattern + (literal + (number_literal)))) + (match_case + (pattern + (literal + (number_literal)))) + (match_case + (pattern + (literal + (number_literal))) + (expression + (subexpression + (subexpression_token + (literal + (string_literal)))))) + (match_case + (pattern + (extended_name + (name_identifier))) + (expression + (subexpression + (function_call_expression + (subexpression_token + (scoped_statement + (superexpression + (expression + (subexpression + (binary_operator_expression + (subexpression + (subexpression_token + (literal + (number_literal)))) + (operator) + (subexpression + (subexpression_token + (literal + (number_literal)))))))))) + (extended_name + (name_identifier)) + (subexpression_token + (name_expression + (extended_name + (name_identifier))))))) + (expression + (subexpression + (subexpression_token + (literal + (string_literal)))))) + (match_case + (pattern + (extended_name + (name_identifier))) + (expression + (subexpression + (function_call_expression + (subexpression_token + (scoped_statement + (superexpression + (expression + (subexpression + (binary_operator_expression + (subexpression + (subexpression_token + (literal + (number_literal)))) + (operator) + (subexpression + (subexpression_token + (literal + (number_literal)))))))))) + (extended_name + (name_identifier)) + (subexpression_token + (name_expression + (extended_name + (name_identifier))))))) + (expression + (subexpression + (subexpression_token + (literal + (string_literal)))))) + (match_case + (pattern + (extended_name + (name_identifier))) + (expression + (subexpression + (subexpression_token + (literal + (string_literal))))))))))) + (block_statement + (prefixed_expression + (return_expression + (expression + (subexpression + (subexpression_token + (name_expression + (extended_name + (name_identifier))))))))))))))))) diff --git a/tests/partitions.lang b/tests/partitions.lang index dbac56a..9ec0b99 100644 --- a/tests/partitions.lang +++ b/tests/partitions.lang @@ -4,6 +4,7 @@ test All::Dev::Syntax::testing { } exec App::exe { - const b = 1117 - ; do_something_different: b b + const b = true + const c = false + ; do_something_different: b b c } diff --git a/tests/tuples.lang b/tests/tuples.lang index c4613b1..1bca00c 100644 --- a/tests/tuples.lang +++ b/tests/tuples.lang @@ -4,5 +4,5 @@ def test_tuples = { const & t1 & t2 & t3 = f: x ; tuple1`0 = "b" - + } diff --git a/tests/typeclasses.lang b/tests/typeclasses.lang index d85e022..e82bdaa 100644 --- a/tests/typeclasses.lang +++ b/tests/typeclasses.lang @@ -17,10 +17,10 @@ decl ( < ) ('A : #Ord) : 'A -> 'A -> Bool def ( < ) : a b = a.is_less_then: b decl ( > ) ('A : #Ord) : 'A -> 'A -> Bool -def ( > ) : a b = !(a <= b) +def ( > ) : a b = not: (a <= b) decl ( <= ) ('A : #Ord) : 'A -> 'A -> Bool -def ( <= ) : a b = (a < b) || (a == b) +def ( <= ) : a b = a < b ||. a == b decl ( >= ) ('A : #Ord) : 'A -> 'A -> Bool -def ( >= ) : a b = !(a < b) +def ( >= ) : a b = not: (a < b) diff --git a/tests/types.lang b/tests/types.lang index f6ce429..757362c 100644 --- a/tests/types.lang +++ b/tests/types.lang @@ -1,3 +1,7 @@ +================================================================================ +Types +================================================================================ + alias T1 = Int abstract (T2 : #A #B #C) @@ -6,3 +10,45 @@ abstract (T2 : #A #B #C) let T2 = Int let T2 = Float let T2 = Complex + +-------------------------------------------------------------------------------- + +(source_file + (source_statement + (namespace_statement + (alias_definition_statement + (type_identifier) + (type_expression + (parametrized_type + (type_identifier)))))) + (source_statement + (abstract_type_definition_statement + (annotated_type + (type_identifier) + (parametrized_typeclass + (typeclass_identifier)) + (parametrized_typeclass + (typeclass_identifier)) + (parametrized_typeclass + (typeclass_identifier))))) + (source_statement + (namespace_statement + (alias_definition_statement + (type_identifier) + (type_expression + (parametrized_type + (type_identifier)))))) + (source_statement + (namespace_statement + (alias_definition_statement + (type_identifier) + (type_expression + (parametrized_type + (type_identifier)))))) + (source_statement + (namespace_statement + (alias_definition_statement + (type_identifier) + (type_expression + (parametrized_type + (type_identifier)))))))