mirror of
https://codeberg.org/ProgramSnail/tree-sitter-lang.git
synced 2025-12-06 06:38:51 +00:00
grammar.g4 new types fixes
This commit is contained in:
parent
8e0cea277e
commit
c9bef5a02e
4 changed files with 195 additions and 106 deletions
41
grammar.g4
41
grammar.g4
|
|
@ -3,6 +3,8 @@ grammar lang ;
|
|||
// not always most recent grammar
|
||||
// not checked
|
||||
|
||||
// TODO
|
||||
|
||||
source_file: (statement)+ EOF ;
|
||||
|
||||
statement: import
|
||||
|
|
@ -21,7 +23,7 @@ constraint: '?' expression ;
|
|||
function_definition: (definietion_info)? (ANNOTATION_INFO)* (constraint ';')*
|
||||
('.')? (SIMPLE_NAME_IDENTIFIER | ('(' OPERATOR ')')) ('?' | '!')
|
||||
(((ANNOTATION_IDENTIFIER)? (REFERENCE)? ARGUMENT_NAME_IDENTIFIER ('?' | '!')?)*)
|
||||
(':' ((ANNOTATION_IDENTIFIER)? (REFERENCE)? type)+)?
|
||||
(':' ((ANNOTATION_IDENTIFIER)? (REFERENCE)? scoped_type)+)?
|
||||
(('=' ( /*prec 2*/ block | (super_expression ';'))) | ';')
|
||||
;
|
||||
|
||||
|
|
@ -29,7 +31,7 @@ type_definition: (DEFINITION_INFO)? (ANNOTATION_INFO)* ('^')?
|
|||
(SIMPLE_TYPE_IDENTIFIER | TYPECLASS_IDENTIFIER)
|
||||
('[' (TYPECLASS_IDENTIFIER)+ ']')?
|
||||
(ARGUMENT_TYPE_IDENTIFIER)*
|
||||
('=' variant_type)?
|
||||
('=' type)?
|
||||
';'
|
||||
;
|
||||
|
||||
|
|
@ -76,7 +78,7 @@ loop_control: 'break'
|
|||
;
|
||||
|
||||
name_expression:
|
||||
((type '.' SIMPLE_NAME_IDENTIFIER)
|
||||
((scoped_type '.' SIMPLE_NAME_IDENTIFIER)
|
||||
| (scoped_expression '.' SIMPLE_NAME_IDENTIFIER)
|
||||
| name_identifier
|
||||
| ('(' OPERATOR ')'))
|
||||
|
|
@ -84,7 +86,7 @@ name_expression:
|
|||
;
|
||||
|
||||
|
||||
constructor: type (ANNOTATION_IDENTIFIER)? scoped_expression)+ ;
|
||||
constructor: scoped_type (ANNOTATION_IDENTIFIER)? scoped_expression)+ ;
|
||||
|
||||
lambda: '\\' (ARGUMENT_NAME_IDENTIFIER)* '=>' expression ;
|
||||
|
||||
|
|
@ -121,13 +123,34 @@ not_name_scoped_expression: block
|
|||
| '(' super_expression ')'
|
||||
;
|
||||
|
||||
variant_type: ('|')? tuple_type ('|' tuple_type)* ;
|
||||
variant_type: ('|')? annotated_type ('|' annotated_type)+ ;
|
||||
|
||||
tuple_type: ('&')? annotated_type ('&' _annotated_type)* ;
|
||||
tuple_type: ('&')? annotated_type ('&' _annotated_type)+ ;
|
||||
|
||||
annotated_type: (ANNOTATION_IDENTIFIER)? type ;
|
||||
annotated_type: (ANNOTATION_IDENTIFIER)? scoped_type ;
|
||||
|
||||
type: ('^')? type_identifier ('?')? ('[' (type)+ ']')? ;
|
||||
array_type: '[[' type ']]' ;
|
||||
|
||||
reference_type: /* prec -1 */ '^' scoped_type ;
|
||||
|
||||
modified_type: scoped_type ('?' | '!') ;
|
||||
|
||||
simple_type: type_identifier ('[' (scoped_type)+ ']')? ;
|
||||
|
||||
type: simple_type
|
||||
| reference_type
|
||||
| modified_type
|
||||
| array_type
|
||||
| variant_type
|
||||
| tuple_type
|
||||
;
|
||||
|
||||
scoped_type: simple_type
|
||||
| reference_type
|
||||
| modified_type
|
||||
| array_type
|
||||
| '(' (variant_type | tuple_type) ')'
|
||||
;
|
||||
|
||||
name_identifier: (ARGUMENT_NAME_IDENTIFIER | SIMPLE_NAME_IDENTIFIER) ;
|
||||
type_identifier: (ARGUMENT_TYPE_IDENTIFIER | SIMPLE_TYPE_IDENTIFIER) ;
|
||||
|
|
@ -152,7 +175,7 @@ EXTRA: EMPTY_LINES
|
|||
|
||||
EMPTY_LINES : ('\n')+ ;
|
||||
|
||||
LINE_COMMENT : '#!' [^\n]* -> skip ;
|
||||
EXEC_COMMENT : '#!' [^\n]* -> skip ;
|
||||
LINE_COMMENT : '//' [^\n]* -> skip ;
|
||||
BLOCK_COMMENT : '\*' ([^*] |('\*' [^/]))* '*/' -> skip ;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue