File: ArgumentsBlock.m.matlab.folded

package info (click to toggle)
codequery 1.0.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,860 kB
  • sloc: cpp: 151,420; xml: 16,576; python: 5,602; ansic: 5,487; makefile: 559; perl: 496; ruby: 209; sql: 194; sh: 106; php: 53; vhdl: 51; erlang: 47; objc: 22; lisp: 18; cobol: 18; modula3: 17; asm: 14; fortran: 12; ml: 11; tcl: 6
file content (138 lines) | stat: -rw-r--r-- 3,947 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
 0 400 400   %% Correctly defined arguments block
 2 400 401 + function y = foo (x)
 0 401 401 | % Some comment here
 0 401 401 | % And, maybe, here
 1 401 401 | 
 2 401 402 + arguments
 0 402 402 |     x (1,2) {mustBeReal(x)}
 0 402 401 | end
 1 401 401 | 
 0 401 401 | y = x*2;
 0 401 401 | arguments = 1;
 0 401 401 | y = y + arguments;
 0 401 400 | end
 1 400 400   
 0 400 400   %% No arguments block, "arguments" is used 
 0 400 400   %  as a variable name (identifier)
 0 400 400   % Prevent arguments from folding with an identifier
 2 400 401 + function y = foo (x)
 0 401 401 | % Some comment here
 0 401 401 | x = x + 1;
 0 401 401 | arguments = 10;
 0 401 401 | y = x + arguments;
 0 401 400 | end
 1 400 400   
 0 400 400   % Prevent arguments from folding with a number
 2 400 401 + function y = foo (x)
 0 401 401 | 4
 0 401 401 | arguments = 10;
 0 401 401 | y = x + arguments;
 0 401 400 | end
 1 400 400   
 0 400 400   % With a double quote string
 2 400 401 + function y = foo (x)
 0 401 401 | "test"
 0 401 401 | arguments = 10;
 0 401 401 | y = x + arguments;
 0 401 400 | end
 1 400 400   
 0 400 400   % With a string
 2 400 401 + function y = foo (x)
 0 401 401 | 'test'
 0 401 401 | arguments = 10;
 0 401 401 | y = x + arguments;
 0 401 400 | end
 1 400 400   
 0 400 400   % With a keyword
 2 400 401 + function y = foo (x)
 2 401 402 + if x == 0;
 0 402 402 |     return 0;
 0 402 401 | end
 0 401 401 | arguments = 10;
 0 401 401 | y = x + arguments;
 0 401 400 | end
 1 400 400   
 0 400 400   % With an operator (illegal syntax)
 2 400 401 + function y = foo (x)
 0 401 401 | *
 0 401 401 | arguments = 10;
 0 401 401 | y = x + arguments;
 0 401 400 | end
 1 400 400   
 0 400 400   % Semicolon is equivalent to a comment
 2 400 401 + function y = foo(x)
 0 401 401 | ;;;;;;;
 2 401 402 + arguments
 0 402 402 |     x
 0 402 401 | end
 0 401 401 | y = x + 2;
 0 401 400 | end
 1 400 400   
 0 400 400   % Arguments block is illegal in nested functions,
 0 400 400   % but lexer should process it anyway
 2 400 401 + function y = foo (x)
 2 401 402 + arguments
 0 402 402 |     x (1,2) {mustBeReal(x)}
 0 402 401 | end
 1 401 401 | 
 2 401 402 +     function y = foo (x)
 2 402 403 +     arguments
 0 403 403 |         x (1,2) {mustBeReal(x)}
 0 403 402 |     end
 0 402 402 |     var = 0;
 0 402 402 |     arguments = 5;
 0 402 402 |     y = arguments + x;
 0 402 401 |     end
 1 401 401 | 
 0 401 401 | % Use as a variable, just in case
 0 401 401 | arguments = 10;
 0 401 400 | end
 1 400 400   
 0 400 400   % Erroneous use of arguments block
 2 400 401 + function y = foo(x)
 0 401 401 | % Some comment
 0 401 401 | x = x + 1;
 0 401 401 | arguments
 0 401 401 |     x
 0 401 400 | end
 0 400 400   y = x;
 0 400 3ff   end
 1 3ff 3ff   
 0 3ff 3ff   % "arguments" is an argument name too
 2 3ff 400 + function r = foo(x, arguments)
 2 400 401 + arguments
 0 401 401 |     x
 0 401 401 |     arguments
 0 401 400 | end
 0 400 400   r = bar(x, arguments{:});
 0 400 3ff   end
 1 3ff 3ff   
 0 3ff 3ff   % Multiple arguments blocks
 2 3ff 400 + function [a, b] = foo(x, y, varargin)
 1 400 400   
 2 400 401 + arguments(Input)
 0 401 401 |     x (1,4) {mustBeReal}
 0 401 401 |     y (1,:) {mustBeInteger} = x(2:end);
 0 401 400 | end
 1 400 400   
 2 400 401 + arguments(Input, Repeating)
 0 401 401 |     varargin
 0 401 400 | end
 1 400 400   
 2 400 401 + arguments(Output)
 0 401 401 |     a (1,1) {mustBeReal}
 0 401 401 |     b (1,1) {mustBeNonNegative}
 0 401 400 | end
 1 400 400   
 0 400 400   var = 10;
 0 400 400   arguments = {"now", "it's", "variable"};
 1 400 400   
 0 400 400   [a, b] = bar(x, y, arguments);
 1 400 400   
 0 400 3ff   end
 1 3ff 3ff   
 0 3ff 3ff   % One line function with arguments block.
 0 3ff 3ff   % This code style is rarely used (if at all), but the
 0 3ff 3ff   % lexer shouldn't break
 0 3ff 3ff   function y = foo(x); arguments; x; end; y = bar(x); end
 1 3ff 3ff