/* * Created by PyramIDE. * User: フランスのトトロ aka (David RENÉ) * Date: 07/06/2016 * Time: 23:15 * © Calexium */ read yaml_type.anubis read tools/streams.anubis read tools/string.anubis read system/string.anubis public define Maybe(YAML_Document) get_yaml_document_content ( Stream s, YAML_Document doc )= if read_line(s) is { failure then success(doc), success(_line) then with line = trim(_line), //check for comment if start_with(line, "#") then //println("skipping comment ["+line+"]"); get_yaml_document_content(s, doc) //check for blank line else if length(line) = 0 then //println("skipping blank line"); get_yaml_document_content(s, doc) //check for item of the list else if start_with(line, "- ") then println("list item ["+line+"]"); get_yaml_document_content(s, doc) //check for entry of the map else if find(":", line, 0) is { failure then println("unrecognize line ["+line+"]"); get_yaml_document_content(s, doc), success(pos) then println("map entry ["+line+"]"); get_yaml_document_content(s, doc) } }. public define Maybe(YAML_Document) get_yaml_document ( Stream s, )= if read_line(s) is { failure then failure, success(line) then if start_with(line, "---") then println("Start parsing YAML document"); get_yaml_document_content(s, yaml_document(var([]))) else get_yaml_document(s) }. public define YAML parse_YAML_file ( Stream s, Var(List(YAML_Document)) docs )= if get_yaml_document(s) is { failure then yaml(var(reverse(*docs))), success(doc) then docs <- [doc . *docs]; parse_YAML_file(s, docs) }. public define YAML parse_YAML_file ( Stream s )= if read_line(s) is { failure then yaml(var([])), success(line) then if start_with(line, "%YAML 1.1") then println("%YAML 1.1 file"); parse_YAML_file(s, var([])) else yaml(var([])) }.