-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support builtin length function (#57)
- Loading branch information
Showing
5 changed files
with
83 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type * as Value from "../value"; | ||
import * as value from "../value"; | ||
|
||
export type BuiltinFunction = (args: any) => Value.Value; | ||
|
||
const len: BuiltinFunction = (args: Value.Value[]) => { | ||
const arg = args[0]; | ||
if (arg.type === "string") { | ||
const length = arg.value.length; | ||
return value.createNumberValue({ value: length }, String(length), arg.range); | ||
} | ||
|
||
throw new Error(); | ||
}; | ||
|
||
const builtins = { | ||
get(identifier: string): BuiltinFunction | null { | ||
switch (identifier) { | ||
case "길이": | ||
return len; | ||
default: | ||
return null; | ||
} | ||
} | ||
}; | ||
export default builtins; |
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