Skip to content

Commit 8eb2061

Browse files
committed
Add #setting
1 parent 3716087 commit 8eb2061

File tree

12 files changed

+956
-15
lines changed

12 files changed

+956
-15
lines changed

.vscode/launch.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@
1414
"type": "node",
1515
"request": "launch",
1616
"name": "Mocha Tests",
17-
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
17+
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
1818
"args": [
1919
"-u",
2020
"tdd",
2121
"--timeout",
2222
"999999",
2323
"--colors",
24-
"${workspaceRoot}/test/*.ts"
24+
"${workspaceFolder}/test/*.ts"
2525
],
2626
"internalConsoleOptions": "openOnSessionStart"
2727
},
2828
{
2929
"type": "node",
3030
"request": "launch",
3131
"name": "Update Ast",
32-
"program": "${workspaceRoot}/scripts/update-ast",
32+
"program": "${workspaceFolder}/scripts/update-ast",
3333
"internalConsoleOptions": "openOnSessionStart"
3434
}
3535
]

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ console.log(data.tokens)
4545
- interpolations `${foo}`
4646
- methods, i.e. `${avg(3, 5)}`
4747
- executing macro
48-
- directives: http://freemarker.sourceforge.net/docs/ref_directives.html
48+
- directives: http://freemarker.sourceforge.net/docs/ref_directives.html
4949
- `#attempt`
5050
- `#recover`
5151
- `#assign`
@@ -68,6 +68,7 @@ console.log(data.tokens)
6868
- `#return`
6969
- `#noparse`, `#noParse`
7070
- `#stop`
71+
- `#setting`
7172
- comments `<#-- -->`
7273

7374
## TODO:
@@ -91,6 +92,5 @@ console.log(data.tokens)
9192
- `#nt`
9293
- `#recurse`
9394
- `#rt`
94-
- `#setting`
9595
- `#t`
9696
- `#visit`

src/enum/NodeNames.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ enum NodeNames {
2424
Compress = 'Compress',
2525
Import = 'Import',
2626
Stop = 'Stop',
27+
Setting = 'Setting',
2728

2829
// Not supported
2930
// Escape = 'Escape',
@@ -35,7 +36,6 @@ enum NodeNames {
3536
// Nested = 'Nested',
3637
// Nt = 'Nt',
3738
// Rt = 'Rt',
38-
// Setting = 'Setting',
3939
// T = 'T',
4040
}
4141

src/types/Nodes/AbstractNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default abstract class AbstractNode implements ILoc {
1717
this.end = token.end
1818
}
1919

20-
public addToNode (child : AbstractNode) {
20+
public addToNode (child : AbstractNode) : void {
2121
throw new NodeError(`Node ${this.type} can't contain ${child.type}`, child)
2222
}
2323
}

src/types/Nodes/ISetting.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import NodeNames from '../../enum/NodeNames'
2+
import ParamNames from '../../enum/ParamNames'
3+
import NodeError from '../../errors/NodeError'
4+
import { parseAssignParams } from '../../utils/Params'
5+
import { IAssignmentExpression } from '../Params'
6+
import { IToken } from '../Tokens'
7+
import AbstractNode from './AbstractNode'
8+
9+
export default class ISetting extends AbstractNode {
10+
public expression : IAssignmentExpression
11+
12+
constructor (token : IToken) {
13+
super(NodeNames.Setting, token)
14+
const params = parseAssignParams(token.start, token.end, token.params)
15+
if (params && params.length === 1) {
16+
const expression = params[0]
17+
if (expression.type === ParamNames.AssignmentExpression) {
18+
this.expression = expression
19+
return
20+
}
21+
}
22+
throw new NodeError(`Invalid parameters in ${NodeNames.Setting}`, token)
23+
}
24+
}

src/types/Tokens.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { ENodeType } from '../Symbols'
22

3+
export interface ILoc {
4+
start : number
5+
end : number
6+
}
7+
38
export interface IToken extends ILoc {
49
type : ENodeType
510
startTag? : string
@@ -8,8 +13,3 @@ export interface IToken extends ILoc {
813
text : string
914
isClose : boolean
1015
}
11-
12-
export interface ILoc {
13-
start : number
14-
end : number
15-
}

src/utils/Directives.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const Directives : IDirectivesTypes = {
2929
// recurse: NodeNames.Recurse,
3030
return: NodeNames.Return,
3131
// rt: NodeNames.Rt,
32-
// setting: NodeNames.Setting,
32+
setting: NodeNames.Setting,
3333
stop: NodeNames.Stop,
3434
switch: NodeNames.Switch,
3535
case: NodeNames.SwitchCase,

src/utils/Nodes.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import ILocal from '../types/Nodes/ILocal'
1717
import IMacro from '../types/Nodes/IMacro'
1818
import IMacroCall from '../types/Nodes/IMacroCall'
1919
import IReturn from '../types/Nodes/IReturn'
20+
import ISetting from '../types/Nodes/ISetting'
2021
import IStop from '../types/Nodes/IStop'
2122
import ISwitch from '../types/Nodes/ISwitch'
2223
import ISwitchCase from '../types/Nodes/ISwitchCase'
@@ -126,6 +127,9 @@ const Nodes : INodes = {
126127
[NodeNames.Stop] (token : IToken) : IStop {
127128
return new IStop(token)
128129
},
130+
[NodeNames.Setting] (token : IToken) : ISetting {
131+
return new ISetting(token)
132+
},
129133
}
130134

131135
export default Nodes

src/utils/Params.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import ParamNames from '../enum/ParamNames'
22
import NodeError from '../errors/NodeError'
33
import { ParamsParser } from '../ParamsParser'
4-
import { AllParamTypes, IAssignmentExpression, IExpression, IIdentifier, IUpdateExpression } from '../types/Params'
4+
import { AllParamTypes, IAssignmentExpression, IIdentifier, IUpdateExpression } from '../types/Params'
55

66
function cIdentifier (name : string) : IIdentifier {
77
return { type: ParamNames.Identifier, name }
88
}
99

10-
export function parseAssignParams (start : number, end : number, params? : string) : IExpression[] | undefined {
10+
export function parseAssignParams (start : number, end : number, params? : string) : AllParamTypes[] | undefined {
1111
if (!params) {
1212
throw new NodeError('Assign require params', { start, end })
1313
}

0 commit comments

Comments
 (0)