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" 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, +) 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, 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)