time-link / timelink-kleio

Provides translation of files in Kleio notation into XML and other formats. Part of Timelink.
1 stars 0 forks source link

Allow for stru files to import other stru files #12

Open joaquimrcarvalho opened 1 year ago

joaquimrcarvalho commented 1 year ago

Implement a new command for str files called read with a parameter name specifying the file to read.

read name=gacto2.str

This command is processed as follows:

(locate(NameParValue, Path) ->
    (
        seeing(Current),   % Check current_input/1 and set_input/1
        push(Current),
        see(Path)
    )
    ;
    assert_error(['Could not find file',NameParValue])

When eof is detected reading is returned to the last pushed file if any, or end processing.

TopLevel.pl

readlines(FileType):-
    setcount(line,1),
    repeat,
     readline2(List,Last), % get the character List %
     inccount(line,L),
     get_tokens(FileType,List,Tokens),% lexical analysis %
     get_string(List,Line), % make a string %
     set_prop(line,number,L),
     set_prop(line,text,Line),
     processLine(FileType,Tokens), % parsing and execution%
      % NEW
     ((was_read_command(FileType,Tokens,NewFile) ->
         (seeing(Current),push(Current),see(NewFile))
        ;
         true
     )
     % what about line numbers?
     echo_line(L,Line),
     set_prop(line,last,Line),
     check_eof(Last,EOF),
    % Changed
    (EOF = eof -> 
        (pop(previous) ->
            (Seen(current), see(previous),fail) %continue previous
        ;
        true % nothing more to process
        )
    ; % not end of file check errors
        not(errors:check_continuation)
    ),
    processLine(FileType,eof),!. % end of file reached %

check_eof(eof):- % eof and no previous file on stack
       empty_file_stack, !.
check_eof(eof):-
       get_value(file_stack,[File|Rest]),
       get_value(stru_file,Current_file),
       close(Current_file),
      file_base_name(Current_file,Basename),
      report([nl,write('Finished included structure:'),write(Basename),nl]),
       put_value(file_stack,Rest),
       open_file_read(File),
       set_input(File).
empty_file_stack:-
    get_value(file_stack,[]),!.

How to specify locations of the inserted files.

The most common usage scenario will be that a file specifying the structure of a new source incorporates the base definitions of the source oriented model

Use python style notation where fonder are separated by "." and the last token is expected to by a file name with extension "str".

escrituras.str

note doc Estrutura para escrituras
note read the default stru for portuguese acts
read name=system.pt.base

system/pt/base.str

note doc Grupos bases documentos portugueses
note read os conceitos básicos
read name=system.base

Example of user token

user_token('0f7afbb96c08ebbc3347d76f156bf560c2e9d73b',
        'ilhavo-editor',
        [ comment('MHK generated token for ilhavo-editor'),
            api([ sources,
                files,
                structures,
                translations,
                identifications,
                upload,
                delete,
                mkdir
                ]),
            sources('projects/ilhavo-editor/sources'),
            structures('projects/ilhavo-editor/structures')
        ])

In requests with this token:

system.gacto2"              : KLEIO_STRU_DIR/gacto2.str
sources.stru.chronolgy"    : /kleio-home/projects/ilhavo-editor/sources/stru/chronology.str
structures.paroquiais.batismos.mybapt"         : /kleio-home/projects/ilhavo-editor/structures/paroquiais/mybapts.str

    Nos ficheiros stru a leitura de outra estrutura seria feira com o comando read/lege

    read name=system.pt.base

Note that KLEIO_STRU_DIR can Be set in a environment variable of the server and defaults to KLEIO_HOME_DIR/system/conf/kleio/stru/

To allow for incremental definitions if group A is in part of group X and group B specializes Group A then Group B would be allowed as part of X.

part name=historical-source;
       part=historical-act

part name=fonte; source=historical-source
part name=bap; source=historical-act

...

fonte$...
    bap$...