vivjson.standard (2025-03-30)
index
https://github.com/benesult/vivjson-python/tree/main/vivjson/standard.py

Standard library for VivJson
 
- std_if: if (condition) { operations }
- std_do: do { operations }
- std_while: while (condition) { operations }
- std_for: for ( ... ) { operations }
- std_int: int(value)
- std_float: float(value)
- std_string: string(value)
- std_len: len(value)
- std_insert: insert(array, index, value)
- std_strip: strip(value)
- std_type: type(value)
- std_print: print(value [, value, ...])
 
Refer to:
- "Crafting Interpreters"
  https://craftinginterpreters.com/
Note that this code is made from scratch. The source code
of the above WEB site is not used.
 
Environment:
- Python 3.9 or later
 
License:
Copyright 2025 benesult
 
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
 
    http://www.apache.org/licenses/LICENSE-2.0
 
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

 
Classes
       
builtins.object
Standard

 
class Standard(builtins.object)
    Standard library class
 
Attributes:
    PREFIX (str): The prefix of method. It is defined as "std_".
                  Almost methods of this library have general name like
                  "print", "if", and so on. It is confused host language's
                  functions and statements.
                  So this prefix is added: std_print, std_if, ...
 
  Static methods defined here:
get_method(name: str)
Get standard library's method.
 
Args:
    name (str): Method name
 
Returns:
    function or NoneType: Standard library's method if it is
                          available, None otherwise.
std_do(evaluator, call, config=None)
do { operations }
 
Args:
    evaluator (Evaluator): Evaluator instance
    call (Call): The information of calling.
                 call.arguments.values is a list of
                 1 statement.
                    1st (Block): A list of operations as Block
    config (Config or NoneType, optional): Configuration if
                                           needed.
 
Returns:
    Any: Result of Block evaluation
 
Raises:
    EvaluateError: It is happen if evaluation is failed.
std_float(evaluator, call, config=None)
float(value)
 
Args:
    evaluator (Evaluator): Evaluator instance
    call (Call): The information of calling.
                 call.arguments.values is a list of
                 1 statement.
                    1st: A number whose type is int, float,
                         or string.
    config (Config or NoneType, optional): Configuration if
                                           needed.
 
Returns:
    float: Number whose type is converted to float.
 
Raises:
    EvaluateError: It is happen if evaluation is failed.
std_for(evaluator, call, config=None)
for ( ... ) { operations }
 
Example:
- for (init; condition; update) { operations }
- for (; condition; update) { operations }
- for (;; update) { operations }
- for (;;) { operations }
- for () { operations }
- for (value in list) { operations }
- for (init; condition; update; { operations })
 
Args:
    evaluator (Evaluator): Evaluator instance
    call (Call): The information of calling.
                 call.arguments.values is a list of
                 statements.
                 When a list has 4 statements:
                     1st (Statement): initial operation
                     2nd (Statement): condition
                     3rd (Statement): update operation
                     4th (Block): A list of operations as Block
                 When a list has 2 statements:
                     1st (Binary): value in list
                     2nd (Block): A list of operations as Block
    config (Config or NoneType, optional): Configuration if
                                           needed.
 
Returns:
    Any: Result of Block evaluation
 
Raises:
    EvaluateError: It is happen if evaluation is failed.
std_if(evaluator, call, config=None)
if/elseif/else
 
if (...) {...} [ elseif (...) {...} ... ] else {...}
 
For example,
    if (...) {...}
       ----- -----
         |     |
         |   call.arguments.values[1]
       call.arguments.values[0]
 
    if (...) {...} else {...}
       ----- -----      -----
         |     |          |
         |     |        call.arguments.values[3]
         |     |    call.arguments.values[2] is always true.
         |   call.arguments.values[1]
       call.arguments.values[0]
 
    if (...) {...} elif (...) {...} else {...}
       ----- -----      ----- -----      -----
         |     |          |     |          |
         |     |          |     |      call.arguments.values[5]
         |     |          |     |  call.arguments.values[4] is
         |     |          |     |  always true.
         |     |          |   call.arguments.values[3]
         |     |        call.arguments.values[2]
         |   call.arguments.values[1]
       call.arguments.values[0]
 
Args:
    evaluator (Evaluator): Evaluator instance
    call (Call): The information of calling.
                 call.arguments.values is a list of
                 2 x n statements.
                    2 x n: condition
                    2 x n + 1: A list of operations as Block
    config (Config or NoneType, optional): Configuration if
                                           needed.
 
Returns:
    Any: Result of Block evaluation
 
Raises:
    EvaluateError: It is happen if evaluation is failed.
std_insert(evaluator, call, config=None)
insert(array, index, value)
 
Insert a value into the array.
Inserted position can be given with "index".
 
Args:
    evaluator (Evaluator): Evaluator instance
    call (Call): The information of calling.
                 call.arguments.values is a list of
                 3 statements.
                    1st (Array): An array
                    2nd (Statement): An index
                    3rd (Statement): A value
    config (Config or NoneType, optional): Configuration if
                                           needed.
 
Returns:
    NoneType: It is always None.
 
Raises:
    EvaluateError: It is happen if evaluation is failed.
std_int(evaluator, call, config=None)
int(value)
 
Args:
    evaluator (Evaluator): Evaluator instance
    call (Call): The information of calling.
                 call.arguments.values is a list of
                 1 statement.
                    1st: A number whose type is int, float,
                         or string.
    config (Config or NoneType, optional): Configuration if
                                           needed.
 
Returns:
    int: Number whose type is converted to int.
 
Raises:
    EvaluateError: It is happen if evaluation is failed.
std_len(evaluator, call, config=None)
len(value)
 
Args:
    evaluator (Evaluator): Evaluator instance
    call (Call): The information of calling.
                 call.arguments.values is a list of
                 1 statement.
                    1st: An array, a block, or a string.
    config (Config or NoneType, optional): Configuration if
                                           needed.
 
Returns:
    int: Length of array, block, or string.
 
Raises:
    EvaluateError: It is happen if evaluation is failed.
std_print(evaluator, call, config=None)
print(value [, value, ...])
 
Args:
    evaluator (Evaluator): Evaluator instance
    call (Call): The information of calling.
                 call.arguments.values is a list of
                 statements that have printable values.
    config (Config or NoneType, optional): Configuration if
                                           needed.
 
Returns:
    NoneType: It is always None.
 
Raises:
    EvaluateError: It is happen if evaluation is failed.
std_string(evaluator, call, config=None)
string(value)
 
Args:
    evaluator (Evaluator): Evaluator instance
    call (Call): The information of calling.
                 call.arguments.values is a list of
                 1 statement.
                    1st: Any value
    config (Config or NoneType, optional): Configuration if
                                           needed.
 
Returns:
    str: Text that is converted from the given value.
 
Raises:
    EvaluateError: It is happen if evaluation is failed.
std_strip(evaluator, call, config=None)
strip(value)
 
Remove white-space and new line code from the head/tail.
Double-byte space (Full-width space) is also removed.
 
Args:
    evaluator (Evaluator): Evaluator instance
    call (Call): The information of calling.
                 call.arguments.values is a list of
                 1 statement.
                    1st: A string.
    config (Config or NoneType, optional): Configuration if
                                           needed.
 
Returns:
    str or NoneType: Type is represented as text format.
 
Raises:
    EvaluateError: It is happen if evaluation is failed.
std_type(evaluator, call, config=None)
type(value)
 
Args:
    evaluator (Evaluator): Evaluator instance
    call (Call): The information of calling.
                 call.arguments.values is a list of
                 1 statement.
                    1st: Any value.
    config (Config or NoneType, optional): Configuration if
                                           needed.
 
Returns:
    str or NoneType: Type is represented as text format.
                     - "int"
                     - "float"
                     - "string"
                     - "boolean"
                     - "null"
                     - "array"
                     - "block"
                     - "function"
                     None is returned for other type.
 
Raises:
    EvaluateError: It is happen if evaluation is failed.
std_while(evaluator, call, config=None)
while (condition) { operations }
 
Args:
    evaluator (Evaluator): Evaluator instance
    call (Call): The information of calling.
                 call.arguments.values is a list of
                 2 statements.
                    1st (Statement): condition
                    2nd (Block): A list of operations as Block
    config (Config or NoneType, optional): Configuration if
                                           needed.
 
Returns:
    Any: Result of Block evaluation
 
Raises:
    EvaluateError: It is happen if evaluation is failed.

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes defined here:
PREFIX = 'std_'

 
Author
        Fumiaki Motegi <motegi@benesult.com>