From 1a62ab26f5fa45967198e1df033803b9a368afea Mon Sep 17 00:00:00 2001 From: Matt Kantor Date: Mon, 13 Jan 2025 07:58:58 -0500 Subject: [PATCH 1/4] Update prettier configuration --- .prettierrc.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.prettierrc.json b/.prettierrc.json index 17fcae0..4e7918d 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,5 +1,6 @@ { "arrowParens": "avoid", + "proseWrap": "always", "semi": false, "singleQuote": true, "trailingComma": "all" From 9dfcf929698d2f54aee84856dd74c5472048e44e Mon Sep 17 00:00:00 2001 From: Matt Kantor Date: Mon, 13 Jan 2025 10:26:58 -0500 Subject: [PATCH 2/4] Export a few more things from semantics barrel file --- src/language/semantics.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/language/semantics.ts b/src/language/semantics.ts index 3eac406..040093c 100644 --- a/src/language/semantics.ts +++ b/src/language/semantics.ts @@ -61,6 +61,8 @@ export { applyKeyPathToSemanticGraph, containsAnyUnelaboratedNodes, isSemanticGraph, + isUnelaborated, + matchSemanticGraph, serialize, stringifySemanticGraphForEndUser, updateValueAtKeyPathInSemanticGraph, From d1b53342fa84df62ce9d249f6aa4b95191b02365 Mon Sep 17 00:00:00 2001 From: Matt Kantor Date: Wed, 18 Dec 2024 11:47:25 -0500 Subject: [PATCH 3/4] Make handleObjectNodeWhichMayBeAExpression slightly more correct --- src/language/semantics/expression-elaboration.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/language/semantics/expression-elaboration.ts b/src/language/semantics/expression-elaboration.ts index 1214f29..1a54147 100644 --- a/src/language/semantics/expression-elaboration.ts +++ b/src/language/semantics/expression-elaboration.ts @@ -161,7 +161,10 @@ const handleObjectNodeWhichMayBeAExpression = ( const { 0: possibleKeyword, ...possibleArguments } = node return isKeyword(possibleKeyword) ? context.keywordHandlers[possibleKeyword]( - makeObjectNode({ ...possibleArguments, 0: possibleKeyword }), + makeUnelaboratedObjectNode({ + ...possibleArguments, + 0: possibleKeyword, + }), context, ) : /^@[^@]/.test(possibleKeyword) From 4152d27f42db6554a0042d54c96c4a8b2b4d1f7e Mon Sep 17 00:00:00 2001 From: Matt Kantor Date: Thu, 30 Jan 2025 16:21:29 -0500 Subject: [PATCH 4/4] Simplify atom parsers --- README.md | 2 +- src/language/parsing/atom.ts | 49 ++++++++++++++++++------------------ 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 8bd5952..f199d68 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ data representation implied by the fact that a value is an atom (e.g. the atom `2` may be an integer in memory). Bare words not containing any -[reserved character sequences](./src/language/parsing/atom.ts#L54-L76) are +[reserved character sequences](./src/language/parsing/atom.ts#L32-L54) are atoms: ``` diff --git a/src/language/parsing/atom.ts b/src/language/parsing/atom.ts index aa8dc02..c2c195e 100644 --- a/src/language/parsing/atom.ts +++ b/src/language/parsing/atom.ts @@ -22,32 +22,10 @@ export const isAtom = (value: unknown): value is Atom => export const unit = '' as const export const atomParser: Parser = optionallySurroundedByParentheses( - lazy(() => oneOf([quotedAtom, unquotedAtom])), + lazy(() => oneOf([unquotedAtomParser, quotedAtomParser])), ) -const quotedAtom = map( - sequence([ - as(literal('"'), ''), - map( - zeroOrMore( - oneOf([ - butNot( - anySingleCharacter, - oneOf([literal('"'), literal('\\')]), - '`"` or `\\`', - ), - as(literal('\\"'), '"'), - as(literal('\\\\'), '\\'), - ]), - ), - output => output.join(''), - ), - as(literal('"'), ''), - ]), - ([_1, contents, _2]) => contents, -) - -const unquotedAtom = map( +export const unquotedAtomParser = map( oneOrMore( butNot( anySingleCharacter, @@ -80,4 +58,25 @@ const unquotedAtom = map( characters => characters.join(''), ) -export { unquotedAtom as unquotedAtomParser } +const quotedAtomParser = map( + sequence([ + literal('"'), + map( + zeroOrMore( + oneOf([ + // `"` and `\` need to be escaped + butNot( + anySingleCharacter, + oneOf([literal('"'), literal('\\')]), + '`"` or `\\`', + ), + as(literal('\\"'), '"'), + as(literal('\\\\'), '\\'), + ]), + ), + output => output.join(''), + ), + literal('"'), + ]), + ([_1, contents, _2]) => contents, +)