@nachoggodino/cello 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BYLAWS.md +446 -0
- package/CHANGELOG.md +11 -0
- package/LICENSE +12 -0
- package/README.md +211 -0
- package/dist/cli/cli.d.ts +16 -0
- package/dist/cli/cli.js +360 -0
- package/dist/cli/serve.d.ts +15 -0
- package/dist/cli/serve.js +226 -0
- package/dist/evaluator/evaluate.d.ts +2 -0
- package/dist/evaluator/evaluate.js +129 -0
- package/dist/evaluator/formula.d.ts +13 -0
- package/dist/evaluator/formula.js +141 -0
- package/dist/formatter/format.d.ts +1 -0
- package/dist/formatter/format.js +112 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +6 -0
- package/dist/parser/parse.d.ts +2 -0
- package/dist/parser/parse.js +552 -0
- package/dist/renderer/render.d.ts +2 -0
- package/dist/renderer/render.js +295 -0
- package/dist/serializer/serialize.d.ts +2 -0
- package/dist/serializer/serialize.js +104 -0
- package/dist/shared/types.d.ts +88 -0
- package/dist/shared/types.js +1 -0
- package/dist/shared/utils.d.ts +16 -0
- package/dist/shared/utils.js +142 -0
- package/dist/validator/validate.d.ts +8 -0
- package/dist/validator/validate.js +10 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +1 -0
- package/docs/ARCHITECTURE.md +43 -0
- package/docs/CLI.md +58 -0
- package/docs/COMPLIANCE.md +82 -0
- package/docs/ERROR_MODEL.md +25 -0
- package/docs/FORMULA_SUPPORT.md +33 -0
- package/docs/SPEC.md +723 -0
- package/docs/SYNTAX_HIGHLIGHTING.md +91 -0
- package/examples/advanced_kpi.cel +42 -0
- package/examples/basic.cel +8 -0
- package/examples/feature_showcase.cel +37 -0
- package/package.json +96 -0
- package/syntaxes/cel.language-configuration.json +31 -0
- package/syntaxes/cel.tmLanguage.json +250 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Architecture
|
|
2
|
+
|
|
3
|
+
## Pipeline
|
|
4
|
+
|
|
5
|
+
1. `parse(text)` -> AST
|
|
6
|
+
2. `evaluate(ast)` -> AST with computed formula values when possible
|
|
7
|
+
3. `render(text|ast)` -> self-contained HTML
|
|
8
|
+
4. `serialize(ast)` -> `.cel` text
|
|
9
|
+
|
|
10
|
+
## Main modules
|
|
11
|
+
|
|
12
|
+
- `src/parser/parse.ts`
|
|
13
|
+
- Parses workbook/sheets/rows/cells
|
|
14
|
+
- Handles `@sheet`, `@header`, `@defaults`, rows, row modifiers, merges, external sheet source (`-> path`), formats (`csv/tsv/excel/markdown/json`)
|
|
15
|
+
- Emits parser diagnostics
|
|
16
|
+
|
|
17
|
+
- `src/evaluator/evaluate.ts`
|
|
18
|
+
- Deep-clones AST
|
|
19
|
+
- Skips HyperFormula loading when the workbook contains no formulas
|
|
20
|
+
- Builds per-sheet matrix for HyperFormula
|
|
21
|
+
- Translates supported named references to A1 ranges before engine evaluation
|
|
22
|
+
- Evaluates formula cells and writes `computed`
|
|
23
|
+
- Emits diagnostics on evaluation failures
|
|
24
|
+
|
|
25
|
+
- `src/renderer/render.ts`
|
|
26
|
+
- Parses text input, including external sheet sources through `baseDir`
|
|
27
|
+
- Evaluates by default, with `evaluate: false` available for raw formula previews
|
|
28
|
+
- Generates HTML tabs + tables
|
|
29
|
+
- Applies inline formatting and style modifiers (`bold`, `italic`, `bg`, color)
|
|
30
|
+
|
|
31
|
+
- `src/serializer/serialize.ts`
|
|
32
|
+
- Converts AST back to `.cel` text for roundtrip workflows
|
|
33
|
+
|
|
34
|
+
- `src/cli/serve.ts`
|
|
35
|
+
- Serves a rendered workbook over local HTTP
|
|
36
|
+
- Caches rendered HTML and refreshes it when the source file changes
|
|
37
|
+
- Injects a small live-reload script for browser previews
|
|
38
|
+
|
|
39
|
+
## Design notes
|
|
40
|
+
|
|
41
|
+
- BYLAWS-first behavior is normative for syntax decisions.
|
|
42
|
+
- Named-reference translation is intentionally narrow: named columns and `!!` alias supported.
|
|
43
|
+
- Parsing is permissive by design; unknown constructs tend to degrade to text/diagnostics.
|
package/docs/CLI.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# CLI Reference
|
|
2
|
+
|
|
3
|
+
The package exposes a `cello` CLI binary from `dist/cli/cli.js`.
|
|
4
|
+
|
|
5
|
+
## Commands
|
|
6
|
+
|
|
7
|
+
- `cello parse <file.cel>`
|
|
8
|
+
- Prints parsed AST as JSON.
|
|
9
|
+
|
|
10
|
+
- `cello --version`
|
|
11
|
+
- Prints the package version.
|
|
12
|
+
|
|
13
|
+
- `cello evaluate <file.cel>`
|
|
14
|
+
- Parses and evaluates formulas, prints resulting AST as JSON.
|
|
15
|
+
|
|
16
|
+
- `cello format <file.cel> [--check] [-o out.cel]`
|
|
17
|
+
- Pretty-prints native Cello pipe tables with padded cells.
|
|
18
|
+
- Rewrites the input file in place by default.
|
|
19
|
+
- `-o` / `--out` writes formatted output to another path instead.
|
|
20
|
+
- `--check` exits `0` when the file is already formatted and `1` when formatting would change it.
|
|
21
|
+
|
|
22
|
+
- `cello validate <file.cel>`
|
|
23
|
+
- Parses and evaluates workbook diagnostics.
|
|
24
|
+
- Prints `{ "valid": boolean, "diagnostics": [...] }` as JSON.
|
|
25
|
+
- Exits `0` when there are no diagnostics, otherwise exits `1`.
|
|
26
|
+
|
|
27
|
+
- `cello render <file.cel> [-o out.html] [--no-eval] [--format document|fragment]`
|
|
28
|
+
- Renders workbook to self-contained HTML.
|
|
29
|
+
- `--format document` is the default full HTML document.
|
|
30
|
+
- `--format fragment` emits an embeddable chunk without `html`, `head`, or `body` wrappers.
|
|
31
|
+
- Use `--no-eval` to render formula text without evaluating formulas.
|
|
32
|
+
- If `-o/--out` is provided, writes to file and prints `Wrote <absolute-path>`.
|
|
33
|
+
- Otherwise prints HTML to stdout.
|
|
34
|
+
|
|
35
|
+
- `cello serialize <file.cel> [-o out.cel]`
|
|
36
|
+
- Parses and serializes AST back to `.cel`.
|
|
37
|
+
- If `-o/--out` is provided, writes to file and prints `Wrote <absolute-path>`.
|
|
38
|
+
- Otherwise prints to stdout.
|
|
39
|
+
|
|
40
|
+
- `cello serve <file.cel> [--port 4321] [--host 127.0.0.1] [--open] [--no-eval]`
|
|
41
|
+
- Serves a live HTML preview for a workbook.
|
|
42
|
+
- Prints a local URL containing the served file name.
|
|
43
|
+
- Auto-reloads the browser view when the source file changes.
|
|
44
|
+
- Keeps the process warm so repeated renders reuse loaded dependencies.
|
|
45
|
+
- Does not open a browser unless `--open` is provided.
|
|
46
|
+
|
|
47
|
+
- `cello help [command]`
|
|
48
|
+
- Prints basic CLI help, or command-specific help for `parse`, `evaluate`, `format`, `validate`, `render`, `serialize`, or `serve`.
|
|
49
|
+
|
|
50
|
+
## Exit codes
|
|
51
|
+
|
|
52
|
+
- `0`: success
|
|
53
|
+
- `1`: invalid arguments, validation diagnostics, or runtime failure
|
|
54
|
+
|
|
55
|
+
## Build/run notes
|
|
56
|
+
|
|
57
|
+
- Build first: `npm run build`
|
|
58
|
+
- Direct run example: `node dist/cli/cli.js render examples/basic.cel -o out.html`
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Compliance Matrix (BYLAWS vs Current Code)
|
|
2
|
+
|
|
3
|
+
This file maps `BYLAWS.md` expectations to current implementation in `src/` and tests in `tests/`.
|
|
4
|
+
|
|
5
|
+
Status legend:
|
|
6
|
+
- `implemented`: behavior present and tested
|
|
7
|
+
- `partial`: behavior exists but scope/guarantees limited
|
|
8
|
+
- `missing`: documented behavior not in code yet
|
|
9
|
+
|
|
10
|
+
## Matrix
|
|
11
|
+
|
|
12
|
+
1. Core file structure (`@sheet`, anonymous fallback)
|
|
13
|
+
- Status: `implemented`
|
|
14
|
+
- Code: `src/parser/parse.ts` (`ensureSheet`, sheet declaration parsing)
|
|
15
|
+
- Tests: `tests/unit/parser/parse.unit.test.ts`, `tests/e2e/fixtures/anonymous-sheet.*`
|
|
16
|
+
|
|
17
|
+
2. Sheet formats (`csv/tsv/excel`, custom delimiter, markdown, json)
|
|
18
|
+
- Status: `implemented`
|
|
19
|
+
- Code: `src/shared/utils.ts` (`parseSheetFormat`), `src/parser/parse.ts` format handlers
|
|
20
|
+
- Tests: `tests/unit/parser/parse.unit.test.ts`, `tests/e2e/fixtures/format-matrix.*`
|
|
21
|
+
|
|
22
|
+
3. External sheet source (`-> path`)
|
|
23
|
+
- Status: `implemented`
|
|
24
|
+
- Code: `src/parser/parse.ts` (`tryHandleExternalSource`)
|
|
25
|
+
- Tests: `tests/unit/parser/parse.unit.test.ts`, `tests/e2e/fixtures/external-source.*`
|
|
26
|
+
|
|
27
|
+
4. Rows, blank-line handling, row-level modifiers
|
|
28
|
+
- Status: `implemented`
|
|
29
|
+
- Code: `src/parser/parse.ts` (`splitNativeRow`, blank line handling)
|
|
30
|
+
- Tests: `tests/unit/parser/parse.unit.test.ts`, `tests/e2e/fixtures/comments-blanklines.*`
|
|
31
|
+
|
|
32
|
+
5. Header rows and column metadata/modifiers
|
|
33
|
+
- Status: `implemented`
|
|
34
|
+
- Code: `src/parser/parse.ts` (`parseHeadersFromLine`, `applyHeadersToColumns`)
|
|
35
|
+
- Tests: `tests/unit/parser/parse.unit.test.ts`, `tests/e2e/fixtures/header-rebinding.*`
|
|
36
|
+
|
|
37
|
+
5a. Column default formulas (`@defaults | ... |`)
|
|
38
|
+
- Status: `implemented`
|
|
39
|
+
- Code: `src/parser/parse.ts` (`tryHandleDefaultsDirective`, `getColumnDefaultFormula`)
|
|
40
|
+
- Tests: `tests/unit/parser/parse.unit.test.ts`, `tests/it/evaluator/evaluate.test.ts`, `tests/it/renderer/render.test.ts`
|
|
41
|
+
|
|
42
|
+
6. Formula parsing + evaluation engine integration
|
|
43
|
+
- Status: `implemented`
|
|
44
|
+
- Code: `src/evaluator/evaluate.ts`
|
|
45
|
+
- Tests: `tests/unit/evaluator/evaluate.unit.test.ts`, `tests/it/evaluator/evaluate.test.ts`
|
|
46
|
+
|
|
47
|
+
7. Named column refs (`SUM(Price)`, `SUM(Sheet!Price)`, slices, `!!`)
|
|
48
|
+
- Status: `implemented`
|
|
49
|
+
- Code: `src/evaluator/formula.ts`
|
|
50
|
+
- Tests: `tests/unit/evaluator/formula.unit.test.ts`
|
|
51
|
+
|
|
52
|
+
8. Row-name dot refs (`Sheet!row_name.Column`)
|
|
53
|
+
- Status: `out of scope`
|
|
54
|
+
- Code: row-name prefixes are not part of the AST or formula translation layer
|
|
55
|
+
- Tests: parser regression covers unsupported row prefixes
|
|
56
|
+
|
|
57
|
+
9. Merges (`<`, `^`)
|
|
58
|
+
- Status: `partial`
|
|
59
|
+
- Code: `src/parser/parse.ts` merge token handling
|
|
60
|
+
- Tests: `tests/unit/parser/parse.unit.test.ts`, `tests/it/renderer/render.test.ts`
|
|
61
|
+
- Note: orphan merge tokens degrade silently (no diagnostic)
|
|
62
|
+
|
|
63
|
+
10. Modifiers precedence (column + row + cell)
|
|
64
|
+
- Status: `implemented`
|
|
65
|
+
- Code: `src/renderer/render.ts` (`collectModifiers` order: column -> row -> cell)
|
|
66
|
+
- Tests: `tests/e2e/fixtures/types-precedence.*`, `tests/e2e/fixtures/row-name-modifiers.*`
|
|
67
|
+
|
|
68
|
+
11. Modifier coverage in renderer
|
|
69
|
+
- Status: `partial`
|
|
70
|
+
- Code: `src/renderer/render.ts` (`bold`, `italic`, `bg`, color, tone presets, numeric display)
|
|
71
|
+
- Missing: `[hidden]` rendering behavior
|
|
72
|
+
|
|
73
|
+
12. Inline formatting (`*`, `_`, `~~`, `#`, `##`)
|
|
74
|
+
- Status: `implemented`
|
|
75
|
+
- Code: `src/renderer/render.ts` (`formatInline`)
|
|
76
|
+
- Tests: `tests/it/renderer/render.test.ts`, `tests/e2e/fixtures/native-bylaws.*`
|
|
77
|
+
|
|
78
|
+
13. Diagnostics and strict mode
|
|
79
|
+
- Status: `implemented`
|
|
80
|
+
- Code: `src/parser/parse.ts`, `src/evaluator/evaluate.ts`, `src/renderer/render.ts`
|
|
81
|
+
- Tests: parser/evaluator unit + integration tests
|
|
82
|
+
- Note: parser strict mode throws on `error` diagnostics only; warnings do not throw
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Error Model
|
|
2
|
+
|
|
3
|
+
## Parse stage
|
|
4
|
+
|
|
5
|
+
- Non-row lines in native Cello sheets are skipped with `warning` diagnostics.
|
|
6
|
+
- Invalid JSON sheets degrade to a single text data row plus warning.
|
|
7
|
+
- Parser strict mode (`parse(..., { strict: true })`) throws only on parser `error` diagnostics (warnings do not throw).
|
|
8
|
+
|
|
9
|
+
## Evaluate stage
|
|
10
|
+
|
|
11
|
+
- If HyperFormula is missing, evaluation is skipped and a warning diagnostic is added.
|
|
12
|
+
- If HyperFormula throws on workbook evaluation, evaluator adds an `error` diagnostic.
|
|
13
|
+
- `evaluate(..., { strict: true })` rethrows evaluation errors.
|
|
14
|
+
|
|
15
|
+
## Render stage
|
|
16
|
+
|
|
17
|
+
- `render(text, { strict })` delegates to parser/evaluator strictness.
|
|
18
|
+
- `render(text, { evaluate: false })` skips evaluation and renders formula text.
|
|
19
|
+
- Non-strict render still returns HTML even when diagnostics exist.
|
|
20
|
+
- Strict render throws only when parse/evaluate throw; non-fatal diagnostics alone do not throw.
|
|
21
|
+
|
|
22
|
+
## Practical contract
|
|
23
|
+
|
|
24
|
+
- `diagnostics` are the canonical error/warning channel in non-strict mode.
|
|
25
|
+
- Strict mode is for CI/validation workflows where failure must be explicit.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Formula Support (Current State)
|
|
2
|
+
|
|
3
|
+
## What works now
|
|
4
|
+
|
|
5
|
+
- Formula cells detected when value starts with `=`.
|
|
6
|
+
- Evaluation uses HyperFormula when dependency available.
|
|
7
|
+
- A1 references pass through unchanged.
|
|
8
|
+
- Named column translation supported before engine eval:
|
|
9
|
+
- `SUM(Name)`
|
|
10
|
+
- `SUM(Name[n:m])`
|
|
11
|
+
- `SUM(Sheet!Name)`
|
|
12
|
+
- `SUM(Sheet!Name[n:m])`
|
|
13
|
+
- `!!` alias supported for first workbook sheet:
|
|
14
|
+
- `SUM(!!Amount)` -> `SUM(<first-sheet>!Amount)`
|
|
15
|
+
|
|
16
|
+
## What does not work yet
|
|
17
|
+
|
|
18
|
+
- Row-name dot refs are not supported:
|
|
19
|
+
- `Sheet!row_name.Column`
|
|
20
|
+
- Translation intentionally regex-based/narrow; complex token patterns can require explicit A1 refs.
|
|
21
|
+
- Direct file-style formula addressing is not supported.
|
|
22
|
+
|
|
23
|
+
## Translation model
|
|
24
|
+
|
|
25
|
+
- Formulas are preprocessed in `src/evaluator/formula.ts`.
|
|
26
|
+
- Unresolvable tokens are kept unchanged.
|
|
27
|
+
- Named refs with missing data rows emit warning diagnostics and remain unchanged.
|
|
28
|
+
- Formula parse errors from engine degrade to original formula text in output (`computed`).
|
|
29
|
+
|
|
30
|
+
## Suggested next steps
|
|
31
|
+
|
|
32
|
+
1. Add strict translation option for unresolved refs.
|
|
33
|
+
2. Expand tests for mixed expressions and nested formula patterns.
|