Skip to content

Commit

Permalink
Add CONFIGURATION.md
Browse files Browse the repository at this point in the history
  • Loading branch information
valtzu committed Feb 16, 2025
1 parent 200bc71 commit 0911566
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 16 deletions.
108 changes: 108 additions & 0 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@

## Enum

- [ELScalar](#elscalar)

### ELScalar



| Property | Type | Description |
| ---------- | ---------- | ---------- |
| `Bool` | `'bool'` | Equivalent to PHP `bool` |
| `Number` | `'number'` | Equivalent to PHP `int` or `float` |
| `String` | `'string'` | Equivalent to PHP `string` |
| `Null` | `'null'` | Equivalent to PHP `null` |
| `Any` | `'any'` | Equivalent to PHP `mixed` |


## Interfaces

- [ExpressionLanguageConfig](#expressionlanguageconfig)
- [ELType](#eltype)
- [ELIdentifier](#elidentifier)
- [ELFunction](#elfunction)
- [ELParameter](#elparameter)
- [ELKeyword](#elkeyword)

### ExpressionLanguageConfig

The configuration object that is passed to `expressionlanguage` function

| Property | Type | Description |
| ---------- | ---------- | ---------- |
| `types` | `{ [key: string]: ELType; } or undefined` | Type definitions used in `identifiers` and `functions` |
| `identifiers` | `ELIdentifier[] or undefined` | Top-level variables |
| `functions` | `ELFunction[] or undefined` | Top-level functions |


### ELType



| Property | Type | Description |
| ---------- | ---------- | ---------- |
| `identifiers` | `ELIdentifier[] or undefined` | Properties of the object |
| `functions` | `ELFunction[] or undefined` | Methods of the object |
| `info` | `string or undefined` | |


### ELIdentifier

Represents a variable or a property of an object

| Property | Type | Description |
| ---------- | ---------- | ---------- |
| `name` | `string` | |
| `detail` | `string or undefined` | If set, this is shown instead of `type` |
| `info` | `string or undefined` | Text to show in hover tooltip, autocomplete etc. |
| `type` | `string[] or undefined` | All possible types for this identifier |


### ELFunction

Represents a function or a method of an object

| Property | Type | Description |
| ---------- | ---------- | ---------- |
| `name` | `string` | |
| `args` | `ELParameter[] or undefined` | |
| `info` | `string or undefined` | |
| `returnType` | `string[] or undefined` | |


### ELParameter



| Property | Type | Description |
| ---------- | ---------- | ---------- |
| `name` | `string` | |
| `type` | `string[] or undefined` | |
| `info` | `string or undefined` | |
| `optional` | `boolean or undefined` | |


### ELKeyword



| Property | Type | Description |
| ---------- | ---------- | ---------- |
| `name` | `string` | |
| `detail` | `string or undefined` | |
| `info` | `string or undefined` | |


## Types

- [ELTypeName](#eltypename)

### ELTypeName

One of predefined types ({@link ELScalar}) or a custom type from {@link ExpressionLanguageConfig.types}

| Type | Type |
| ---------- | ---------- |
| `ELTypeName` | `ELScalar or string` |

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ yarn add @valtzu/codemirror-lang-el

---

### Configuration

See [CONFIGURATION.md](CONFIGURATION.md)

### Example

[Live demo](https://jsfiddle.net/turse2xq/)
Expand Down
55 changes: 39 additions & 16 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
// generate CONFIGURATION.md from this file by running "tsdoc --src=src/types.ts --dest=CONFIGURATION.md --noemoji --types"

/**
* The configuration object that is passed to `expressionlanguage` function
*/
export interface ExpressionLanguageConfig {
/** Type definitions used in `identifiers` & `functions` */
types?: { [key: string]: ELType };
/** Top-level variables */
identifiers?: ELIdentifier[];
/** Top-level functions */
functions?: ELFunction[];
}

export interface ELType {
/** Properties of the object */
identifiers?: ELIdentifier[];
/** Methods of the object */
functions?: ELFunction[];
info?: string;
}

/**
* Represents a variable or a property of an object
*/
export interface ELIdentifier {
name: string;
/** If set, this is shown instead of `type` */
detail?: string;
/** Text to show in hover tooltip, autocomplete etc. */
info?: string;
type?: string[];
/** All possible types for this identifier */
type?: ELTypeName[];
}

/**
Expand All @@ -15,38 +40,36 @@ export interface ELFunction {
name: string;
args?: ELParameter[];
info?: string;
returnType?: string[];
returnType?: ELTypeName[];
}

export interface ELParameter {
name: string;
type?: string[];
type?: ELTypeName[];
info?: string;
optional?: boolean;
}

export interface ELType {
identifiers?: ELIdentifier[];
functions?: ELFunction[];
info?: string;
}

export interface ExpressionLanguageConfig {
types?: { [key: string]: ELType };
identifiers?: ELIdentifier[];
functions?: ELFunction[];
}

export interface ELKeyword {
name: string;
detail?: string;
info?: string;
}

export enum ELScalar {
/** Equivalent to PHP `bool` */
Bool = 'bool',
/** Equivalent to PHP `int` or `float` */
Number = 'number',
/** Equivalent to PHP `string` */
String = 'string',
/** Equivalent to PHP `null` */
Null = 'null',
Any = 'any', // not really scalar but meh
/** Equivalent to PHP `mixed` */
Any = 'any',
}

/**
* One of predefined types (`ELScalar`) or a custom type from `ExpressionLanguageConfig.types`
*/
export type ELTypeName = ELScalar | string;

0 comments on commit 0911566

Please sign in to comment.