@exercism/codemirror-lang-awk 1.0.0 → 2.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/CHANGELOG.md +71 -0
- package/README.md +8 -8
- package/dist/completion.d.ts +1 -1
- package/dist/grammar.d.ts +2 -2
- package/dist/highlight.d.ts +1 -1
- package/dist/index.cjs +5 -5
- package/dist/index.d.ts +7 -7
- package/dist/index.js +79 -79
- package/dist/linter.d.ts +1 -1
- package/dist/theme.d.ts +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [2.0.0] - 2026-11-21
|
|
9
|
+
|
|
10
|
+
This project was renamed from "gawk" to "awk". The public API now uses `awk` naming
|
|
11
|
+
throughout. This is a **breaking change**: the old `gawk*` names are no longer exported.
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- **BREAKING:** Renamed exports:
|
|
16
|
+
- `gawk()` → `awk()`
|
|
17
|
+
- `gawkLanguage` → `awkLanguage`
|
|
18
|
+
- `gawkHighlighting` → `awkHighlighting`
|
|
19
|
+
- `gawkStreamParser` → `awkStreamParser`
|
|
20
|
+
- `gawkHighlightStyle` → `awkHighlightStyle`
|
|
21
|
+
- `gawkCompletionSource` → `awkCompletionSource`
|
|
22
|
+
- `gawkLinter` → `awkLinter`
|
|
23
|
+
- `gawkDarkTheme` → `awkDarkTheme`
|
|
24
|
+
- `gawkLightTheme` → `awkLightTheme`
|
|
25
|
+
- `GawkState` → `AwkState`
|
|
26
|
+
- `GawkLanguageOptions` → `AwkLanguageOptions`
|
|
27
|
+
- **BREAKING:** Renamed the highlighting CSS classes from `cm-gawk-*` to `cm-awk-*`
|
|
28
|
+
(`directive`, `pattern`, `keyword`, `builtin-var`, `field`, `builtin-func`,
|
|
29
|
+
`func-def`, `func-call`, `string`, `regex`, `number`, `comment`, `operator`,
|
|
30
|
+
`punctuation`). Custom stylesheets targeting the old classes must be updated.
|
|
31
|
+
- The stream parser's language name is now `'awk'` (was `'gawk'`).
|
|
32
|
+
- Updated the README, demo and tests to use the new names.
|
|
33
|
+
|
|
34
|
+
### Unchanged
|
|
35
|
+
|
|
36
|
+
- The `GAWK_*` token constants (`GAWK_PATTERNS`, `GAWK_KEYWORDS`, `GAWK_DIRECTIVES`,
|
|
37
|
+
`GAWK_BUILTIN_VARS`, `GAWK_BUILTIN_FUNCTIONS`) keep their names.
|
|
38
|
+
|
|
39
|
+
### Migration
|
|
40
|
+
|
|
41
|
+
```diff
|
|
42
|
+
- import { gawk, gawkDarkTheme } from '@exercism/codemirror-lang-awk';
|
|
43
|
+
+ import { awk, awkDarkTheme } from '@exercism/codemirror-lang-awk';
|
|
44
|
+
|
|
45
|
+
- extensions: [basicSetup, gawk(), gawkDarkTheme]
|
|
46
|
+
+ extensions: [basicSetup, awk(), awkDarkTheme]
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## [1.0.0] - 2026-11-20
|
|
50
|
+
|
|
51
|
+
Initial release of the CodeMirror 6 language package for AWK and GNU AWK (gawk).
|
|
52
|
+
|
|
53
|
+
### Added
|
|
54
|
+
|
|
55
|
+
- Stream parser (`gawkStreamParser` / `gawkLanguage`) supporting POSIX AWK and GNU AWK:
|
|
56
|
+
directives (`@include`, `@load`, `@namespace`), pattern blocks (`BEGIN`, `END`,
|
|
57
|
+
`BEGINFILE`, `ENDFILE`), control keywords, regex literals, field references
|
|
58
|
+
(`$0`, `$NF`), and hex/octal numbers.
|
|
59
|
+
- Syntax highlighting (`gawkHighlighting`) with bundled dark and light themes
|
|
60
|
+
(`gawkDarkTheme`, `gawkLightTheme`).
|
|
61
|
+
- Context-aware autocompletion (`gawkCompletionSource`): directives, built-in functions
|
|
62
|
+
with signatures and documentation, built-in variables, snippets, and a scanner for
|
|
63
|
+
user-defined functions and variables in the document.
|
|
64
|
+
- Diagnostic linter (`gawkLinter`): unterminated strings and regexes, unmatched braces
|
|
65
|
+
and parentheses, unknown directives, and malformed function definitions.
|
|
66
|
+
- `gawk()` extension bundling highlighting, autocompletion and linting, with `lint` and
|
|
67
|
+
`autocomplete` options.
|
|
68
|
+
- Interactive demo (`npm run dev`).
|
|
69
|
+
|
|
70
|
+
[2.0.0]: https://github.com/exercism/codemirror-lang-awk/compare/v1.0.0...v2.0.0
|
|
71
|
+
[1.0.0]: https://github.com/exercism/codemirror-lang-awk/releases/tag/v1.0.0
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# CodeMirror 6 GNU AWK (gawk) Support
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@exercism/codemirror-lang-awk` is a CodeMirror 6 language plugin providing full syntax highlighting, autocompletion, diagnostic linting, and custom themes for both standard **POSIX AWK** and **GNU AWK (gawk)**.
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -44,20 +44,20 @@
|
|
|
44
44
|
|
|
45
45
|
## ✨ CodeMirror 6 Features Implemented
|
|
46
46
|
|
|
47
|
-
* **Stream Parser Engine (`
|
|
47
|
+
* **Stream Parser Engine (`awkLanguage` / `awkStreamParser`)**:
|
|
48
48
|
Custom tokenizer built for CodeMirror 6 supporting standard AWK and GNU AWK extensions (including directives, special pattern blocks, regex literals, field references, and hex/octal numbers).
|
|
49
49
|
|
|
50
|
-
* **Syntax Highlighting & Bundled Themes (`
|
|
50
|
+
* **Syntax Highlighting & Bundled Themes (`awkHighlighting`, `awkDarkTheme`, `awkLightTheme`)**:
|
|
51
51
|
Token tags mapped to `@lezer/highlight` with custom dark and light editor themes tailored for AWK development.
|
|
52
52
|
|
|
53
|
-
* **Context-Aware Autocompletion (`
|
|
53
|
+
* **Context-Aware Autocompletion (`awkCompletionSource`)**:
|
|
54
54
|
* **GNU Directives**: `@include`, `@load`, `@namespace`.
|
|
55
55
|
* **Built-in Functions**: Comprehensive completion list with function signatures, types, and detailed documentation tooltips (e.g., `gensub`, `patsplit`, `strftime`, `typeof`, `asort`).
|
|
56
56
|
* **Built-in Variables**: Standard and GNU-specific special variables (`FS`, `OFS`, `NR`, `NF`, `ARGIND`, `FPAT`, `ERRNO`, `SYMTAB`, etc.).
|
|
57
57
|
* **Snippets**: Quick insertions for `BEGIN`, `END`, `function`, `for (in)`, `for (i=1..n)`, `@include`, `@namespace`, and `@load`.
|
|
58
58
|
* **Document Symbol Scanner**: Dynamically collects user-defined function names and variable identifiers from the active document.
|
|
59
59
|
|
|
60
|
-
* **Live Diagnostic Linter (`
|
|
60
|
+
* **Live Diagnostic Linter (`awkLinter`)**:
|
|
61
61
|
Real-time syntax checking highlighting code issues directly in the editor:
|
|
62
62
|
* Unterminated string literals (`"text...`)
|
|
63
63
|
* Unclosed regular expression literals (`/pattern...`)
|
|
@@ -112,7 +112,7 @@
|
|
|
112
112
|
```typescript
|
|
113
113
|
import { EditorView } from '@codemirror/view';
|
|
114
114
|
import { basicSetup } from 'codemirror';
|
|
115
|
-
import {
|
|
115
|
+
import { awk, awkDarkTheme } from '@exercism/codemirror-lang-awk';
|
|
116
116
|
|
|
117
117
|
const editor = new EditorView({
|
|
118
118
|
doc: `@include "helpers.awk"
|
|
@@ -139,8 +139,8 @@ END {
|
|
|
139
139
|
}`,
|
|
140
140
|
extensions: [
|
|
141
141
|
basicSetup,
|
|
142
|
-
|
|
143
|
-
|
|
142
|
+
awk({ lint: true, autocomplete: true }),
|
|
143
|
+
awkDarkTheme
|
|
144
144
|
],
|
|
145
145
|
parent: document.getElementById('editor')!
|
|
146
146
|
});
|
package/dist/completion.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ import { CompletionContext, CompletionResult } from '@codemirror/autocomplete';
|
|
|
2
2
|
/**
|
|
3
3
|
* CodeMirror 6 Completion Source for GNU AWK
|
|
4
4
|
*/
|
|
5
|
-
export declare function
|
|
5
|
+
export declare function awkCompletionSource(context: CompletionContext): CompletionResult | null;
|
package/dist/grammar.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StreamParser } from '@codemirror/language';
|
|
2
|
-
export interface
|
|
2
|
+
export interface AwkState {
|
|
3
3
|
inString: boolean;
|
|
4
4
|
stringQuote: string;
|
|
5
5
|
inRegex: boolean;
|
|
@@ -8,4 +8,4 @@ export interface GawkState {
|
|
|
8
8
|
inDirective: boolean;
|
|
9
9
|
lastToken: string;
|
|
10
10
|
}
|
|
11
|
-
export declare const
|
|
11
|
+
export declare const awkStreamParser: StreamParser<AwkState>;
|
package/dist/highlight.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("@codemirror/language"),f=require("@codemirror/autocomplete"),n=require("@lezer/highlight"),U=require("@codemirror/lint"),D=require("@codemirror/view"),S=new Set(["BEGIN","END","BEGINFILE","ENDFILE"]),v=new Set(["if","else","while","do","for","in","break","continue","next","nextfile","exit","return","delete","function","func"]),N=new Set(["@include","@load","@namespace"]),T=new Set(["ARGC","ARGV","CONVFMT","ENVIRON","FILENAME","FNR","FS","NF","NR","OFMT","OFS","ORS","RLENGTH","RS","RSTART","SUBSEP","ARGIND","BINMODE","ERRNO","FIELDWIDTHS","FPAT","FUNCTAB","LINT","PREC","ROUNDMODE","RT","STRTAB","SYMTAB","TEXTDOMAIN"]),x={atan2:{name:"atan2",signature:"atan2(y, x)",detail:"Math function",doc:"Returns the arctangent of y/x in radians.",type:"math"},cos:{name:"cos",signature:"cos(x)",detail:"Math function",doc:"Returns the cosine of x (x in radians).",type:"math"},exp:{name:"exp",signature:"exp(x)",detail:"Math function",doc:"Returns the exponential function of x (e^x).",type:"math"},int:{name:"int",signature:"int(x)",detail:"Math function",doc:"Truncates x to an integer value towards zero.",type:"math"},log:{name:"log",signature:"log(x)",detail:"Math function",doc:"Returns the natural logarithm of x.",type:"math"},rand:{name:"rand",signature:"rand()",detail:"Math function",doc:"Returns a random floating point number r such that 0 <= r < 1.",type:"math"},sin:{name:"sin",signature:"sin(x)",detail:"Math function",doc:"Returns the sine of x (x in radians).",type:"math"},sqrt:{name:"sqrt",signature:"sqrt(x)",detail:"Math function",doc:"Returns the square root of x.",type:"math"},srand:{name:"srand",signature:"srand([x])",detail:"Math function",doc:"Sets the seed for rand() to x and returns the previous seed. If x omitted, uses current time.",type:"math"},asort:{name:"asort",signature:"asort(source [, dest [, how]])",detail:"gawk String / Array function",doc:"Sorts array source by values. If dest given, source is duplicated into dest before sorting.",type:"string"},asorti:{name:"asorti",signature:"asorti(source [, dest [, how]])",detail:"gawk String / Array function",doc:"Sorts array source by indices instead of values into dest array.",type:"string"},gensub:{name:"gensub",signature:"gensub(regex, replacement, how [, target])",detail:"gawk String function",doc:'Substitutes replacement for regex in target (or $0). how can be "g", "G", or a number N for Nth match.',type:"string"},gsub:{name:"gsub",signature:"gsub(regex, replacement [, target])",detail:"String function",doc:"Globally substitutes replacement for regex in target (or $0). Returns number of substitutions made.",type:"string"},index:{name:"index",signature:"index(str, target)",detail:"String function",doc:"Returns the 1-based position of target substring in str, or 0 if not found.",type:"string"},length:{name:"length",signature:"length([str_or_arr])",detail:"String / Array function",doc:"Returns the length of string str or number of elements in array. Defaults to length($0).",type:"string"},match:{name:"match",signature:"match(str, regex [, array])",detail:"String function",doc:"Searches str for regex match. Sets RSTART, RLENGTH, and populates submatch array in gawk.",type:"string"},patsplit:{name:"patsplit",signature:"patsplit(str, arr [, regex [, seps]])",detail:"gawk String function",doc:"Splits str into arr matching regex pattern instead of field separators.",type:"string"},split:{name:"split",signature:"split(str, arr [, regex [, seps]])",detail:"String function",doc:"Splits str into arr elements indexed from 1 using field separator regex (or FS).",type:"string"},sprintf:{name:"sprintf",signature:"sprintf(fmt, expr1, ...)",detail:"String function",doc:"Formats expressions according to printf format specifier fmt and returns string.",type:"string"},strtonum:{name:"strtonum",signature:"strtonum(str)",detail:"gawk String function",doc:"Examines str and returns numeric value. Supports decimal, octal (leading 0), and hex (leading 0x/0X).",type:"string"},sub:{name:"sub",signature:"sub(regex, replacement [, target])",detail:"String function",doc:"Substitutes first match of regex with replacement in target (or $0). Returns 1 if matched, else 0.",type:"string"},substr:{name:"substr",signature:"substr(str, start [, length])",detail:"String function",doc:"Returns substring of str starting at 1-based start index up to length characters.",type:"string"},tolower:{name:"tolower",signature:"tolower(str)",detail:"String function",doc:"Returns copy of str converted to lowercase.",type:"string"},toupper:{name:"toupper",signature:"toupper(str)",detail:"String function",doc:"Returns copy of str converted to uppercase.",type:"string"},mktime:{name:"mktime",signature:"mktime(datespec [, utc])",detail:"gawk Time function",doc:'Converts "YYYY MM DD HH MM SS [DST]" datespec into epoch timestamp in seconds.',type:"time"},strftime:{name:"strftime",signature:"strftime([fmt [, timestamp [, utc]]])",detail:"gawk Time function",doc:"Formats timestamp (or current time) using strftime format specifier fmt.",type:"time"},systime:{name:"systime",signature:"systime()",detail:"gawk Time function",doc:"Returns current time as number of seconds since POSIX epoch.",type:"time"},and:{name:"and",signature:"and(v1, v2, ...)",detail:"gawk Bitwise function",doc:"Returns bitwise AND of arguments.",type:"bitwise"},compl:{name:"compl",signature:"compl(val)",detail:"gawk Bitwise function",doc:"Returns bitwise complement (NOT) of val.",type:"bitwise"},lshift:{name:"lshift",signature:"lshift(val, count)",detail:"gawk Bitwise function",doc:"Returns val shifted left by count bits.",type:"bitwise"},rshift:{name:"rshift",signature:"rshift(val, count)",detail:"gawk Bitwise function",doc:"Returns val shifted right by count bits.",type:"bitwise"},or:{name:"or",signature:"or(v1, v2, ...)",detail:"gawk Bitwise function",doc:"Returns bitwise OR of arguments.",type:"bitwise"},xor:{name:"xor",signature:"xor(v1, v2, ...)",detail:"gawk Bitwise function",doc:"Returns bitwise exclusive OR (XOR) of arguments.",type:"bitwise"},isarray:{name:"isarray",signature:"isarray(x)",detail:"gawk Type function",doc:"Returns 1 if x is an array, else 0.",type:"gawk"},typeof:{name:"typeof",signature:"typeof(x)",detail:"gawk Type function",doc:'Returns string indicating type of x ("array", "number", "string", "regexp", "unassigned", "untyped").',type:"gawk"},close:{name:"close",signature:"close(filename_or_cmd [, how])",detail:"I/O function",doc:"Closes an open file or pipe connection.",type:"io"},fflush:{name:"fflush",signature:"fflush([filename_or_cmd])",detail:"I/O function",doc:"Flushes pending output buffers for file/pipe or stdout if omitted.",type:"io"},system:{name:"system",signature:"system(command)",detail:"I/O function",doc:"Executes operating system shell command and returns its exit status.",type:"io"},bindtextdomain:{name:"bindtextdomain",signature:"bindtextdomain(dir [, domain])",detail:"gawk i18n function",doc:"Specifies directory for searching text domain MO files.",type:"gawk"},dcgettext:{name:"dcgettext",signature:"dcgettext(string [, domain [, category]])",detail:"gawk i18n function",doc:"Returns localized translation of string for domain and category.",type:"gawk"},dcngettext:{name:"dcngettext",signature:"dcngettext(string1, string2, number [, domain [, category]])",detail:"gawk i18n function",doc:"Returns plural-aware localized translation of string for number.",type:"gawk"}},F={name:"gawk",tokenTable:{"special(keyword)":n.tags.special(n.tags.keyword),"special(variableName)":n.tags.special(n.tags.variableName),"standard(variableName)":n.tags.standard(n.tags.variableName),"standard(name)":n.tags.standard(n.tags.name),"function(definition)":n.tags.definition(n.tags.function(n.tags.variableName)),"function(call)":n.tags.function(n.tags.variableName)},startState(){return{inString:!1,stringQuote:'"',inRegex:!1,expectRegex:!0,inComment:!1,inDirective:!1,lastToken:""}},token(t,e){if(t.eatSpace())return null;if(t.peek()==="#")return t.skipToEnd(),e.expectRegex=!0,"comment";if(e.inString){let i=!1;for(;!t.eol();){const c=t.next();if(i)i=!1;else if(c==="\\")i=!0;else if(c===e.stringQuote)return e.inString=!1,e.expectRegex=!1,"string"}return i||(e.inString=!1),"string"}if(e.inRegex){let i=!1;for(;!t.eol();){const c=t.next();if(i)i=!1;else if(c==="\\")i=!0;else if(c==="/")return e.inRegex=!1,e.expectRegex=!1,"regexp"}return i||(e.inRegex=!1),"regexp"}if(t.peek()==="@"){t.eat("@"),t.eatWhile(/[\w_]/);const i=t.current();return e.expectRegex=!0,N.has(i)?(e.lastToken=i,"processingInstruction"):"keyword"}if(t.peek()==='"')return t.next(),e.inString=!0,e.stringQuote='"',"string";if(t.peek()==="/")return e.expectRegex?(t.next(),e.inRegex=!0,"regexp"):(t.next(),t.peek()==="="?(t.next(),e.lastToken="/="):e.lastToken="/",e.expectRegex=!0,"operator");if(t.peek()==="$")return t.next(),t.match(/^\d+/)||t.match(/^[A-Za-z_][A-Za-z0-9_]*/)?(e.expectRegex=!1,"special(variableName)"):(e.expectRegex=!0,"operator");if(t.match(/^0[xX][0-9a-fA-F]+/)||t.match(/^\d+(\.\d+)?([eE][+-]?\d+)?/))return e.expectRegex=!1,"number";if(t.match(/^(~|!~|\+\+|--|&&|\|\||\|&|==|!=|<=|>=|\+=|-=|\*=|\/=|%=|\^=|\*\*=|<<|>>|\*\*)/))return e.expectRegex=!0,"operator";const u=t.next();if("+-*%^=<>!~|&".includes(u))return e.expectRegex=!0,"operator";if("{}()[];,".includes(u))return u===")"||u==="}"?e.expectRegex=!1:e.expectRegex=!0,"punctuation";if(/[A-Za-z_]/.test(u)){t.eatWhile(/[\w_]/);const i=t.current();return S.has(i)?(e.expectRegex=!0,e.lastToken=i,"special(keyword)"):v.has(i)?(e.expectRegex=!0,e.lastToken=i,"keyword"):T.has(i)?(e.expectRegex=!1,e.lastToken=i,"standard(variableName)"):x[i]?(e.expectRegex=!0,e.lastToken=i,"standard(name)"):e.lastToken==="function"||e.lastToken==="func"?(e.expectRegex=!1,"function(definition)"):t.peek()==="("?(e.expectRegex=!0,"function(call)"):(e.expectRegex=!1,e.lastToken=i,"variableName")}return null},indent(t,e){return e.startsWith("}")?0:2}},M=[{tag:n.tags.keyword,class:"cm-gawk-keyword"},{tag:n.tags.special(n.tags.keyword),class:"cm-gawk-pattern"},{tag:n.tags.processingInstruction,class:"cm-gawk-directive"},{tag:n.tags.meta,class:"cm-gawk-directive"},{tag:n.tags.standard(n.tags.variableName),class:"cm-gawk-builtin-var"},{tag:n.tags.special(n.tags.variableName),class:"cm-gawk-field"},{tag:n.tags.standard(n.tags.name),class:"cm-gawk-builtin-func"},{tag:n.tags.definition(n.tags.function(n.tags.variableName)),class:"cm-gawk-func-def"},{tag:n.tags.function(n.tags.variableName),class:"cm-gawk-func-call"},{tag:n.tags.string,class:"cm-gawk-string"},{tag:n.tags.regexp,class:"cm-gawk-regex"},{tag:n.tags.number,class:"cm-gawk-number"},{tag:n.tags.comment,class:"cm-gawk-comment"},{tag:n.tags.operator,class:"cm-gawk-operator"},{tag:n.tags.punctuation,class:"cm-gawk-punctuation"}],E=Array.from(N).map(t=>({label:t,type:"keyword",detail:"GNU AWK Directive",boost:10})),z=Array.from(S).map(t=>({label:t,type:"type",detail:"Pattern Block",boost:8})),K=Array.from(v).map(t=>({label:t,type:"keyword",detail:"Control Keyword"})),P=Array.from(T).map(t=>({label:t,type:"variable",detail:"GNU AWK Built-in Variable",boost:2})),Z=Object.values(x).map(t=>({label:t.name,type:"function",detail:t.signature,info:`${t.detail}
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("@codemirror/language"),g=require("@codemirror/autocomplete"),n=require("@lezer/highlight"),U=require("@codemirror/lint"),D=require("@codemirror/view"),S=new Set(["BEGIN","END","BEGINFILE","ENDFILE"]),v=new Set(["if","else","while","do","for","in","break","continue","next","nextfile","exit","return","delete","function","func"]),N=new Set(["@include","@load","@namespace"]),T=new Set(["ARGC","ARGV","CONVFMT","ENVIRON","FILENAME","FNR","FS","NF","NR","OFMT","OFS","ORS","RLENGTH","RS","RSTART","SUBSEP","ARGIND","BINMODE","ERRNO","FIELDWIDTHS","FPAT","FUNCTAB","LINT","PREC","ROUNDMODE","RT","STRTAB","SYMTAB","TEXTDOMAIN"]),x={atan2:{name:"atan2",signature:"atan2(y, x)",detail:"Math function",doc:"Returns the arctangent of y/x in radians.",type:"math"},cos:{name:"cos",signature:"cos(x)",detail:"Math function",doc:"Returns the cosine of x (x in radians).",type:"math"},exp:{name:"exp",signature:"exp(x)",detail:"Math function",doc:"Returns the exponential function of x (e^x).",type:"math"},int:{name:"int",signature:"int(x)",detail:"Math function",doc:"Truncates x to an integer value towards zero.",type:"math"},log:{name:"log",signature:"log(x)",detail:"Math function",doc:"Returns the natural logarithm of x.",type:"math"},rand:{name:"rand",signature:"rand()",detail:"Math function",doc:"Returns a random floating point number r such that 0 <= r < 1.",type:"math"},sin:{name:"sin",signature:"sin(x)",detail:"Math function",doc:"Returns the sine of x (x in radians).",type:"math"},sqrt:{name:"sqrt",signature:"sqrt(x)",detail:"Math function",doc:"Returns the square root of x.",type:"math"},srand:{name:"srand",signature:"srand([x])",detail:"Math function",doc:"Sets the seed for rand() to x and returns the previous seed. If x omitted, uses current time.",type:"math"},asort:{name:"asort",signature:"asort(source [, dest [, how]])",detail:"gawk String / Array function",doc:"Sorts array source by values. If dest given, source is duplicated into dest before sorting.",type:"string"},asorti:{name:"asorti",signature:"asorti(source [, dest [, how]])",detail:"gawk String / Array function",doc:"Sorts array source by indices instead of values into dest array.",type:"string"},gensub:{name:"gensub",signature:"gensub(regex, replacement, how [, target])",detail:"gawk String function",doc:'Substitutes replacement for regex in target (or $0). how can be "g", "G", or a number N for Nth match.',type:"string"},gsub:{name:"gsub",signature:"gsub(regex, replacement [, target])",detail:"String function",doc:"Globally substitutes replacement for regex in target (or $0). Returns number of substitutions made.",type:"string"},index:{name:"index",signature:"index(str, target)",detail:"String function",doc:"Returns the 1-based position of target substring in str, or 0 if not found.",type:"string"},length:{name:"length",signature:"length([str_or_arr])",detail:"String / Array function",doc:"Returns the length of string str or number of elements in array. Defaults to length($0).",type:"string"},match:{name:"match",signature:"match(str, regex [, array])",detail:"String function",doc:"Searches str for regex match. Sets RSTART, RLENGTH, and populates submatch array in gawk.",type:"string"},patsplit:{name:"patsplit",signature:"patsplit(str, arr [, regex [, seps]])",detail:"gawk String function",doc:"Splits str into arr matching regex pattern instead of field separators.",type:"string"},split:{name:"split",signature:"split(str, arr [, regex [, seps]])",detail:"String function",doc:"Splits str into arr elements indexed from 1 using field separator regex (or FS).",type:"string"},sprintf:{name:"sprintf",signature:"sprintf(fmt, expr1, ...)",detail:"String function",doc:"Formats expressions according to printf format specifier fmt and returns string.",type:"string"},strtonum:{name:"strtonum",signature:"strtonum(str)",detail:"gawk String function",doc:"Examines str and returns numeric value. Supports decimal, octal (leading 0), and hex (leading 0x/0X).",type:"string"},sub:{name:"sub",signature:"sub(regex, replacement [, target])",detail:"String function",doc:"Substitutes first match of regex with replacement in target (or $0). Returns 1 if matched, else 0.",type:"string"},substr:{name:"substr",signature:"substr(str, start [, length])",detail:"String function",doc:"Returns substring of str starting at 1-based start index up to length characters.",type:"string"},tolower:{name:"tolower",signature:"tolower(str)",detail:"String function",doc:"Returns copy of str converted to lowercase.",type:"string"},toupper:{name:"toupper",signature:"toupper(str)",detail:"String function",doc:"Returns copy of str converted to uppercase.",type:"string"},mktime:{name:"mktime",signature:"mktime(datespec [, utc])",detail:"gawk Time function",doc:'Converts "YYYY MM DD HH MM SS [DST]" datespec into epoch timestamp in seconds.',type:"time"},strftime:{name:"strftime",signature:"strftime([fmt [, timestamp [, utc]]])",detail:"gawk Time function",doc:"Formats timestamp (or current time) using strftime format specifier fmt.",type:"time"},systime:{name:"systime",signature:"systime()",detail:"gawk Time function",doc:"Returns current time as number of seconds since POSIX epoch.",type:"time"},and:{name:"and",signature:"and(v1, v2, ...)",detail:"gawk Bitwise function",doc:"Returns bitwise AND of arguments.",type:"bitwise"},compl:{name:"compl",signature:"compl(val)",detail:"gawk Bitwise function",doc:"Returns bitwise complement (NOT) of val.",type:"bitwise"},lshift:{name:"lshift",signature:"lshift(val, count)",detail:"gawk Bitwise function",doc:"Returns val shifted left by count bits.",type:"bitwise"},rshift:{name:"rshift",signature:"rshift(val, count)",detail:"gawk Bitwise function",doc:"Returns val shifted right by count bits.",type:"bitwise"},or:{name:"or",signature:"or(v1, v2, ...)",detail:"gawk Bitwise function",doc:"Returns bitwise OR of arguments.",type:"bitwise"},xor:{name:"xor",signature:"xor(v1, v2, ...)",detail:"gawk Bitwise function",doc:"Returns bitwise exclusive OR (XOR) of arguments.",type:"bitwise"},isarray:{name:"isarray",signature:"isarray(x)",detail:"gawk Type function",doc:"Returns 1 if x is an array, else 0.",type:"gawk"},typeof:{name:"typeof",signature:"typeof(x)",detail:"gawk Type function",doc:'Returns string indicating type of x ("array", "number", "string", "regexp", "unassigned", "untyped").',type:"gawk"},close:{name:"close",signature:"close(filename_or_cmd [, how])",detail:"I/O function",doc:"Closes an open file or pipe connection.",type:"io"},fflush:{name:"fflush",signature:"fflush([filename_or_cmd])",detail:"I/O function",doc:"Flushes pending output buffers for file/pipe or stdout if omitted.",type:"io"},system:{name:"system",signature:"system(command)",detail:"I/O function",doc:"Executes operating system shell command and returns its exit status.",type:"io"},bindtextdomain:{name:"bindtextdomain",signature:"bindtextdomain(dir [, domain])",detail:"gawk i18n function",doc:"Specifies directory for searching text domain MO files.",type:"gawk"},dcgettext:{name:"dcgettext",signature:"dcgettext(string [, domain [, category]])",detail:"gawk i18n function",doc:"Returns localized translation of string for domain and category.",type:"gawk"},dcngettext:{name:"dcngettext",signature:"dcngettext(string1, string2, number [, domain [, category]])",detail:"gawk i18n function",doc:"Returns plural-aware localized translation of string for number.",type:"gawk"}},F={name:"awk",tokenTable:{"special(keyword)":n.tags.special(n.tags.keyword),"special(variableName)":n.tags.special(n.tags.variableName),"standard(variableName)":n.tags.standard(n.tags.variableName),"standard(name)":n.tags.standard(n.tags.name),"function(definition)":n.tags.definition(n.tags.function(n.tags.variableName)),"function(call)":n.tags.function(n.tags.variableName)},startState(){return{inString:!1,stringQuote:'"',inRegex:!1,expectRegex:!0,inComment:!1,inDirective:!1,lastToken:""}},token(t,e){if(t.eatSpace())return null;if(t.peek()==="#")return t.skipToEnd(),e.expectRegex=!0,"comment";if(e.inString){let i=!1;for(;!t.eol();){const c=t.next();if(i)i=!1;else if(c==="\\")i=!0;else if(c===e.stringQuote)return e.inString=!1,e.expectRegex=!1,"string"}return i||(e.inString=!1),"string"}if(e.inRegex){let i=!1;for(;!t.eol();){const c=t.next();if(i)i=!1;else if(c==="\\")i=!0;else if(c==="/")return e.inRegex=!1,e.expectRegex=!1,"regexp"}return i||(e.inRegex=!1),"regexp"}if(t.peek()==="@"){t.eat("@"),t.eatWhile(/[\w_]/);const i=t.current();return e.expectRegex=!0,N.has(i)?(e.lastToken=i,"processingInstruction"):"keyword"}if(t.peek()==='"')return t.next(),e.inString=!0,e.stringQuote='"',"string";if(t.peek()==="/")return e.expectRegex?(t.next(),e.inRegex=!0,"regexp"):(t.next(),t.peek()==="="?(t.next(),e.lastToken="/="):e.lastToken="/",e.expectRegex=!0,"operator");if(t.peek()==="$")return t.next(),t.match(/^\d+/)||t.match(/^[A-Za-z_][A-Za-z0-9_]*/)?(e.expectRegex=!1,"special(variableName)"):(e.expectRegex=!0,"operator");if(t.match(/^0[xX][0-9a-fA-F]+/)||t.match(/^\d+(\.\d+)?([eE][+-]?\d+)?/))return e.expectRegex=!1,"number";if(t.match(/^(~|!~|\+\+|--|&&|\|\||\|&|==|!=|<=|>=|\+=|-=|\*=|\/=|%=|\^=|\*\*=|<<|>>|\*\*)/))return e.expectRegex=!0,"operator";const f=t.next();if("+-*%^=<>!~|&".includes(f))return e.expectRegex=!0,"operator";if("{}()[];,".includes(f))return f===")"||f==="}"?e.expectRegex=!1:e.expectRegex=!0,"punctuation";if(/[A-Za-z_]/.test(f)){t.eatWhile(/[\w_]/);const i=t.current();return S.has(i)?(e.expectRegex=!0,e.lastToken=i,"special(keyword)"):v.has(i)?(e.expectRegex=!0,e.lastToken=i,"keyword"):T.has(i)?(e.expectRegex=!1,e.lastToken=i,"standard(variableName)"):x[i]?(e.expectRegex=!0,e.lastToken=i,"standard(name)"):e.lastToken==="function"||e.lastToken==="func"?(e.expectRegex=!1,"function(definition)"):t.peek()==="("?(e.expectRegex=!0,"function(call)"):(e.expectRegex=!1,e.lastToken=i,"variableName")}return null},indent(t,e){return e.startsWith("}")?0:2}},M=[{tag:n.tags.keyword,class:"cm-awk-keyword"},{tag:n.tags.special(n.tags.keyword),class:"cm-awk-pattern"},{tag:n.tags.processingInstruction,class:"cm-awk-directive"},{tag:n.tags.meta,class:"cm-awk-directive"},{tag:n.tags.standard(n.tags.variableName),class:"cm-awk-builtin-var"},{tag:n.tags.special(n.tags.variableName),class:"cm-awk-field"},{tag:n.tags.standard(n.tags.name),class:"cm-awk-builtin-func"},{tag:n.tags.definition(n.tags.function(n.tags.variableName)),class:"cm-awk-func-def"},{tag:n.tags.function(n.tags.variableName),class:"cm-awk-func-call"},{tag:n.tags.string,class:"cm-awk-string"},{tag:n.tags.regexp,class:"cm-awk-regex"},{tag:n.tags.number,class:"cm-awk-number"},{tag:n.tags.comment,class:"cm-awk-comment"},{tag:n.tags.operator,class:"cm-awk-operator"},{tag:n.tags.punctuation,class:"cm-awk-punctuation"}],E=Array.from(N).map(t=>({label:t,type:"keyword",detail:"GNU AWK Directive",boost:10})),z=Array.from(S).map(t=>({label:t,type:"type",detail:"Pattern Block",boost:8})),K=Array.from(v).map(t=>({label:t,type:"keyword",detail:"Control Keyword"})),P=Array.from(T).map(t=>({label:t,type:"variable",detail:"GNU AWK Built-in Variable",boost:2})),Z=Object.values(x).map(t=>({label:t.name,type:"function",detail:t.signature,info:`${t.detail}
|
|
2
2
|
|
|
3
|
-
${t.doc}`,boost:3})),$=[{label:"BEGIN",type:"snippet",detail:"BEGIN pattern block",apply:
|
|
3
|
+
${t.doc}`,boost:3})),$=[{label:"BEGIN",type:"snippet",detail:"BEGIN pattern block",apply:g.snippet(`BEGIN {
|
|
4
4
|
\${1}
|
|
5
|
-
}`),boost:9},{label:"END",type:"snippet",detail:"END pattern block",apply:
|
|
5
|
+
}`),boost:9},{label:"END",type:"snippet",detail:"END pattern block",apply:g.snippet(`END {
|
|
6
6
|
\${1}
|
|
7
|
-
}`),boost:9},{label:"function",type:"snippet",detail:"User-defined function definition",apply:
|
|
7
|
+
}`),boost:9},{label:"function",type:"snippet",detail:"User-defined function definition",apply:g.snippet("function ${1:name}(${2:args}) {\n ${3}\n}"),boost:9},{label:"for (in)",type:"snippet",detail:"Array iteration loop",apply:g.snippet("for (${1:key} in ${2:array}) {\n ${3}\n}"),boost:8},{label:"for (i=1..n)",type:"snippet",detail:"Numeric count loop",apply:g.snippet("for (${1:i} = 1; ${1:i} <= ${2:n}; ${1:i}++) {\n ${3}\n}"),boost:8},{label:"if",type:"snippet",detail:"Conditional statement",apply:g.snippet("if (${1:condition}) {\n ${2}\n}"),boost:8},{label:"if-else",type:"snippet",detail:"If-else statement",apply:g.snippet(`if (\${1:condition}) {
|
|
8
8
|
\${2}
|
|
9
9
|
} else {
|
|
10
10
|
\${3}
|
|
11
|
-
}`),boost:8},{label:"@include",type:"snippet",detail:"Include AWK source file",apply:
|
|
11
|
+
}`),boost:8},{label:"@include",type:"snippet",detail:"Include AWK source file",apply:g.snippet('@include "${1:filename.awk}"'),boost:10},{label:"@namespace",type:"snippet",detail:"GNU AWK Namespace definition",apply:g.snippet('@namespace "${1:name}"'),boost:10},{label:"@load",type:"snippet",detail:"Load shared extension library",apply:g.snippet('@load "${1:extension}"'),boost:10}];function V(t){const e=new Map,f=/\b(?:function|func)\s+([A-Za-z_][A-Za-z0-9_]*)/g;let i;for(;(i=f.exec(t))!==null;){const o=i[1];x[o]||e.set(o,{label:o,type:"function",detail:"User Function",boost:5})}const c=/\b([A-Za-z_][A-Za-z0-9_]*)\b/g;for(;(i=c.exec(t))!==null;){const o=i[1];!v.has(o)&&!S.has(o)&&!T.has(o)&&!x[o]&&!e.has(o)&&e.set(o,{label:o,type:"variable",detail:"Document Variable"})}return Array.from(e.values())}function O(t){const e=t.matchBefore(/@[\w_]*|[A-Za-z_][A-Za-z0-9_]*/);if(!e||e.from===e.to&&!t.explicit)return null;if(e.text.startsWith("@"))return{from:e.from,options:[...E,...$.filter(o=>o.label.startsWith("@"))],validFor:/^@[\w_]*$/};const i=t.state.doc.toString(),c=V(i);return{from:e.from,options:[...$,...z,...E,...K,...Z,...P,...c],validFor:/^[A-Za-z_][A-Za-z0-9_]*$/}}function B(){return U.linter(t=>{const e=[],f=t.state.doc,i=f.lines;let c=[],o=[];for(let u=1;u<=i;u++){const s=f.line(u),b=s.text,A=b.indexOf("#"),l=A!==-1?b.slice(0,A):b,C=b.match(/@([a-zA-Z0-9_]+)/g);if(C){for(const a of C)if(!N.has(a)){const r=s.from+b.indexOf(a);e.push({from:r,to:r+a.length,severity:"error",message:`Unknown GNU AWK directive '${a}'. Valid directives: @include, @load, @namespace.`})}}if(/@include\s*(?!["<])/.test(l)){const a=s.from+l.indexOf("@include");e.push({from:a,to:a+8,severity:"warning",message:'@include directive expects a quoted filename e.g. @include "filename.awk"'})}if(/@namespace\s*(?!["<])/.test(l)){const a=s.from+l.indexOf("@namespace");e.push({from:a,to:a+10,severity:"warning",message:'@namespace directive expects a quoted string e.g. @namespace "my_module"'})}const h=l.match(/\b(?:function|func)\b/);if(h){const a=l.slice(h.index+h[0].length).trim();if(a===""||a.startsWith("{")||a.startsWith("(")){const r=s.from+h.index;e.push({from:r,to:r+h[0].length,severity:"error",message:"Function definition missing function name."})}else{const r=l.match(/\b(?:function|func)\s+([A-Za-z_][A-Za-z0-9_]*)/);if(r){const p=r[1];if(!l.slice(r.index+r[0].length).trim().startsWith("(")){const d=s.from+r.index;e.push({from:d,to:d+r[0].length,severity:"error",message:`Function definition '${p}' missing parameter parentheses '()'.`})}}}}let y=!1,I="",W=0,w=!1,_=0,k=!1;for(let a=0;a<l.length;a++){const r=l[a],p=a>0?l[a-1]:"";if(y)r===I&&p!=="\\"&&(y=!1);else if(w)r==="["&&p!=="\\"?k=!0:r==="]"&&p!=="\\"?k=!1:r==="/"&&p!=="\\"&&!k&&(w=!1);else if(r==='"')y=!0,I='"',W=s.from+a;else if(r==="/"){const m=l.slice(0,a).trim();(m===""||/[=~,\(\!\?\:\{\;\+\-\*\%\&\|]$/.test(m)||/\b(print|printf|return|match|sub|gsub|gensub|patsplit|split|if|while)\s*$/i.test(m))&&(w=!0,k=!1,_=s.from+a)}else if(r==="{"){const m=o.filter(d=>d.line===u);for(const d of m)e.push({from:d.pos,to:d.pos+1,severity:"error",message:'Unclosed parenthesis "(" in condition before brace.'});o=o.filter(d=>d.line!==u),c.push({pos:s.from+a,line:u})}else r==="}"?c.length>0?c.pop():e.push({from:s.from+a,to:s.from+a+1,severity:"error",message:'Unmatched closing brace "}".'}):r==="("?o.push({pos:s.from+a,line:u}):r===")"&&(o.length>0?o.pop():e.push({from:s.from+a,to:s.from+a+1,severity:"error",message:'Unmatched closing parenthesis ")".'}))}y&&!l.endsWith("\\")&&e.push({from:W,to:s.to,severity:"error",message:"Unterminated string literal."}),w&&!l.endsWith("\\")&&e.push({from:_,to:s.to,severity:"error",message:"Unterminated regular expression."})}for(const u of c)e.push({from:u.pos,to:u.pos+1,severity:"error",message:'Unclosed brace "{"'});for(const u of o)e.push({from:u.pos,to:u.pos+1,severity:"error",message:'Unclosed parenthesis "("'});return e})}const q=D.EditorView.theme({"&":{backgroundColor:"#0f172a",color:"#f8fafc",fontFamily:"'Fira Code', 'JetBrains Mono', 'Source Code Pro', monospace",fontSize:"14px",borderRadius:"8px"},".cm-content":{caretColor:"#38bdf8"},".cm-cursor, .cm-dropCursor":{borderLeftColor:"#38bdf8"},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:"#1e293b"},".cm-activeLine":{backgroundColor:"rgba(51, 65, 85, 0.4)"},".cm-gutters":{backgroundColor:"#0b1329",color:"#64748b",borderRight:"1px solid #1e293b"},".cm-activeLineGutter":{backgroundColor:"#1e293b",color:"#38bdf8"},".cm-foldPlaceholder":{backgroundColor:"#1e293b",color:"#94a3b8",border:"none",borderRadius:"4px",padding:"0 4px"},".cm-awk-directive":{color:"#c084fc",fontWeight:"bold"},".cm-awk-pattern":{color:"#f59e0b",fontWeight:"bold"},".cm-awk-keyword":{color:"#f43f5e",fontWeight:"bold"},".cm-awk-builtin-var":{color:"#38bdf8",fontWeight:"600"},".cm-awk-field":{color:"#4ade80",fontWeight:"bold"},".cm-awk-builtin-func":{color:"#60a5fa"},".cm-awk-func-def":{color:"#a78bfa",fontWeight:"bold"},".cm-awk-func-call":{color:"#38bdf8"},".cm-awk-string":{color:"#a3e635"},".cm-awk-regex":{color:"#fb923c"},".cm-awk-number":{color:"#facc15"},".cm-awk-comment":{color:"#64748b",fontStyle:"italic"},".cm-awk-operator":{color:"#cbd5e1"},".cm-awk-punctuation":{color:"#94a3b8"}},{dark:!0}),H=D.EditorView.theme({"&":{backgroundColor:"#ffffff",color:"#0f172a",fontFamily:"'Fira Code', 'JetBrains Mono', 'Source Code Pro', monospace",fontSize:"14px",borderRadius:"8px"},".cm-content":{caretColor:"#0284c7"},".cm-gutters":{backgroundColor:"#f8fafc",color:"#94a3b8",borderRight:"1px solid #e2e8f0"},".cm-activeLine":{backgroundColor:"#f1f5f9"},".cm-activeLineGutter":{backgroundColor:"#e2e8f0",color:"#0284c7"},".cm-awk-directive":{color:"#7e22ce",fontWeight:"bold"},".cm-awk-pattern":{color:"#d97706",fontWeight:"bold"},".cm-awk-keyword":{color:"#be123c",fontWeight:"bold"},".cm-awk-builtin-var":{color:"#0369a1",fontWeight:"600"},".cm-awk-field":{color:"#15803d",fontWeight:"bold"},".cm-awk-builtin-func":{color:"#1d4ed8"},".cm-awk-func-def":{color:"#6d28d9",fontWeight:"bold"},".cm-awk-func-call":{color:"#0284c7"},".cm-awk-string":{color:"#4d7c0f"},".cm-awk-regex":{color:"#c2410c"},".cm-awk-number":{color:"#b45309"},".cm-awk-comment":{color:"#64748b",fontStyle:"italic"},".cm-awk-operator":{color:"#334155"},".cm-awk-punctuation":{color:"#475569"}},{dark:!1}),G=R.syntaxHighlighting(R.HighlightStyle.define(M)),L=R.StreamLanguage.define(F);function Y(t={}){const e=[G];return t.autocomplete!==!1&&e.push(g.autocompletion({override:[O]})),t.lint!==!1&&e.push(B()),new R.LanguageSupport(L,e)}exports.GAWK_BUILTIN_FUNCTIONS=x;exports.GAWK_BUILTIN_VARS=T;exports.GAWK_DIRECTIVES=N;exports.GAWK_KEYWORDS=v;exports.GAWK_PATTERNS=S;exports.awk=Y;exports.awkCompletionSource=O;exports.awkDarkTheme=q;exports.awkHighlightStyle=M;exports.awkHighlighting=G;exports.awkLanguage=L;exports.awkLightTheme=H;exports.awkLinter=B;exports.awkStreamParser=F;
|
package/dist/index.d.ts
CHANGED
|
@@ -9,12 +9,12 @@ export * from './theme';
|
|
|
9
9
|
/**
|
|
10
10
|
* Highlighting Style extension for GNU AWK
|
|
11
11
|
*/
|
|
12
|
-
export declare const
|
|
12
|
+
export declare const awkHighlighting: Extension;
|
|
13
13
|
/**
|
|
14
14
|
* CodeMirror 6 StreamLanguage definition for GNU AWK
|
|
15
15
|
*/
|
|
16
|
-
export declare const
|
|
17
|
-
export interface
|
|
16
|
+
export declare const awkLanguage: StreamLanguage<import("./grammar").AwkState>;
|
|
17
|
+
export interface AwkLanguageOptions {
|
|
18
18
|
/**
|
|
19
19
|
* Enable diagnostic linting for syntax errors. Default: true.
|
|
20
20
|
*/
|
|
@@ -25,7 +25,7 @@ export interface GawkLanguageOptions {
|
|
|
25
25
|
autocomplete?: boolean;
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
|
-
* Main CodeMirror 6 plugin extension function for GNU AWK (
|
|
28
|
+
* Main CodeMirror 6 plugin extension function for GNU AWK (awk).
|
|
29
29
|
*
|
|
30
30
|
* @param options Configuration options for linting and autocompletion
|
|
31
31
|
* @returns LanguageSupport instance for CodeMirror 6
|
|
@@ -34,12 +34,12 @@ export interface GawkLanguageOptions {
|
|
|
34
34
|
* ```ts
|
|
35
35
|
* import { EditorView } from '@codemirror/view';
|
|
36
36
|
* import { basicSetup } from 'codemirror';
|
|
37
|
-
* import {
|
|
37
|
+
* import { awk } from '@exercism/codemirror-lang-awk';
|
|
38
38
|
*
|
|
39
39
|
* new EditorView({
|
|
40
40
|
* doc: 'BEGIN { print "Hello, GNU AWK!" }',
|
|
41
|
-
* extensions: [basicSetup,
|
|
41
|
+
* extensions: [basicSetup, awk()]
|
|
42
42
|
* });
|
|
43
43
|
* ```
|
|
44
44
|
*/
|
|
45
|
-
export declare function
|
|
45
|
+
export declare function awk(options?: AwkLanguageOptions): LanguageSupport;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { syntaxHighlighting as F, HighlightStyle as M, StreamLanguage as D, LanguageSupport as B } from "@codemirror/language";
|
|
2
|
-
import { snippet as
|
|
2
|
+
import { snippet as d, autocompletion as O } from "@codemirror/autocomplete";
|
|
3
3
|
import { tags as n } from "@lezer/highlight";
|
|
4
4
|
import { linter as G } from "@codemirror/lint";
|
|
5
5
|
import { EditorView as _ } from "@codemirror/view";
|
|
@@ -346,7 +346,7 @@ const R = /* @__PURE__ */ new Set(["BEGIN", "END", "BEGINFILE", "ENDFILE"]), v =
|
|
|
346
346
|
type: "gawk"
|
|
347
347
|
}
|
|
348
348
|
}, L = {
|
|
349
|
-
name: "
|
|
349
|
+
name: "awk",
|
|
350
350
|
tokenTable: {
|
|
351
351
|
"special(keyword)": n.special(n.keyword),
|
|
352
352
|
"special(variableName)": n.special(n.variableName),
|
|
@@ -428,21 +428,21 @@ const R = /* @__PURE__ */ new Set(["BEGIN", "END", "BEGINFILE", "ENDFILE"]), v =
|
|
|
428
428
|
return e.startsWith("}") ? 0 : 2;
|
|
429
429
|
}
|
|
430
430
|
}, U = [
|
|
431
|
-
{ tag: n.keyword, class: "cm-
|
|
432
|
-
{ tag: n.special(n.keyword), class: "cm-
|
|
433
|
-
{ tag: n.processingInstruction, class: "cm-
|
|
434
|
-
{ tag: n.meta, class: "cm-
|
|
435
|
-
{ tag: n.standard(n.variableName), class: "cm-
|
|
436
|
-
{ tag: n.special(n.variableName), class: "cm-
|
|
437
|
-
{ tag: n.standard(n.name), class: "cm-
|
|
438
|
-
{ tag: n.definition(n.function(n.variableName)), class: "cm-
|
|
439
|
-
{ tag: n.function(n.variableName), class: "cm-
|
|
440
|
-
{ tag: n.string, class: "cm-
|
|
441
|
-
{ tag: n.regexp, class: "cm-
|
|
442
|
-
{ tag: n.number, class: "cm-
|
|
443
|
-
{ tag: n.comment, class: "cm-
|
|
444
|
-
{ tag: n.operator, class: "cm-
|
|
445
|
-
{ tag: n.punctuation, class: "cm-
|
|
431
|
+
{ tag: n.keyword, class: "cm-awk-keyword" },
|
|
432
|
+
{ tag: n.special(n.keyword), class: "cm-awk-pattern" },
|
|
433
|
+
{ tag: n.processingInstruction, class: "cm-awk-directive" },
|
|
434
|
+
{ tag: n.meta, class: "cm-awk-directive" },
|
|
435
|
+
{ tag: n.standard(n.variableName), class: "cm-awk-builtin-var" },
|
|
436
|
+
{ tag: n.special(n.variableName), class: "cm-awk-field" },
|
|
437
|
+
{ tag: n.standard(n.name), class: "cm-awk-builtin-func" },
|
|
438
|
+
{ tag: n.definition(n.function(n.variableName)), class: "cm-awk-func-def" },
|
|
439
|
+
{ tag: n.function(n.variableName), class: "cm-awk-func-call" },
|
|
440
|
+
{ tag: n.string, class: "cm-awk-string" },
|
|
441
|
+
{ tag: n.regexp, class: "cm-awk-regex" },
|
|
442
|
+
{ tag: n.number, class: "cm-awk-number" },
|
|
443
|
+
{ tag: n.comment, class: "cm-awk-comment" },
|
|
444
|
+
{ tag: n.operator, class: "cm-awk-operator" },
|
|
445
|
+
{ tag: n.punctuation, class: "cm-awk-punctuation" }
|
|
446
446
|
], E = Array.from(S).map((t) => ({
|
|
447
447
|
label: t,
|
|
448
448
|
type: "keyword",
|
|
@@ -475,7 +475,7 @@ ${t.doc}`,
|
|
|
475
475
|
label: "BEGIN",
|
|
476
476
|
type: "snippet",
|
|
477
477
|
detail: "BEGIN pattern block",
|
|
478
|
-
apply:
|
|
478
|
+
apply: d(`BEGIN {
|
|
479
479
|
\${1}
|
|
480
480
|
}`),
|
|
481
481
|
boost: 9
|
|
@@ -484,7 +484,7 @@ ${t.doc}`,
|
|
|
484
484
|
label: "END",
|
|
485
485
|
type: "snippet",
|
|
486
486
|
detail: "END pattern block",
|
|
487
|
-
apply:
|
|
487
|
+
apply: d(`END {
|
|
488
488
|
\${1}
|
|
489
489
|
}`),
|
|
490
490
|
boost: 9
|
|
@@ -493,35 +493,35 @@ ${t.doc}`,
|
|
|
493
493
|
label: "function",
|
|
494
494
|
type: "snippet",
|
|
495
495
|
detail: "User-defined function definition",
|
|
496
|
-
apply:
|
|
496
|
+
apply: d("function ${1:name}(${2:args}) {\n ${3}\n}"),
|
|
497
497
|
boost: 9
|
|
498
498
|
},
|
|
499
499
|
{
|
|
500
500
|
label: "for (in)",
|
|
501
501
|
type: "snippet",
|
|
502
502
|
detail: "Array iteration loop",
|
|
503
|
-
apply:
|
|
503
|
+
apply: d("for (${1:key} in ${2:array}) {\n ${3}\n}"),
|
|
504
504
|
boost: 8
|
|
505
505
|
},
|
|
506
506
|
{
|
|
507
507
|
label: "for (i=1..n)",
|
|
508
508
|
type: "snippet",
|
|
509
509
|
detail: "Numeric count loop",
|
|
510
|
-
apply:
|
|
510
|
+
apply: d("for (${1:i} = 1; ${1:i} <= ${2:n}; ${1:i}++) {\n ${3}\n}"),
|
|
511
511
|
boost: 8
|
|
512
512
|
},
|
|
513
513
|
{
|
|
514
514
|
label: "if",
|
|
515
515
|
type: "snippet",
|
|
516
516
|
detail: "Conditional statement",
|
|
517
|
-
apply:
|
|
517
|
+
apply: d("if (${1:condition}) {\n ${2}\n}"),
|
|
518
518
|
boost: 8
|
|
519
519
|
},
|
|
520
520
|
{
|
|
521
521
|
label: "if-else",
|
|
522
522
|
type: "snippet",
|
|
523
523
|
detail: "If-else statement",
|
|
524
|
-
apply:
|
|
524
|
+
apply: d(`if (\${1:condition}) {
|
|
525
525
|
\${2}
|
|
526
526
|
} else {
|
|
527
527
|
\${3}
|
|
@@ -532,21 +532,21 @@ ${t.doc}`,
|
|
|
532
532
|
label: "@include",
|
|
533
533
|
type: "snippet",
|
|
534
534
|
detail: "Include AWK source file",
|
|
535
|
-
apply:
|
|
535
|
+
apply: d('@include "${1:filename.awk}"'),
|
|
536
536
|
boost: 10
|
|
537
537
|
},
|
|
538
538
|
{
|
|
539
539
|
label: "@namespace",
|
|
540
540
|
type: "snippet",
|
|
541
541
|
detail: "GNU AWK Namespace definition",
|
|
542
|
-
apply:
|
|
542
|
+
apply: d('@namespace "${1:name}"'),
|
|
543
543
|
boost: 10
|
|
544
544
|
},
|
|
545
545
|
{
|
|
546
546
|
label: "@load",
|
|
547
547
|
type: "snippet",
|
|
548
548
|
detail: "Load shared extension library",
|
|
549
|
-
apply:
|
|
549
|
+
apply: d('@load "${1:extension}"'),
|
|
550
550
|
boost: 10
|
|
551
551
|
}
|
|
552
552
|
];
|
|
@@ -648,14 +648,14 @@ function q() {
|
|
|
648
648
|
} else {
|
|
649
649
|
const o = l.match(/\b(?:function|func)\s+([A-Za-z_][A-Za-z0-9_]*)/);
|
|
650
650
|
if (o) {
|
|
651
|
-
const
|
|
651
|
+
const p = o[1];
|
|
652
652
|
if (!l.slice(o.index + o[0].length).trim().startsWith("(")) {
|
|
653
|
-
const
|
|
653
|
+
const m = s.from + o.index;
|
|
654
654
|
e.push({
|
|
655
|
-
from:
|
|
656
|
-
to:
|
|
655
|
+
from: m,
|
|
656
|
+
to: m + o[0].length,
|
|
657
657
|
severity: "error",
|
|
658
|
-
message: `Function definition '${
|
|
658
|
+
message: `Function definition '${p}' missing parameter parentheses '()'.`
|
|
659
659
|
});
|
|
660
660
|
}
|
|
661
661
|
}
|
|
@@ -663,26 +663,26 @@ function q() {
|
|
|
663
663
|
}
|
|
664
664
|
let x = !1, C = "", W = 0, y = !1, $ = 0, w = !1;
|
|
665
665
|
for (let r = 0; r < l.length; r++) {
|
|
666
|
-
const o = l[r],
|
|
666
|
+
const o = l[r], p = r > 0 ? l[r - 1] : "";
|
|
667
667
|
if (x)
|
|
668
|
-
o === C &&
|
|
668
|
+
o === C && p !== "\\" && (x = !1);
|
|
669
669
|
else if (y)
|
|
670
|
-
o === "[" &&
|
|
670
|
+
o === "[" && p !== "\\" ? w = !0 : o === "]" && p !== "\\" ? w = !1 : o === "/" && p !== "\\" && !w && (y = !1);
|
|
671
671
|
else if (o === '"')
|
|
672
672
|
x = !0, C = '"', W = s.from + r;
|
|
673
673
|
else if (o === "/") {
|
|
674
|
-
const
|
|
675
|
-
(
|
|
674
|
+
const g = l.slice(0, r).trim();
|
|
675
|
+
(g === "" || /[=~,\(\!\?\:\{\;\+\-\*\%\&\|]$/.test(g) || /\b(print|printf|return|match|sub|gsub|gensub|patsplit|split|if|while)\s*$/i.test(g)) && (y = !0, w = !1, $ = s.from + r);
|
|
676
676
|
} else if (o === "{") {
|
|
677
|
-
const
|
|
678
|
-
for (const
|
|
677
|
+
const g = a.filter((m) => m.line === f);
|
|
678
|
+
for (const m of g)
|
|
679
679
|
e.push({
|
|
680
|
-
from:
|
|
681
|
-
to:
|
|
680
|
+
from: m.pos,
|
|
681
|
+
to: m.pos + 1,
|
|
682
682
|
severity: "error",
|
|
683
683
|
message: 'Unclosed parenthesis "(" in condition before brace.'
|
|
684
684
|
});
|
|
685
|
-
a = a.filter((
|
|
685
|
+
a = a.filter((m) => m.line !== f), c.push({ pos: s.from + r, line: f });
|
|
686
686
|
} else o === "}" ? c.length > 0 ? c.pop() : e.push({
|
|
687
687
|
from: s.from + r,
|
|
688
688
|
to: s.from + r + 1,
|
|
@@ -762,26 +762,26 @@ const ne = _.theme(
|
|
|
762
762
|
padding: "0 4px"
|
|
763
763
|
},
|
|
764
764
|
// GNU AWK Syntax Highlighting Classes
|
|
765
|
-
".cm-
|
|
765
|
+
".cm-awk-directive": { color: "#c084fc", fontWeight: "bold" },
|
|
766
766
|
// @include, @namespace
|
|
767
|
-
".cm-
|
|
767
|
+
".cm-awk-pattern": { color: "#f59e0b", fontWeight: "bold" },
|
|
768
768
|
// BEGIN, END
|
|
769
|
-
".cm-
|
|
769
|
+
".cm-awk-keyword": { color: "#f43f5e", fontWeight: "bold" },
|
|
770
770
|
// if, else, for, while
|
|
771
|
-
".cm-
|
|
771
|
+
".cm-awk-builtin-var": { color: "#38bdf8", fontWeight: "600" },
|
|
772
772
|
// FS, NF, NR, ARGIND
|
|
773
|
-
".cm-
|
|
773
|
+
".cm-awk-field": { color: "#4ade80", fontWeight: "bold" },
|
|
774
774
|
// $0, $1, $NF
|
|
775
|
-
".cm-
|
|
775
|
+
".cm-awk-builtin-func": { color: "#60a5fa" },
|
|
776
776
|
// gensub, patsplit, strftime
|
|
777
|
-
".cm-
|
|
778
|
-
".cm-
|
|
779
|
-
".cm-
|
|
780
|
-
".cm-
|
|
781
|
-
".cm-
|
|
782
|
-
".cm-
|
|
783
|
-
".cm-
|
|
784
|
-
".cm-
|
|
777
|
+
".cm-awk-func-def": { color: "#a78bfa", fontWeight: "bold" },
|
|
778
|
+
".cm-awk-func-call": { color: "#38bdf8" },
|
|
779
|
+
".cm-awk-string": { color: "#a3e635" },
|
|
780
|
+
".cm-awk-regex": { color: "#fb923c" },
|
|
781
|
+
".cm-awk-number": { color: "#facc15" },
|
|
782
|
+
".cm-awk-comment": { color: "#64748b", fontStyle: "italic" },
|
|
783
|
+
".cm-awk-operator": { color: "#cbd5e1" },
|
|
784
|
+
".cm-awk-punctuation": { color: "#94a3b8" }
|
|
785
785
|
},
|
|
786
786
|
{ dark: !0 }
|
|
787
787
|
), ie = _.theme(
|
|
@@ -809,20 +809,20 @@ const ne = _.theme(
|
|
|
809
809
|
color: "#0284c7"
|
|
810
810
|
},
|
|
811
811
|
// Light mode syntax highlighting
|
|
812
|
-
".cm-
|
|
813
|
-
".cm-
|
|
814
|
-
".cm-
|
|
815
|
-
".cm-
|
|
816
|
-
".cm-
|
|
817
|
-
".cm-
|
|
818
|
-
".cm-
|
|
819
|
-
".cm-
|
|
820
|
-
".cm-
|
|
821
|
-
".cm-
|
|
822
|
-
".cm-
|
|
823
|
-
".cm-
|
|
824
|
-
".cm-
|
|
825
|
-
".cm-
|
|
812
|
+
".cm-awk-directive": { color: "#7e22ce", fontWeight: "bold" },
|
|
813
|
+
".cm-awk-pattern": { color: "#d97706", fontWeight: "bold" },
|
|
814
|
+
".cm-awk-keyword": { color: "#be123c", fontWeight: "bold" },
|
|
815
|
+
".cm-awk-builtin-var": { color: "#0369a1", fontWeight: "600" },
|
|
816
|
+
".cm-awk-field": { color: "#15803d", fontWeight: "bold" },
|
|
817
|
+
".cm-awk-builtin-func": { color: "#1d4ed8" },
|
|
818
|
+
".cm-awk-func-def": { color: "#6d28d9", fontWeight: "bold" },
|
|
819
|
+
".cm-awk-func-call": { color: "#0284c7" },
|
|
820
|
+
".cm-awk-string": { color: "#4d7c0f" },
|
|
821
|
+
".cm-awk-regex": { color: "#c2410c" },
|
|
822
|
+
".cm-awk-number": { color: "#b45309" },
|
|
823
|
+
".cm-awk-comment": { color: "#64748b", fontStyle: "italic" },
|
|
824
|
+
".cm-awk-operator": { color: "#334155" },
|
|
825
|
+
".cm-awk-punctuation": { color: "#475569" }
|
|
826
826
|
},
|
|
827
827
|
{ dark: !1 }
|
|
828
828
|
), Y = F(M.define(U)), X = D.define(L);
|
|
@@ -840,13 +840,13 @@ export {
|
|
|
840
840
|
S as GAWK_DIRECTIVES,
|
|
841
841
|
v as GAWK_KEYWORDS,
|
|
842
842
|
R as GAWK_PATTERNS,
|
|
843
|
-
re as
|
|
844
|
-
V as
|
|
845
|
-
ne as
|
|
846
|
-
U as
|
|
847
|
-
Y as
|
|
848
|
-
X as
|
|
849
|
-
ie as
|
|
850
|
-
q as
|
|
851
|
-
L as
|
|
843
|
+
re as awk,
|
|
844
|
+
V as awkCompletionSource,
|
|
845
|
+
ne as awkDarkTheme,
|
|
846
|
+
U as awkHighlightStyle,
|
|
847
|
+
Y as awkHighlighting,
|
|
848
|
+
X as awkLanguage,
|
|
849
|
+
ie as awkLightTheme,
|
|
850
|
+
q as awkLinter,
|
|
851
|
+
L as awkStreamParser
|
|
852
852
|
};
|
package/dist/linter.d.ts
CHANGED
package/dist/theme.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { Extension } from '@codemirror/state';
|
|
|
2
2
|
/**
|
|
3
3
|
* Built-in Modern Dark Visual Theme for GNU AWK Editor
|
|
4
4
|
*/
|
|
5
|
-
export declare const
|
|
5
|
+
export declare const awkDarkTheme: Extension;
|
|
6
6
|
/**
|
|
7
7
|
* Built-in Modern Light Visual Theme for GNU AWK Editor
|
|
8
8
|
*/
|
|
9
|
-
export declare const
|
|
9
|
+
export declare const awkLightTheme: Extension;
|