-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from uzmoi/dev
Dev
- Loading branch information
Showing
31 changed files
with
3,482 additions
and
4,768 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"version": "0.2", | ||
"useGitignore": true, | ||
"ignorePaths": ["package.json", "package-lock.json"], | ||
"words": [ | ||
"accum", | ||
"biomejs", | ||
"emnorst", | ||
"fuga", | ||
"hoge", | ||
"parsea", | ||
"parsimmon", | ||
"tsup", | ||
"uzmoi", | ||
"vitest" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import "vitest/importMeta"; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,27 @@ | ||
import { type Parser, choice, el, lazy, many, regex } from "../src"; | ||
import { type Parser, choice, el, lazy, many, parseA, regex } from "parsea"; | ||
|
||
export type SExpression = string | readonly SExpression[]; | ||
|
||
const list = lazy(() => SExpression) | ||
.apply(many) | ||
.between(el("("), el(")")); | ||
const list = lazy(() => SExpression.apply(many).between(el("("), el(")"))); | ||
|
||
export const SExpression: Parser<SExpression, string> = choice([ | ||
el("'") | ||
.option() | ||
.and(list) | ||
.map(([quote, list]) => (quote ? ["quote", ...list] : list)), | ||
el("'").then(list.map(list => ["quote", ...list])), | ||
list, | ||
regex(/"([^"\\]|\\.)*"/), | ||
regex(/[^\s()"]+/), | ||
]).between(regex(/\s*/)); | ||
|
||
if (import.meta.vitest) { | ||
const { test, expect } = import.meta.vitest; | ||
|
||
test("Hello world!", () => { | ||
expect(parseA(SExpression, '(print "Hello world!")')).toEqual([ | ||
"print", | ||
'"Hello world!"', | ||
]); | ||
}); | ||
|
||
test("quote list", () => { | ||
expect(parseA(SExpression, "'(1 2 3 4)")).toEqual(["quote", "1", "2", "3", "4"]); | ||
}); | ||
} |
Oops, something went wrong.