parse(3f) - [ARGUMENTS:M_kracken] parse user command and store tokens into Language Dictionary (LICENSE:PD)
Synopsis
Description
Options
Returns
Examples
See Also
Author
License
recursive subroutine parse(verb,string,allow,error_return)
character(len=*),intent(in) :: verb character(len=*),intent(in) :: string character(len=*),intent(in) :: allow integer,optional,intent(out) :: error_return
given a string of form
value -var value -var valuedefine variables of form
verb_var(i) = value--var will become verb__var
o values may be in double quotes if they contain alphameric characters o a # signifies the rest of the line is a comment o adjacent double quotes put one double quote into value o processing ends when an unquoted semi-colon or end of string is encountered o the variable name for the first value is verb_init (often verb_oo) o leading and trailing blanks are removed from values o call it once to give defaults o call it again and vars without values are set to null strings
VERB command name to process STRING string is character input string with first verb removed (options + other commands) ALLOW flag to allow or disallow new VERB_KEYWORD name being added. Should be
o o
o o
That is, ff add or append and the value is not blank
it will be APPENDED to the current value. If define or
to it.
RETURNS
ERROR_RETURN error code. If zero, no error occurred
sample program:
program demo_parse use M_kracken, only : parse, sget, iget, rget use M_strings, only : chomp implicit none character(len=:),allocatable :: verb character(len=*),parameter :: delimiters= ;, integer :: i integer :: ierr character(len=132) :: line character(len=132),parameter :: commands(5)= [character(len=132) :: & start -i 10 -message this is a message, & end -i 20 -j 30 -k 55.55 , & list, & help -oo, & end -i 44.44 ] do i=1,size(commands) line=commands(i) ! need mutable line if(chomp(line,verb,delimiters).ge. 0)then call parse(verb,line,add,ierr) write(*,*)do whatever a //verb// command does select case(verb) case(start) write(*,*)trim(sget(start_i)) write(*,*)trim(sget(start_message)) case(end) write(*,*)iget(end_i) write(*,*)iget(end_j) write(*,*)rget(end_k) case(list) write(*,*)list things case(help) write(*,*)show help text endselect endif enddo ! look at some of the values as strings or numbers write(*,*)trim(sget(start_i)) write(*,*)trim(sget(start_message)) write(*,*)iget(end_i) write(*,*)iget(end_j) write(*,*)rget(end_k) end program demo_parseResults:
do whatever a start command does 10 this is a message do whatever a end command does 20 30 55.5499992 do whatever a list command does list things do whatever a help command does show help text do whatever a end command does 44 30 55.5499992 10 this is a message 44 30 55.5499992
dget(3f), dgets(3f), iget(3f), igets(3f), lget(3f), lgets(3f), rget(3f), rgets(3f), sget(3f), sgets(3f), retrev(3f)
M_kracken(3f), kracken(3f) parse(3f), dissect(3f), store(3f), setprompts(3f), show(3f)
John S. Urban
Public Domain
Nemo Release 3.1 | parse (3) | February 23, 2025 |