Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"arrowParens": "avoid",
"proseWrap": "always",
"semi": false,
"singleQuote": true,
"trailingComma": "all"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

```
Expand Down
49 changes: 24 additions & 25 deletions src/language/parsing/atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,10 @@ export const isAtom = (value: unknown): value is Atom =>
export const unit = '' as const

export const atomParser: Parser<Atom> = 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,
Expand Down Expand Up @@ -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,
)
2 changes: 2 additions & 0 deletions src/language/semantics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export {
applyKeyPathToSemanticGraph,
containsAnyUnelaboratedNodes,
isSemanticGraph,
isUnelaborated,
matchSemanticGraph,
serialize,
stringifySemanticGraphForEndUser,
updateValueAtKeyPathInSemanticGraph,
Expand Down
5 changes: 4 additions & 1 deletion src/language/semantics/expression-elaboration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down