@exercism/codemirror-lang-abap 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.md +115 -2
- package/dist/index.cjs +1011 -0
- package/dist/index.d.cts +21 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +1000 -0
- package/package.json +51 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (C) 2024 by Erik Schierboom <erik_schierboom@hotmail.com> and others
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,116 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ABAP language support for CodeMirror
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
This repo contains a Lezer grammar for ABAP, with highlighting, indentation, folding and autocompletion for CodeMirror 6.
|
|
6
|
+
|
|
7
|
+
The grammar reads ABAP Objects code: class and interface definitions, class implementations and their methods, and the statements inside them. It knows the blocks (`IF`, `CASE`, `LOOP`, `DO`, `WHILE`, `TRY` and `AT`), the declarations (`DATA`, `TYPES`, `CONSTANTS`, `METHODS`, `FIELD-SYMBOLS` and inline `DATA(x)`), and expressions such as `VALUE #( )`, `NEW`, `->`, `=>`, table expressions, substrings (`text+2(3)`) and string templates.
|
|
8
|
+
|
|
9
|
+
ABAP is case-insensitive and has no reserved words, so a structure can have a field called `key` or `index`. The tokenizer reads each word and asks the parser which kind of word fits at that point. Where both a keyword and a name would fit, it looks at the words around it. For example, a word followed by `=` is a name, and so is `index` in `x < index`.
|
|
10
|
+
|
|
11
|
+
Comments start with `*` in the first column, or with `"` anywhere on a line.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import { EditorView, basicSetup } from "codemirror";
|
|
17
|
+
import { abap } from "@exercism/codemirror-lang-abap";
|
|
18
|
+
|
|
19
|
+
new EditorView({ extensions: [basicSetup, abap()] });
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The completion offers:
|
|
23
|
+
|
|
24
|
+
- the ABAP keywords, in upper or lower case, to match what the user is typing, and the built-in functions (such as `strlen`, `lines`, `condense` and `to_upper`), types and constants.
|
|
25
|
+
- snippets for a class definition and implementation, `METHOD`, `METHODS`, `LOOP AT`, `IF`, `CASE`, `DO`, `WHILE`, `TRY`, `DATA`, `TYPES` structures, `VALUE #( )` and `COND #( )`.
|
|
26
|
+
- the names declared in the file that are in scope. Inside a method, these are the method's parameters, the class's attributes, constants, types and methods (with those of a parent class defined in the same file), and the data declared earlier in the method. The class and interface names are offered everywhere.
|
|
27
|
+
- the members of the class after `me->` or `zcl_x=>`, and after `ref->` when `ref` is declared `TYPE REF TO` a class in the file.
|
|
28
|
+
- the fields of a structure after `ls_line-`, when its type is defined in the file.
|
|
29
|
+
|
|
30
|
+
It offers nothing inside strings, string templates or comments, and nothing while a new name is being typed.
|
|
31
|
+
|
|
32
|
+
To keep the package working on the Exercism website, don't change the versions of these packages:
|
|
33
|
+
|
|
34
|
+
```json
|
|
35
|
+
"@codemirror/language": "^6.10.1",
|
|
36
|
+
"@lezer/highlight": "^1.2.0",
|
|
37
|
+
"@lezer/lr": "^1.4.0"
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Install
|
|
41
|
+
|
|
42
|
+
- NPM: `npm install @exercism/codemirror-lang-abap`
|
|
43
|
+
- Yarn: `yarn add @exercism/codemirror-lang-abap`
|
|
44
|
+
- Bun: `bun add @exercism/codemirror-lang-abap`
|
|
45
|
+
|
|
46
|
+
## Prerequisites
|
|
47
|
+
|
|
48
|
+
- [Bun](https://bun.sh/)
|
|
49
|
+
|
|
50
|
+
## Resources
|
|
51
|
+
|
|
52
|
+
- [CodeMirror](https://codemirror.net/docs/)
|
|
53
|
+
- [Lezer](https://lezer.codemirror.net/docs/guide/)
|
|
54
|
+
- [Writing a Grammar](https://lezer.codemirror.net/docs/guide/#writing-a-grammar)
|
|
55
|
+
- [Examples](https://lezer.codemirror.net/examples/)
|
|
56
|
+
- [Existing grammar files](https://github.com/search?q=org%3Alezer-parser+path%3A%2F.grammar%24%2F&type=code)
|
|
57
|
+
|
|
58
|
+
## Structure
|
|
59
|
+
|
|
60
|
+
The source is written in [TypeScript](https://www.typescriptlang.org/).
|
|
61
|
+
|
|
62
|
+
The repo is structured as follows:
|
|
63
|
+
|
|
64
|
+
```text
|
|
65
|
+
.
|
|
66
|
+
├── src
|
|
67
|
+
│ ├── index.ts (the main plugin, with highlighting, indentation and folding)
|
|
68
|
+
│ ├── complete.ts (the completion sources)
|
|
69
|
+
│ ├── tokens.ts (the tokenizers for words, comments and the punctuation written straight after a name)
|
|
70
|
+
│ ├── words.ts (the keywords and built-in names)
|
|
71
|
+
│ ├── syntax.grammar (the Lezer grammar)
|
|
72
|
+
│ ├── syntax.grammar.d.ts (the grammar typings)
|
|
73
|
+
│ └── syntax.grammar.terms.d.ts (the term typings, written by scripts/terms-dts.mjs)
|
|
74
|
+
├── scripts
|
|
75
|
+
│ └── terms-dts.mjs (writes the term typings before each build)
|
|
76
|
+
├── test
|
|
77
|
+
│ ├── cases (grammar test cases)
|
|
78
|
+
│ │ └ *.txt (test case)
|
|
79
|
+
│ ├── grammar.test.ts (runs the grammar test cases)
|
|
80
|
+
│ ├── complete.test.ts (tests the completion)
|
|
81
|
+
│ └── language.test.ts (tests highlighting, folding and indentation)
|
|
82
|
+
├── index.html (dev server file)
|
|
83
|
+
├── rollup.config.js (bundling config)
|
|
84
|
+
├── tsconfig.json (typescript config)
|
|
85
|
+
└── vite.config.js (vite dev server config)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Setup
|
|
89
|
+
|
|
90
|
+
Run `bun install` to install all dependencies.
|
|
91
|
+
|
|
92
|
+
## Developing
|
|
93
|
+
|
|
94
|
+
To help with development, run `bun run dev`.
|
|
95
|
+
This will start a [Vite](https://vite.dev/) dev server (usually at http://localhost:5173/) that renders the `index.html` file.
|
|
96
|
+
The `#editor` element shows some sample code, highlighted by the grammar in `src/syntax.grammar`.
|
|
97
|
+
When you change the grammar, the page refreshes.
|
|
98
|
+
|
|
99
|
+
## Building
|
|
100
|
+
|
|
101
|
+
Run `bun run prepare` to build the package into `dist`.
|
|
102
|
+
`bun install` also runs this script.
|
|
103
|
+
|
|
104
|
+
## Testing
|
|
105
|
+
|
|
106
|
+
The `test/cases` directory contains the grammar test cases, in Lezer's test format.
|
|
107
|
+
Run `bun run test` to build the package and run all the tests.
|
|
108
|
+
The grammar needs the tokenizers in `src/tokens.ts`, so the tests run against the built package.
|
|
109
|
+
|
|
110
|
+
Keep each test case file small and focused on one aspect of the grammar.
|
|
111
|
+
|
|
112
|
+
## Publishing
|
|
113
|
+
|
|
114
|
+
To publish a new version, set `version` in `package.json` and commit it.
|
|
115
|
+
Then push a git tag named `v` followed by that version, such as `v1.0.1` for version 1.0.1.
|
|
116
|
+
The publish workflow builds and tests the package, then publishes it to npm.
|