mirror of https://github.com/arendst/Tasmota.git
Merge pull request #15906 from s-hadinger/berry_static_var
Berry prefer `static var` syntax
This commit is contained in:
commit
3d4a5bb4b9
|
@ -1446,11 +1446,16 @@ static void classdef_stmt(bparser *parser, bclass *c, bbool is_static)
|
|||
static void classstatic_stmt(bparser *parser, bclass *c, bexpdesc *e)
|
||||
{
|
||||
bstring *name;
|
||||
/* 'static' ID ['=' expr] {',' ID ['=' expr] } */
|
||||
/* 'static' ['var'] ID ['=' expr] {',' ID ['=' expr] } */
|
||||
/* 'static' 'def' ID '(' varlist ')' block 'end' */
|
||||
scan_next_token(parser); /* skip 'static' */
|
||||
if (next_type(parser) == KeyDef) { /* 'static' 'def' ... */
|
||||
classdef_stmt(parser, c, btrue);
|
||||
} else if (match_id(parser, name) != NULL) {
|
||||
} else {
|
||||
if (next_type(parser) == KeyVar) {
|
||||
scan_next_token(parser); /* skip 'var' if any */
|
||||
}
|
||||
if (match_id(parser, name) != NULL) {
|
||||
check_class_attr(parser, c, name);
|
||||
be_class_member_bind(parser->vm, c, name, bfalse);
|
||||
class_static_assignment_expr(parser, e, name);
|
||||
|
@ -1468,6 +1473,7 @@ static void classstatic_stmt(bparser *parser, bclass *c, bexpdesc *e)
|
|||
parser_error(parser, "class static error");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void class_inherit(bparser *parser, bexpdesc *e)
|
||||
{
|
||||
|
|
|
@ -8,11 +8,11 @@ def assert_attribute_error(f)
|
|||
end
|
||||
|
||||
class A
|
||||
static a
|
||||
static a #- deprecated syntax -#
|
||||
def init() self.b = 2 end
|
||||
def f() end
|
||||
var b
|
||||
static c, s, r
|
||||
static var c, s, r #- preferred syntax -#
|
||||
end
|
||||
|
||||
assert(A.a == nil)
|
||||
|
|
|
@ -17,7 +17,7 @@ func_body = '(' [arg_field {',' arg_field}] ')' block 'end';
|
|||
arg_field = ['*'] ID;
|
||||
(* class define statement *)
|
||||
class_stmt = 'class' ID [':' ID] class_block 'end';
|
||||
class_block = {'var' ID {',' ID} | 'static' ID ['=' expr] {',' ID ['=' expr] } | 'static' func_stmt | func_stmt};
|
||||
class_block = {'var' ID {',' ID} | 'static' ['var'] ID ['=' expr] {',' ID ['=' expr] } | 'static' func_stmt | func_stmt};
|
||||
import_stmt = 'import' (ID (['as' ID] | {',' ID}) | STRING 'as' ID);
|
||||
(* exceptional handling statement *)
|
||||
try_stmt = 'try' block except_block {except_block} 'end';
|
||||
|
@ -28,12 +28,13 @@ throw_stmt = 'raise' expr [',' expr];
|
|||
var_stmt = 'var' ID ['=' expr] {',' ID ['=' expr]};
|
||||
(* expression define *)
|
||||
expr_stmt = expr [assign_op expr];
|
||||
expr = suffix_expr | unop expr | expr binop expr | cond_expr;
|
||||
expr = suffix_expr | unop expr | expr binop expr | range_expr | cond_expr;
|
||||
cond_expr = expr '?' expr ':' expr; (* conditional expression *)
|
||||
assign_op = '=' | '+=' | '-=' | '*=' | '/=' |
|
||||
'%=' | '&=' | '|=' | '^=' | '<<=' | '>>=';
|
||||
binop = '..' | '<' | '<=' | '==' | '!=' | '>' | '>=' | '||' | '&&' |
|
||||
binop = '<' | '<=' | '==' | '!=' | '>' | '>=' | '||' | '&&' |
|
||||
'<<' | '>>' | '&' | '|' | '^' | '+' | '-' | '*' | '/' | '%';
|
||||
range_expr = expr '..' [expr]
|
||||
unop = '-' | '!' | '~';
|
||||
suffix_expr = primary_expr {call_expr | ('.' ID) | '[' expr ']'};
|
||||
primary_expr = '(' expr ')' | simple_expr | list_expr | map_expr | anon_func | lambda_expr;
|
||||
|
|
Loading…
Reference in New Issue