types_checking.anubis 1.34 KB
/*
 * Created by PyramIDE.
 * User: フランスのトトロ aka (David RENÉ) 
 * Date: 21/01/2017
 * Time: 00:36
 * © Calexium 
 */

read densaku_lib/types/ds_types.anubis
read system/string.anubis
read tools/basis.anubis

define Bool
  is_upper_case_start
  (
    String  name
  )=
  if nth(0, name) is
  {
    failure       then println("Can't get the first character of "+name);false,
    success(char) then
      if (char +=< 90) & (64 +< char) then 
        true
      else
        println("Type name ["+name+"] doesn't start with upper case");false
  }
.
  
define Maybe(One)
/* Check if the type name start with upper case and if that type doesn't already exists
 */
  check_name
  (
    List(DS_Type) types,             //types description
    List(String)  so_far,
    Maybe(One)    return
  )=
  if types is
  {
    []      then return,
    [h . t] then
      since h is ds_type(type_name, _, tk_alts),
      if is_upper_case_start(type_name) then
        check_name(t, [], return)
      else  
        check_name(t, [], failure)
  }
.
  
public define Maybe(One)
  check_types
  (
    List(DS_Type)     types             //types description
  )=
  //check if name start with upper case
  if check_name(types, [], success(unique)) is
  {
    failure     then  println("Error(s) in type checking "); failure
    success(_)  then  
      success(unique)
  }
.