Wiki

root/cobra/trunk/Source/KeywordSpecs.cobra

Revision 2395, 12.4 KB (checked in by Chuck.Esterbrook, 2 years ago)

Reserved keyword "par" for parallel programming enhancements.

  • Property svn:eol-style set to native
Line 
1class KeywordSpecs
2    """
3    Specifies the keywords, their logical groups and documentation.
4   
5    The tokenizer obtains its list of keywords from this class.
6
7    Also, this information can be used for command line help and to generate documentation.
8    """
9
10    shared
11
12        var _keywords as List<of String>?
13
14        def keywords as List<of String>
15            if _keywords is nil, _keywords = .unpackKeywords(.rawSpecs)
16            return List<of String>(_keywords to !)
17
18        def unpackKeywords(specs as List<of String>) as List<of String>
19            """
20            Return a list of keyword names in no particular order.
21            """
22            keywords = List<of String>()
23            for spec in specs
24                i = spec.indexOf('|')
25                assert i > 0
26                name = spec[:i].trim
27                if name.endsWith('(r)')
28                    name = name[:-3].trim
29                keywords.add(name)
30            return keywords
31
32        var _groups as Dictionary<of String, List<of Keyword>>?
33
34        def groups as Dictionary<of String, List<of Keyword>>
35            if _groups is nil, _groups = .unpackGroups(.rawSpecs)
36            return _groups to !
37
38        def unpackGroups(specs as List<of String>) as Dictionary<of String, List<of Keyword>>
39            """
40            Return a dictionary of keyword groups.
41            """
42            groups = Dictionary<of String, List<of Keyword>>()
43            for spec in specs
44                parts = spec.trim.split(c'|')
45                assert parts.length >= 2
46                name = parts[0].trim
47                if name.endsWith('(r)')
48                    reservedForFutureUse = true
49                    name = name[:-3].trim
50                else
51                    reservedForFutureUse = false
52                for part in parts  # CC: parts[1:]
53                    i = part.indexOf(':')
54                    if i == -1, continue
55                    group = part[:i].trim
56                    description = part[i+1:].trim
57                    groups[group].add(Keyword(name, description, reservedForFutureUse))
58            return groups
59
60        get rawSpecs as List<of String>
61            # format:
62            #     word | explanation 1 | explanation 2 | ... | explanation N
63            # a 'word' can be suffixed with ' (r)' to indicate 'reserved'
64            # an 'explanation' is: group: text
65            # where 'group' is the group of keywords that the explanation belongs to
66            return [
67                'use         | module: Specify namespaces used in module.',
68                'import (r)  | module: From another Cobra module, import all the "use" clauses and declare the same namespace.',
69                'namespace   | declarative: Specify the namespace that subsequent declarations reside in.',
70                'enum        | declarative: Declare an enumeration type.',
71                'class       | declarative: Declare a class type.',
72                'inherits    | declarative: Specify inheritance for a class or interface. | operator: Test type inheritance.',
73                'implements  | declarative: Specify the interfaces that a class implements. | operator: Test interface implementation.',
74                'interface   | declarative: Declare an interface.',
75                'mixin       | declarative: Declare a mixin.',
76                'struct      | declarative: Declare a struct.',
77                'extend      | declarative: Declare extension methods on an existing type.',
78                'where       | declarative: Specify constraints on generic parameters. | expression: The filtering condition on a `for` expression.',
79                'must        | declarative: Specify constraints on generic parameters (`must be`).',
80                'be          | declarative: Specify constraints on generic parameters (`must be`).',
81                'callable    | declarative: Specify constraint that generic type argument must be callable/instantiable.',
82                'adds        | declarative: Specify mixins to add the type declaration.',
83                'cue         | declarative: Declare an object cue such as `cue init` or `cue hash`.',
84                'invariant   | declarative, contracts: Declare invariant conditions that are true on objects after any public call.',
85                'def         | declarative: Declare a method.',
86                'sig         | declarative: Declare a method signature.',
87                'as          | declarative: Declare the type for an argument, variable, method return, property, etc.',
88                'get         | declarative: Declare property reader/accessor. | expression: The evaluation result on a `for` expression.',
89                'set         | declarative: Declare property writer/mutator.',
90                'pro         | declarative: Declare a property.',
91                'var         | declarative: Declare a variable at the object or type level. Also, used as `from var` in property declarations. | expression: Refer to the variable that matches the containing property name.',
92                'const       | declarative: Declare a constant at the object or type level.',
93                'from        | declarative: Specify the backing variable for a property. Also, may be used for future LINQ syntax.',
94                'has         | declarative: Specify attributes to attach to the containing declaration.',
95                'body        | declarative: Declare the body of a method, indexer or property after blocked contracts or unit tests.',
96                'test        | declarative: Declare a unit test attached to the containing declaration.',
97                'shared      | declarative: Specify that a member is shared among all instances. (Called `static` in some languages.)',
98                'is          | declarative: Specify modifies on a member such as `override` and `shared`.',
99                'event       | declarative: Declare an event.',
100                'of          | declarative: Specify the underlying type of an enumeration. Also, specify type arguments to a generic type.',
101                'inlined (r) | declarative: ',
102                'abstract    | modifier: Specify that the member is abstract, e.g., without implementation.',
103                'extern      | modifier: Specify that a class is external to the Cobra code.',
104                'fake        | modifier: Specify that a class is external to the Cobra code. Deprecated 2008-10-03.',
105                'internal    | modifier: Specify that the member is visible within the entire assembly only.',
106                'new         | modifier: Specify that the member is a new member, distinct from the one in the base class with the same name.',
107                'nonvirtual  | modifier: Specify that the member cannot be overidden. NOT the default.',
108                'override    | modifier: Specify that the member is overriding the same member in an ancestor type.',
109                'partial     | modifier: Specify that the type implementation is split across declarations; usually across files.',
110                'public      | modifier: Specify that a type or member is visible to all. The default, unless a name starts with an underscore.',
111                'private     | modifier: Specify that the member is visible to this type only. The default for members starting with two underscores.',
112                'protected   | modifier: Specify that the member is visible to this type and all descendant types. The default for members starting with one underscore.',
113                'virtual     | modifier: Specify that the member can be overidden. On by default.',
114                'bool        | type: The Boolean data type.',
115                'char        | type: The (Unicode) character data type.',
116                'int         | type: The default integer data type; signed 32-bit. Alias for `int32`.',
117                'uint        | type: The unsigned integer data type; unsigned 32-bit. Alias for `uint32`.',
118                'decimal     | type: The default decimal data type for accurate, but slower, decimal point arithmetic.',
119                'float       | type: The floating point type, 64-bit, for less accurate, but faster decimal point arithmetic. Alias for `float64`.',
120                'dynamic     | type: The `dynamic` type for which all operations become late bound.`',
121                'same (r)    | type: The type indicating the same type as the current instance which will always be the same as the enclosing type or a descendant thereof.',
122                'number      | type: The numeric type which defaults to `decimal`. Via command line args or directives, can be set to a different decimal point type.',
123                'require     | contracts: Declare the preconditions of a method, property or indexer.',
124                'ensure      | contracts: Declare the postconditions of a method, property or indexer.',
125                'old         | contracts: Access the old, or original, value of an expression before the method executed.',
126                'implies     | contracts: Express a conditional in a contract.',
127                'assert      | statement: Assert that a condition is true, or throw an AssertException.',
128                'branch      | statement: Branch control against multiple choices. (Called `switch` in some languages.)',
129                'on          | statement: Used for `branch` and `trace` statements.',
130                'off         | statement: Used for `trace` statements.',
131                'expect      | statement: Expect and trap an exception, or throw an ExpectException.',
132                'if          | statement: The classic `if` statement. Execute statements if a condition is true.',
133                'else        | statement: The `else` portion of an `if-else` statement.',
134                'using       | statement: Use a resource and dispose it afterwards.',
135                'lock        | statement: Obtains a mutual-exclusion lock for a given object, executes the statement block and releases the lock.',
136                'while       | statement: The classic `while` statement. Execute statements while a condition is true.',
137                'post        | statement: The `post while` loop evaluates its expression after the statements execute.',
138                'for         | statement: Enumerate through objects or numbers.',
139                'break       | statement: Break out of the closest loop.',
140                'continue    | statement: Continue at the top of the closest loop.',
141                'try         | statement: Start an exception catch/trap boundary block.',
142                'catch       | statement: Catch/trap an exception type or all exceptions.',
143                'success     | statement: Act when catch/trap block succeeds with no exception.',
144                'finally     | statement: Act regardless of exception catch/trap success.',
145                'throw       | statement: Throw an exception.',
146                'pass        | statement: Placeholder for an empty block.',
147                'print       | statement: Print output.',
148                'stop        | statement: Stop the newline after a print.',
149                'trace       | statement: Emit trace output for debugging purposes.',
150                'return      | statement: Return a value from a method, property or indexer.',
151                'yield       | statement: Yield a value from a method, property or indexer.',
152                'listen      | statement: Listen to an event.',
153                'ignore      | statement: Stop listening to an event.',
154                'raise       | statement: Raise an event.',
155                'end (r)     | statement: For Python Server Pages (PSP) style "end syntax".',
156                'do          | expression: Start an anonymous method (aka "closure").',
157                'ref         | expression: Refer to a method without invoking it.',
158                'this        | expression: Reference to the current object/instance at run-time.',
159                'base        | expression: Reference to the base class.',
160                'to          | expression: Cast an expression to a type or throw InvalidCastException.',
161                'to\\?       | expression: Cast an expression to a type or evaluate to `nil`.',
162                'and         | expression: Logical "and". | contracts: "and ensure" to strengthen postconditions in an overriding method.',
163                'or          | expression: Logical "or". | contracts: "or require" to weaken preconditions in an overriding method.',
164                'not         | expression: Logical negation.',
165                'any         | expression: Evaluate to true if any element in a sequence is true.',
166                'every (r)   | expression:',
167                'all         | expression: Evaluate to true if all elements in a sequent is true.',
168                'each (r)    | expression:',
169                'in          | expression: Test inclusion | arg modifier: Value passed into method only (the default).',
170                "passthrough | expression: Psuedo-type used in typecasting in order to bypass the compiler's typechecking. Code pass through to the backend (C#, Java, whatever).",
171                'true        | expression: The Boolean value `true`.',
172                'false       | expression: The Boolean value `value`.',
173                'nil         | expression: The special value `nil`. Called `null`, `None` and `Nothing` in some languages.',
174                'vari        | arg modifier: Specify that the parameter captures variable number of arguments.',
175                'out         | arg modifier: Value returned/set by method, but not passed in.',
176                'inout       | arg modifier: Value passed in and returned/set by the method.',
177                'par (r)     | misc: Parallel programming.',
178                'objc (r)    | misc: For potential Objective-C integration.',
179                'except      | misc: Catch Python syntax for exceptions to give helpful error message.',
180            ]
181
182
183class Keyword
184    """
185    Used by KeywordSpecs.unpackGroups to capture the information about a keyword including
186    its name, description and whether or not it's reserved for future use.
187    """
188
189    var _name as String
190    var _description as String
191    var _reservedForFutureUse as bool
192   
193    cue init(name as String, description as String, reservedForFutureUse as bool)
194        base.init
195        _name = name
196        _description = description
197        _reservedForFutureUse = reservedForFutureUse
198
199    get name from var
200
201    get description from var
202
203    get reservedForFutureUse from var
Note: See TracBrowser for help on using the browser.