Urara-Blog/node_modules/.pnpm-store/v3/files/e1/da8e6d39323c7a148609a65bd21801b9ac375bfa02e3af9f4d8efbc5b0589918dbd335ba21c41b03c2e7583ec51d8ef14551118aef6f71e64dd1bb543645fa
2022-08-14 01:14:53 +08:00

41 lines
974 B
Text

import {
Function as FunctionToken,
RightParenthesis
} from '../../tokenizer/index.js';
export const name = 'Function';
export const walkContext = 'function';
export const structure = {
name: String,
children: [[]]
};
// <function-token> <sequence> )
export function parse(readSequence, recognizer) {
const start = this.tokenStart;
const name = this.consumeFunctionName();
const nameLowerCase = name.toLowerCase();
let children;
children = recognizer.hasOwnProperty(nameLowerCase)
? recognizer[nameLowerCase].call(this, recognizer)
: readSequence.call(this, recognizer);
if (!this.eof) {
this.eat(RightParenthesis);
}
return {
type: 'Function',
loc: this.getLocation(start, this.tokenStart),
name,
children
};
}
export function generate(node) {
this.token(FunctionToken, node.name + '(');
this.children(node);
this.token(RightParenthesis, ')');
}