mirror of
https://codeberg.org/ProgramSnail/tree-sitter-lang.git
synced 2025-12-06 06:38:51 +00:00
or_out or_in references added
This commit is contained in:
parent
a75ea8012d
commit
1a237adf0e
3 changed files with 45 additions and 20 deletions
|
|
@ -6,10 +6,10 @@ Test
|
|||
|
||||
:: module; // import module to current namespace
|
||||
|
||||
:: _ = module; // import module to current namespace and use functions inside without namespace
|
||||
:: _ = module_2; // import module to current namespace and use functions inside without namespace
|
||||
|
||||
:: module : func1 func2 func3;
|
||||
:: module_namespace = module;
|
||||
:: module_3 : func1 func2 func3;
|
||||
:: module_namespace = module_4;
|
||||
|
||||
func = {
|
||||
|
||||
|
|
@ -44,7 +44,7 @@ sum 'a? 'b? =
|
|||
: example that shows that default annotations are argument names (without ')
|
||||
@a is integer
|
||||
@b also integer
|
||||
sum 'a 'b = 'a + 'b;
|
||||
sum_2 'a 'b = 'a + 'b;
|
||||
|
||||
: this function can be used to calculate Fibonacci sequence elements
|
||||
: it is important is some algorithmic tasks
|
||||
|
|
@ -141,7 +141,7 @@ bubble_sort 'arr : <> Array['A] = {
|
|||
}
|
||||
|
||||
: bubble_sort with names instead of symbols
|
||||
bubble_sort 'arr : ref Array['A] = {
|
||||
bubble_sort_2 'arr : ref Array['A] = {
|
||||
var swap_occured := true;
|
||||
for swap_occured do {
|
||||
swap_occured = false;
|
||||
|
|
@ -155,9 +155,7 @@ bubble_sort 'arr : ref Array['A] = {
|
|||
& @key Key
|
||||
& @value Value
|
||||
& @left ^TreeNode['Key 'Value]
|
||||
& @right ^TreeNode['Key 'Value];
|
||||
|
||||
TreeNode {
|
||||
& @right ^TreeNode['Key 'Value] {
|
||||
new = do_something; // static methods
|
||||
|
||||
$insert 'key = do_something; // const methods
|
||||
|
|
@ -190,7 +188,7 @@ print_two 'a 'b = print 'a, print 'b;
|
|||
swap 'a 'b : <> 'A <> 'A = %c := <- 'a, 'a := <- 'b, 'b := <- c;
|
||||
|
||||
: previous example with automatic type deduction
|
||||
swap <> 'a <> 'b = %c := <- 'a, 'a := <- 'b, 'b := <- c;
|
||||
swap_2 <> 'a <> 'b = %c := <- 'a, 'a := <- 'b, 'b := <- c;
|
||||
|
||||
: several outputs example
|
||||
scan_three : -> String -> String -> String = scan & scan & scan;
|
||||
|
|
@ -221,6 +219,7 @@ parse_number : Unit! = {
|
|||
bring ();
|
||||
}
|
||||
|
||||
( & ) <-| 'a <-| 'b |-> 'x |-> 'y = (<-| 'a := |-> 'x) && (<-| 'b := |-> 'y);
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -877,10 +876,7 @@ parse_number : Unit! = {
|
|||
(type
|
||||
(argument_type_identifier))
|
||||
(type
|
||||
(argument_type_identifier))))))
|
||||
(empty_lines)
|
||||
(type_definition
|
||||
(simple_type_identifier)
|
||||
(argument_type_identifier)))))
|
||||
(function_definition
|
||||
(simple_name_identifier)
|
||||
(name_expression
|
||||
|
|
@ -1185,4 +1181,25 @@ parse_number : Unit! = {
|
|||
(name_expression
|
||||
(simple_name_identifier))
|
||||
(return
|
||||
(unit_literal)))))
|
||||
(unit_literal))))
|
||||
(empty_lines)
|
||||
(function_definition
|
||||
(operator)
|
||||
(argument_name_identifier)
|
||||
(argument_name_identifier)
|
||||
(argument_name_identifier)
|
||||
(argument_name_identifier)
|
||||
(operator_expression
|
||||
(match
|
||||
(reference_expression
|
||||
(argument_name_identifier))
|
||||
(case
|
||||
(reference_expression
|
||||
(argument_name_identifier))))
|
||||
(operator)
|
||||
(match
|
||||
(reference_expression
|
||||
(argument_name_identifier))
|
||||
(case
|
||||
(reference_expression
|
||||
(argument_name_identifier)))))))
|
||||
|
|
|
|||
18
grammar.g4
18
grammar.g4
|
|
@ -1,6 +1,6 @@
|
|||
grammar lang ;
|
||||
|
||||
// not always most recent grammar ??
|
||||
// not always most recent grammar
|
||||
// not checked
|
||||
|
||||
source_file: (statement)+ EOF ;
|
||||
|
|
@ -25,8 +25,8 @@ type_definition: (DEFINITION_INFO)? (ANNOTATION_INFO)* ('^')?
|
|||
|
||||
function_definition: (definietion_info)? (ANNOTATION_INFO)* (constraint ';')*
|
||||
(('%' | 'let') | ('$' | 'var'))? (SIMPLE_NAME_IDENTIFIER | ('(' OPERATOR ')'))
|
||||
((ANNOTATION_IDENTIFIER)? (('->' | 'in') | ('<-' | 'out') | ('<>' | 'ref')) ARGUMENT_NAME_IDENTIFIER ('?')?)*
|
||||
(':' ((ANNOTATION_IDENTIFIER)? (('->' | 'in') | ('<-' | 'out') | ('<>' | 'ref')))? type)+)?
|
||||
((ANNOTATION_IDENTIFIER)? (REFERENCE)? ARGUMENT_NAME_IDENTIFIER ('?')?)*
|
||||
(':' ((ANNOTATION_IDENTIFIER)? (REFERENCE)? type)+)?
|
||||
(('=' ( /*prec 2*/ block | (super_expression ';'))) | ';')
|
||||
;
|
||||
|
||||
|
|
@ -67,7 +67,7 @@ array_access: scoped_expression '[' super_expression ']' ;
|
|||
|
||||
tuple_access: scoped_expression, '.' NUMBER_LITERAL
|
||||
|
||||
reference_expression: /* prec -1 ?? */ (('->' | 'in') | ('<-' | 'out') | ('<>' | 'ref')) scoped_expression ;
|
||||
reference_expression: /* prec -1 ?? */ REFERENCE scoped_expression ;
|
||||
|
||||
suffix_expression: scoped_expression ('?' | '!')
|
||||
|
||||
|
|
@ -141,16 +141,24 @@ literal: FLOAT_NUMBER_LITERAL
|
|||
| BOOL_LITERAL
|
||||
| UNIT_LITERAL
|
||||
| NULL_LITERAL
|
||||
;
|
||||
|
||||
DEFINITION_INFO : : ': ' ([^\n]*)+ ;
|
||||
ANNOTATION_INFO : ANNOTATION_IDENTIFIER [^\n]* ;
|
||||
|
||||
EMPTY_LINES '\n' ('\n')+
|
||||
EMPTY_LINES '\n' ('\n')+ ;
|
||||
|
||||
LINE_COMMENT : '#!' [^\n]* -> skip ;
|
||||
LINE_COMMENT : '//' [^\n]* -> skip ;
|
||||
BLOCK_COMMENT : '\*' ([^*] |('\*' [^/]))* '*/' -> skip ;
|
||||
|
||||
REFERENCE: ('->' | 'out')
|
||||
| ('<-' | 'in')
|
||||
| ('<>' | 'ref')
|
||||
| ('|->' | 'or_out')
|
||||
| ('<-|' | 'or_in')
|
||||
;
|
||||
|
||||
PLACEHOLDER : '_' ;
|
||||
|
||||
SIMPLE_NAME_IDENTIFIER : ([a-z_][a-z0-9_]* '.')* [a-z_][a-z0-9_]* ;
|
||||
|
|
|
|||
|
|
@ -255,7 +255,7 @@ module.exports = grammar({
|
|||
_do: $ => choice('=>', 'do'),
|
||||
_var_let: $ => choice(choice('%', 'let'), choice('$', 'var')),
|
||||
_optional_result: $ => choice('?', '!'),
|
||||
_reference: $ => choice(choice('->', 'out'), choice('<-', 'in'), choice('<>', 'ref')),
|
||||
_reference: $ => choice(choice('->', 'out'), choice('<-', 'in'), choice('<>', 'ref'), choice('|->', 'or_out'), choice('<-|', 'or_in')),
|
||||
|
||||
_name_identifier: $ => choice($.argument_name_identifier, $.simple_name_identifier),
|
||||
_type_identifier: $ => choice($.argument_type_identifier, $.simple_type_identifier),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue