[UP]


Manual Reference Pages  - parse (3)

NAME

parse(3f) - [ARGUMENTS:M_kracken] parse user command and store tokens into Language Dictionary (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Returns
Example
See Also
Author
License

SYNOPSIS

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

DESCRIPTION

given a string of form

     value  -var value -var value

define 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

OPTIONS

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

    NEW VARIABLES ARE ALLOWED

o
o

    NO NEW VARIABLES ARE ALLOWED

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

EXAMPLE

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_parse

Results:

    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

SEE ALSO

M_kracken(3f),
  kracken(3f)
dget(3f), dgets(3f), iget(3f), igets(3f), lget(3f), lgets(3f), rget(3f), rgets(3f), sget(3f), sgets(3f), retrev(3f)

parse(3f), dissect(3f), store(3f), setprompts(3f), show(3f)

AUTHOR

John S. Urban

LICENSE

Public Domain


parse (3) March 11, 2021
Generated by manServer 1.08 from 6d060895-0b4a-487e-833a-d82e1f587e8b using man macros.