Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
597 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Doc, Param } from "../doc"; | ||
import VariableBlock from "./VariableBlock"; | ||
|
||
/** | ||
* Represents an var block for `foreach` | ||
*/ | ||
export default class ForeachBlock extends VariableBlock | ||
{ | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected pattern:RegExp = /^\s*foreach\s*\(.*?as\s+(\$[a-z_][a-z0-9_]*\s*=>\s*)?(\$[a-z_][a-z0-9_]*)\s*\)/im; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public parse():Doc | ||
{ | ||
let params = this.match(); | ||
return this.parseVar(params[2]); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Block } from "../block"; | ||
import { Doc, Param } from "../doc"; | ||
import Config from "../util/config"; | ||
import TypeUtil from "../util/TypeUtil"; | ||
|
||
/** | ||
* Represents an var block | ||
*/ | ||
export default class VariableBlock extends Block | ||
{ | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected pattern:RegExp = /^\s*(\$[a-z0-9_]+)\s*\=?\s*([^;]*)/im; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public parse():Doc | ||
{ | ||
let params = this.match(); | ||
return this.parseVar(params[1], params[2]); | ||
} | ||
|
||
/** | ||
* parse | ||
* | ||
* @param key e.g.`$key` | ||
* @param value | ||
* @returns | ||
*/ | ||
protected parseVar(key: string, value: any=undefined): Doc | ||
{ | ||
let doc = new Doc(key.substring(1)); | ||
if (value) { | ||
doc.var = TypeUtil.instance.getTypeFromValue(value); | ||
} else { | ||
doc.var = TypeUtil.instance.getDefaultType(); | ||
} | ||
doc.inline = true; | ||
|
||
return doc; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Doc, Param } from "../doc"; | ||
import VariableBlock from "./VariableBlock"; | ||
|
||
/** | ||
* Represents an var block for `while` | ||
*/ | ||
export default class WhileBlock extends VariableBlock | ||
{ | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected pattern:RegExp = /^\s*while\s*\((\$[a-z0-9_]+)\s*=(?!=)/im; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public parse():Doc | ||
{ | ||
let params = this.match(); | ||
return this.parseVar(params[1]); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.