From f5642473c8c406f4fbcc9a706e777613d8eeab31 Mon Sep 17 00:00:00 2001 From: "Robert J. Simmons" <442315+robsimmons@users.noreply.github.com> Date: Sun, 24 Nov 2024 15:11:24 -0500 Subject: [PATCH] Allow single-quotes in variable names (#72) --- src/client.test.ts | 4 +++- src/language/dusa-tokenizer.ts | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/client.test.ts b/src/client.test.ts index 5060511..85e4b85 100644 --- a/src/client.test.ts +++ b/src/client.test.ts @@ -32,6 +32,8 @@ test('Basic operation', () => { expect(dusa.solution?.get('a')).toStrictEqual({ name: 'tt' }); dusa.assert({ name: 'a', value: 'ff' }); expect(dusa.solution).toBeNull(); + + expect(() => new Dusa("a is '.")).toThrow(); }); test('Exhaustive choices', () => { @@ -166,6 +168,6 @@ test('Builtin STRING_CONCAT, full reverse', () => { test('Builtin INT_MINUS (issue #29)', () => { expect( - solutions(new Dusa('#builtin INT_MINUS minus.\ny 4.\nx N :- y M, minus N 1 is M.'), 'x'), + solutions(new Dusa("#builtin INT_MINUS minus.\ny 4.\nx N :- y N', minus N 1 is N'."), 'x'), ).toStrictEqual(['x 5']); }); diff --git a/src/language/dusa-tokenizer.ts b/src/language/dusa-tokenizer.ts index 5939304..6df3be0 100644 --- a/src/language/dusa-tokenizer.ts +++ b/src/language/dusa-tokenizer.ts @@ -48,11 +48,11 @@ export type Token = export type ParserState = StateRoot; -const META_ID_TOKEN = /^[A-Za-z_][A-Za-z0-9_]*/; +const META_ID_TOKEN = /^[A-Za-z_][A-Za-z0-9_']*/; const META_NUM_TOKEN = /^[+-]?[0-9][A-Za-z0-9_]*/; const CONST_TOKEN = /^[a-z][a-zA-Z0-9_]*$/; -const WILDCARD_TOKEN = /^_[a-zA-Z0-9_]*$/; -const VAR_TOKEN = /^[A-Z][a-zA-Z0-9_]*$/; +const WILDCARD_TOKEN = /^_[a-zA-Z0-9_']*$/; +const VAR_TOKEN = /^[A-Z][a-zA-Z0-9_']*$/; const INT_TOKEN = /^-?(0|[1-9][0-9]*)$/; const TRIV_TOKEN = /^\(\)/;