{"name":"cspell-grammar","version":"10.3.5","keywords":["cspell","grammar"],"author":{"name":"Jason Dent","email":"jason@streetsidesoftware.nl"},"license":"MIT","_id":"cspell-grammar@10.3.5","maintainers":[{"name":"jason-dent","email":"jason@streetsidesoftware.nl"}],"homepage":"https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell-grammar#readme","bugs":{"url":"https://github.com/streetsidesoftware/cspell/labels/cspell-grammar"},"bin":{"cspell-grammar":"bin.mjs"},"dist":{"shasum":"9363e122c1378190f97919290250706e6656d8ca","tarball":"http://registry-npm.ywwl.com/cspell-grammar/download/cspell-grammar-10.3.5.tgz","fileCount":62,"integrity":"sha512-isBahk4y5BOw12U3Iltb+gejea7gTNhUDE4XOqH/F+38W3HskJL4hRrxA/C8RyT/b+jvu8jy4hKafGzjsuM7oA==","signatures":[{"sig":"MEYCIQD8+FgbAFt4U3HnplvfGPQ3vJc0vkBv36fzEkUoqZ2ckgIhALIZztFpuVqRRyv+FuIJ9ezkWL9DCkyu6/p5uMNe42xT","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEUCIQDN7Fd66nbdAVIDPWy+V/L9KaqYQX3J4f3kuh9+hD3v6wIgKs2SXUWW5b+25bsLe3xjvVda1rBEqkXm8dVPUl8F618=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/cspell-grammar@10.3.5","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":74832,"size":20553,"noattachment":false,"key":"/cspell-grammar/-/cspell-grammar-10.3.5.tgz"},"type":"module","types":"dist/index.d.ts","module":"dist/index.js","engines":{"node":">=22.18.0"},"exports":{".":{"import":"./dist/index.js"},"./parsers/typescript":{"import":"./dist/parsers/typescript/index.js"}},"gitHead":"f37a244a54b686fc1ac11272d6019b9a059b062a","scripts":{"test":"vitest run","build":"tsc -p .","clean":"shx rm -rf dist temp coverage \"*.tsbuildInfo\"","watch":"tsc -p . -w","coverage":"vitest run --coverage","test:watch":"vitest","clean-build":"pnpm run clean && pnpm run build"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:a45284d5-87e8-424b-b60f-60e892a53c06"}},"repository":{"url":"git+https://github.com/streetsidesoftware/cspell.git","type":"git","directory":"packages/cspell-grammar"},"_npmVersion":"lerna/5.6.1/node@v24.21.0+x64 (linux)","description":"Grammar parsing support for cspell","directories":{},"sideEffects":false,"_nodeVersion":"24.21.0","dependencies":{"@cspell/cspell-pipe":"10.3.5","@cspell/cspell-types":"10.3.5"},"publishConfig":{"access":"public","provenance":true},"typesVersions":{"*":{"*":["dist/*.d.ts","dist/*/index.d.ts"],"parsers":["dist/parsers/index.d.ts"],"index.js":["dist/index.d.ts"],"index.d.ts":["dist/index.d.ts"],"dist/*.d.ts":["dist/*.d.ts"],"parsers/typescript":["dist/parsers/typescript/index.d.ts"],"parsers/typescript/*.d.ts":["dist/parsers/typescript/*.d.ts"]}},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/cspell-grammar_10.3.5_1790540334305_0.742860592085113","host":"s3://npm-registry-packages-npm-production"},"readme":"# `cspell-grammar`\n\nCSpell Grammar is used to generate a parser. The Parser is used to add context / scope to parts of a document, making it easier to define the parts to be spell checked.\n\nThis is to address the issues and limitations related to `ignoreRegExpList` and `includeRegExpList`.\n\nThe parser is used to add `scope` to sections of a document. The `scope` can then be used to apply spell checking rules.\n\nExample: Only check comments and strings\n\n```yaml\nrules:\n  '*': false\n  comment: true\n  string: true\n```\n\nIt can be even more powerful like controlling the language settings based upon scope.\n\n```yaml\nrules:\n  comment:\n    language: en\n  string:\n    language: en,fr\n    dictionaries: ['marketing-terms']\n    caseSensitive: true\n  string.javascript:\n    caseSensitive: false\n```\n\nRules are applied in the order they match the scope of the text.\n\nWhen checking JavaScript files with the above example rules:\n\n- strings will:\n  - use the locale `en,fr`\n  - the `marketing-terms` dictionary will be enabled\n  - `caseSensitive` will be `true`\n- everything else:\n  - locale: `en`\n  - `caseSensitive` will be `false`\n\nAt its core, `cspell-grammar` uses a simplified form of the TextMate grammar.\n\n## Reasoning\n\nWhy use a grammar parser? Couldn't a colorizer / highlighter or a language AST be used?\nAt one level, needs of the spell checker are simpler and different from colorizers or language AST parsers.\nThe goal of a spell checker is to spell check **_relevant_** text. The spell check does not need to care about\nthe syntactical correctness of a document or presentation.\n\nThe goal of a grammar parser for the spell checker is to allow the user to decide:\n\n1. What text should be checked.\n1. Which dictionaries (or languages) should be used.\n1. Are accents and case important\n\nNote: CSpell is a pure JavaScript application, so including Oniguruma is not an option.\n\n### Considerations\n\n- Parsing a document should be fast - meaning the grammar should be as simple as possible to meet\n  the needs of the spell checker and not focus on scope detail. This is where a colorizer grammar is\n  not a good fit to be used.\n- ASTs are a bit of an overkill for a spell checker. They provide too much detail while not bringing much benefit\n  from the detail.\n\n## Transformation\n\nConsider the following bit of LaTeX:\n\n```latex\nk\\\"{o}nnen\nkönnen\n```\n\n<!--- cspell:ignore können nnen   -->\n\nFor the spell checker to work correctly, the `\\\"{o}` should be transformed into `ö` before it is checked against the German dictionary.\n\nThis creates a few challenges.\n\nPossible options:\n\n1. Simple whole document substitution\n   - Challenges\n     - It is not context aware and might replace the wrong text.\n     - It changes the location of the words and messes up issue reporting (some sort of Map would be needed to get the correct line / character offset).\n   - Advantages\n     - Easy to implement except for the context and mapping.\n\n1. Scope level substitution\n   Transformations occur at the scope level.\n   - Challenges\n     - offset mapping is still an issue (maybe)\n     - need a way to merge text with adjacent scopes after transformation\n   - Advantages\n     - it is context aware\n","publish_time":1790540334389,"_cnpm_publish_time":1790540334389,"dist-tags":{"latest":"10.4.0","next":"10.4.0-alpha.1"}}