|
| 1 | +# MEP-001: Keywords, Operators, and Patterns |
| 2 | + |
| 3 | +## 1. Abstract |
| 4 | + |
| 5 | +This proposal specifies the reserved keywords, operators, punctuation, and common expression patterns for our markup language. It establishes clear rules for keyword usage, operator precedence, and syntax validation. Key updates include support for pipeline operations, enhanced string literal handling (with various quoting forms), conditional (ternary) expressions, membership and merge operators, and reserved functions like `File()` and `Git()`. |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## 2. Motivation |
| 10 | + |
| 11 | +- **Consistency and Clarity:** |
| 12 | + Defining keywords, operators, and punctuation prevents naming conflicts and ambiguous syntax, ensuring consistent parsing and predictable expression evaluation. |
| 13 | + |
| 14 | +- **Avoiding Conflicts:** |
| 15 | + Reserving critical language constructs (keywords, functions, and punctuation) stops users from unintentionally overwriting core elements, which could lead to errors. |
| 16 | + |
| 17 | +- **Enhanced Error Handling:** |
| 18 | + A well-defined syntax with reserved elements enables robust parsing and clear error messages, aiding debugging and future tooling integrations. |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +## 3. Specification |
| 23 | + |
| 24 | +### 3.1. Reserved Keywords |
| 25 | + |
| 26 | +The following identifiers are reserved and **cannot** be used as names for keys, tables, variables, or user-defined types: |
| 27 | + |
| 28 | +- **Logical and Boolean Keywords:** |
| 29 | + - `true`, `false`, `null`, `is`, `not`, `and`, `or` |
| 30 | +- **Control Flow Keywords:** |
| 31 | + - `if`, **`elif`**, `else`, `for`, `in` |
| 32 | +- **Directive Keywords:** |
| 33 | + - `include` |
| 34 | +- **Special Functions:** |
| 35 | + - `File()`, `Git()` |
| 36 | + |
| 37 | +#### Keyword Usage |
| 38 | +- Keywords must appear in the appropriate context (for example, `if` and `elif` in conditional expressions). |
| 39 | +- Using any of these reserved words as identifiers will result in a syntax error. |
| 40 | + |
| 41 | +--- |
| 42 | + |
| 43 | +### 3.2. Reserved Punctuations and Brackets |
| 44 | + |
| 45 | +#### 3.2.1. Reserved Punctuation Marks |
| 46 | + |
| 47 | +The following punctuation marks are reserved and **must not** be used as part of key names, variable names, or unquoted strings: |
| 48 | + |
| 49 | +- **Colon (`:`)** – For type annotations and key-value separation. |
| 50 | +- **Dot (`.`)** – For namespace access. |
| 51 | +- **Comma (`,`)** – As a separator in lists and inline tables. |
| 52 | +- **Equals Sign (`=`)** – For assignment in key-value pairs. |
| 53 | +- **Arrow (`->`)** – Reserved for potential functional expressions. |
| 54 | +- **Semicolon (`;`)** – Reserved for future extensions. |
| 55 | +- **Tilde (`~`)** – Used for load-time expressions. |
| 56 | +- **At Symbol (`@`)** – Global scope indicator. |
| 57 | +- **Dollar Sign (`$`)** – Context scope indicator. |
| 58 | +- **Percent Sign (`%`)** – Self (table-local) scope indicator. |
| 59 | +- **Less Than (`<`)** and **Greater Than (`>`)** – Used in comparisons. |
| 60 | +- **Exclamation Mark (`!`)** – For negation. |
| 61 | +- **Asterisk (`*`)** – For multiplication and comprehensions. |
| 62 | +- **Caret (`^`)** – Reserved for future use. |
| 63 | +- **Ampersand (`&`)** – Reserved for future use. |
| 64 | +- **Pipe (`|`)** – **Used as a pipeline operator** to chain operations. |
| 65 | +- **Forward Slash (`/`)** – In path strings and division. |
| 66 | +- **Backslash (`\`)** – As an escape character in strings. |
| 67 | + |
| 68 | +#### 3.2.2. Reserved Bracket Combinations |
| 69 | + |
| 70 | +All bracket types are reserved to ensure unambiguous syntax: |
| 71 | + |
| 72 | +- **Round Brackets (`()`)** – For grouping expressions and function calls. |
| 73 | +- **Square Brackets (`[]`)** – For defining lists and accessing array elements. |
| 74 | +- **Curly Braces (`{}`)** – For inline tables and dictionary-like structures. |
| 75 | +- **Angle Brackets (`<>`)** – Reserved for future use. |
| 76 | +- **Nested Bracket Combinations:** |
| 77 | + - Examples: `[{}]`, `{{}}`, `<(>)`, `([)])`, `<{>}` |
| 78 | + These are reserved to avoid ambiguity. |
| 79 | +- **F-String Brackets (`f"{...}"`)** – For formatted string interpolation. |
| 80 | + |
| 81 | +#### Punctuation Usage |
| 82 | +- Any use of reserved punctuation or bracket combinations outside their valid syntax context (or within unquoted identifiers) will raise a syntax error. |
| 83 | + |
| 84 | +--- |
| 85 | + |
| 86 | +### 3.3. String Quotation Rules |
| 87 | + |
| 88 | +Our markup language supports multiple string delimiters to handle both literal and interpolated content: |
| 89 | + |
| 90 | +- **Single Quotes (`'...'`):** |
| 91 | + Basic strings with no interpolation. |
| 92 | + ```toml |
| 93 | + greeting = 'Hello, World!' |
| 94 | + ``` |
| 95 | +- **Double Quotes (`"..."`):** |
| 96 | + Strings that support interpolation. |
| 97 | + ```toml |
| 98 | + welcome = "Hello, ${user.name}!" |
| 99 | + ``` |
| 100 | +- **Triple Single Quotes (`'''...'''`):** |
| 101 | + Multi-line literal strings. |
| 102 | + ```toml |
| 103 | + message = '''This is a |
| 104 | + multi-line string.''' |
| 105 | + ``` |
| 106 | +- **Triple Double Quotes (`"""..."""`):** |
| 107 | + Multi-line strings with interpolation. |
| 108 | + ```toml |
| 109 | + announcement = """Version: ${version} |
| 110 | + Released Today!""" |
| 111 | + ``` |
| 112 | +- **Backticks (`` `...` ``):** |
| 113 | + Raw strings where no escaping is performed. |
| 114 | + ```toml |
| 115 | + path = `C:\Users\Name` |
| 116 | + ``` |
| 117 | +- **F-Strings (`f"..."`):** |
| 118 | + For formatted strings with inline variable interpolation. |
| 119 | + ```toml |
| 120 | + configPath = f"${base}/config.toml" |
| 121 | + ``` |
| 122 | + |
| 123 | +#### String Quotation Guidelines |
| 124 | +- Mixing different string delimiters in one literal is not allowed. |
| 125 | +- Unescaped or mismatched quotes within a string will trigger a syntax error. |
| 126 | + |
| 127 | +--- |
| 128 | + |
| 129 | +### 3.4. Supported Operators |
| 130 | + |
| 131 | +#### 3.4.1. Arithmetic Operators |
| 132 | +- **Addition:** `+` |
| 133 | +- **Subtraction:** `-` |
| 134 | +- **Multiplication:** `*` |
| 135 | +- **Division:** `/` |
| 136 | +- **Modulo:** `%` |
| 137 | +- **Exponentiation:** `**` |
| 138 | + |
| 139 | +#### 3.4.2. Comparison Operators |
| 140 | +- **Equal to:** `==` |
| 141 | +- **Not equal to:** `!=` |
| 142 | +- **Greater than:** `>` |
| 143 | +- **Less than:** `<` |
| 144 | +- **Greater than or equal to:** `>=` |
| 145 | +- **Less than or equal to:** `<=` |
| 146 | +- **Identity:** `is` |
| 147 | + |
| 148 | +#### 3.4.3. Logical Operators |
| 149 | +- **Logical AND:** `and` |
| 150 | +- **Logical OR:** `or` |
| 151 | +- **Logical NOT:** `not` |
| 152 | + |
| 153 | +#### 3.4.4. Pipeline Operator |
| 154 | +- Chains operations together in a readable sequence: |
| 155 | + ```toml |
| 156 | + result = ~( data | transform | filter ) |
| 157 | + ``` |
| 158 | + |
| 159 | +#### 3.4.5. Conditional (Ternary) Operator |
| 160 | +- Allows inline conditional expressions: |
| 161 | + ```toml |
| 162 | + status = ~( "Active" if is_active else "Inactive" ) |
| 163 | + ``` |
| 164 | + |
| 165 | +#### 3.4.6. String Concatenation and Interpolation |
| 166 | +- **Concatenation:** Using the `+` operator. |
| 167 | +- **Interpolation:** Via f-string syntax: |
| 168 | + ```toml |
| 169 | + full_path = f"${base}/docs" |
| 170 | + ``` |
| 171 | + |
| 172 | +#### 3.4.7. Membership Operators |
| 173 | +- **Membership:** `in` |
| 174 | +- **Non-membership:** `not in` |
| 175 | + |
| 176 | +#### 3.4.8. Merge Operator |
| 177 | +- Used for table or inline table merging: |
| 178 | + ```toml |
| 179 | + [production] |
| 180 | + << = default_config |
| 181 | + ``` |
| 182 | + |
| 183 | +--- |
| 184 | + |
| 185 | +### 3.5. Error Handling |
| 186 | + |
| 187 | +- **Syntax Errors:** |
| 188 | + - Reserved keywords or punctuation misused as identifiers will result in a syntax error. |
| 189 | + - Incorrect use of reserved functions (`File()`, `Git()`) or keywords (such as using `if` or `elif` as variable names) is not permitted. |
| 190 | +- **Bracket Errors:** |
| 191 | + - Unmatched, incorrectly nested, or ambiguous bracket combinations will trigger an error. |
| 192 | +- **Invalid Punctuation:** |
| 193 | + - Reserved punctuation appearing outside of its valid syntax (or within unquoted keys/identifiers) will raise a clear error. |
| 194 | +- **String Delimiter Errors:** |
| 195 | + - Mismatched or unescaped quotes in strings will cause a syntax error. |
| 196 | + |
| 197 | +--- |
| 198 | + |
| 199 | +## 4. Examples |
| 200 | + |
| 201 | +### Example 1: Pipeline Operation |
| 202 | + |
| 203 | +```toml |
| 204 | +[processing] |
| 205 | +output = ~( data | sanitize | format ) |
| 206 | +``` |
| 207 | + |
| 208 | +### Example 2: Valid Use of Reserved Keywords and Conditional Expression |
| 209 | + |
| 210 | +```toml |
| 211 | +[config] |
| 212 | +is_active = true |
| 213 | +status = ~( "Running" if is_active else "Stopped" ) |
| 214 | +``` |
| 215 | + |
| 216 | +### Example 3: Reserved Function Usage |
| 217 | + |
| 218 | +```toml |
| 219 | +[dependencies] |
| 220 | +source = File("requirements.txt") |
| 221 | +version = Git("https://repo.git", tag="v1.0") |
| 222 | +``` |
| 223 | + |
| 224 | +### Example 4: Membership and Merge Operators |
| 225 | + |
| 226 | +```toml |
| 227 | +[settings] |
| 228 | +allowed = ~( "admin" in user.roles ) |
| 229 | +merged_config = default << user_override |
| 230 | +``` |
| 231 | + |
| 232 | +### Example 5: Invalid Use of Reserved Punctuation |
| 233 | + |
| 234 | +```toml |
| 235 | +[invalid] |
| 236 | +some:key = "value" # Syntax error: Colon used incorrectly in key name |
| 237 | +``` |
| 238 | + |
| 239 | +### Example 6: Invalid Use of Reserved Keyword |
| 240 | + |
| 241 | +```toml |
| 242 | +[config] |
| 243 | +if = "condition" # Syntax error: 'if' is a reserved keyword |
| 244 | +``` |
| 245 | + |
| 246 | +--- |
| 247 | + |
| 248 | +## 5. Open Issues |
| 249 | + |
| 250 | +- **Future Reserved Symbols:** |
| 251 | + Evaluate whether symbols such as `^`, `&`, or certain bracket combinations should have dedicated functionality. |
| 252 | +- **Keyword Expansion:** |
| 253 | + Consider if additional keywords (e.g., `match`) need to be reserved as language features evolve. |
| 254 | +- **Operator Overloading:** |
| 255 | + Determine if custom operator definitions for user-defined types are desirable. |
| 256 | +- **Pipeline Syntax Complexity:** |
| 257 | + Investigate supporting more complex chaining scenarios or error reporting for pipelines. |
| 258 | + |
| 259 | +--- |
| 260 | + |
| 261 | +## 6. Conclusion |
| 262 | + |
| 263 | +MEP-001 clearly defines the reserved keywords, operators, punctuation, and syntax patterns for our markup language. By reserving key elements such as control flow keywords (including `elif`), special functions (`File()`, `Git()`), and specific punctuation and bracket combinations, the specification prevents naming conflicts and ambiguity. Enhanced support for pipelines, conditional expressions, membership tests, and string handling ensures that the language remains both expressive and robust. Feedback is encouraged as we continue refining these rules and explore future language enhancements. |
0 commit comments