kopscript 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LLM.md CHANGED
@@ -201,6 +201,11 @@ $"Hello {name}, you are {age} years old" // interpolated string
201
201
  r"^[a-z]+$" // regex literal (only meaningful as a match pattern)
202
202
  ```
203
203
 
204
+ A regex literal's contents pass to the real `RegExp` unprocessed — `\s`, `\d`, `\w`, `\.`,
205
+ etc. all mean real regex syntax, not string escapes (only `\"` is special, letting a
206
+ literal `"` appear before the closing quote). This differs from every other string-like
207
+ literal in the language, which do interpret `\n`/`\t`/`\\`/etc.
208
+
204
209
  ### Lambdas
205
210
 
206
211
  ```ks
package/dist/checker.js CHANGED
@@ -856,6 +856,15 @@ export class Checker {
856
856
  this.checkBlock(decl.body, scope, { returnType, currentClass: null, inConstructor: false, loopDepth: 0, isAsync: decl.isAsync });
857
857
  }
858
858
  checkClassBody(decl) {
859
+ // Constructor/method *bodies* run in this same scope registerClass used
860
+ // for the *signatures* (see withTypeParamInScope) — without it, `T`
861
+ // resolves everywhere in a generic class's declared field/param/return
862
+ // types but not inside a method body itself (a local `T x = ...;`, or a
863
+ // lambda parameter typed `T`), which would make the type parameter
864
+ // usable only at the class's boundary and not inside its own logic.
865
+ this.withTypeParamInScope(decl.typeParam, () => this.checkClassBodyInner(decl));
866
+ }
867
+ checkClassBodyInner(decl) {
859
868
  const info = this.classes.get(decl.name);
860
869
  if (decl.constructor) {
861
870
  const paramScope = new Scope();
package/dist/lexer.js CHANGED
@@ -133,12 +133,27 @@ export class Lexer {
133
133
  }
134
134
  return this.make(TokenKind.InterpolatedString, raw, line, col);
135
135
  }
136
+ // Deliberately its own reader, not `readStringChar` — a regex literal's
137
+ // backslash escapes (`\s`, `\d`, `\.`, ...) are regex syntax, meant to
138
+ // reach the real `RegExp` constructor unchanged, not string escapes to be
139
+ // interpreted here. `readStringChar` turns any unrecognized `\x` into a
140
+ // bare `x` (dropping the backslash), which silently corrupts almost every
141
+ // realistic pattern. Only `\"` gets special handling, so a literal quote
142
+ // can appear inside a pattern without ending the literal early; every
143
+ // other `\` + character (including `\\` itself) passes through verbatim.
136
144
  readRegexLiteral(line, col) {
137
145
  this.advance(); // 'r'
138
146
  this.advance(); // opening quote
139
147
  let value = "";
140
148
  while (!this.isAtEnd() && this.peek() !== '"') {
141
- value += this.readStringChar();
149
+ const c = this.advance();
150
+ if (c === "\\" && !this.isAtEnd()) {
151
+ const next = this.advance();
152
+ value += next === '"' ? '"' : "\\" + next;
153
+ }
154
+ else {
155
+ value += c;
156
+ }
142
157
  }
143
158
  if (this.isAtEnd()) {
144
159
  this.diagnostics.error("Unterminated regex literal", line, col);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kopscript",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "KopScript: a small OOP, strongly-typed language that transpiles to JavaScript, with generics and nullable types",
5
5
  "type": "module",
6
6
  "license": "MIT",