fortrangoingonforty/fortsh / f5614fe

Browse files

add word_len to case_data_t to preserve whitespace-only case values

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
f5614feabf40db978f34f8a2fc0fe3ec227337d4
Parents
7cadb54
Tree
4131a6b

2 changed files

StatusFile+-
M src/parsing/command_tree.f90 8 1
M src/parsing/grammar_parser.f90 4 2
src/parsing/command_tree.f90modified
@@ -167,6 +167,7 @@ module command_tree
167167
   ! =====================================
168168
   type :: case_data_t
169169
     character(len=MAX_TOKEN_LEN) :: word                      ! case $word in
170
+    integer :: word_len = 0                                   ! Actual word length (for whitespace-only values)
170171
     type(case_item_t), allocatable :: items(:)                ! Case items
171172
     integer :: num_items = 0
172173
   end type case_data_t
@@ -312,16 +313,22 @@ contains
312313
     node%for_loop%body => body
313314
   end function create_for_loop
314315
 
315
-  function create_case_statement(word, items, num_items) result(node)
316
+  function create_case_statement(word, items, num_items, word_len) result(node)
316317
     character(len=*), intent(in) :: word
317318
     type(case_item_t), intent(in) :: items(:)
318319
     integer, intent(in) :: num_items
320
+    integer, intent(in), optional :: word_len
319321
     type(command_node_t), pointer :: node
320322
 
321323
     allocate(node)
322324
     node%node_type = NODE_CASE
323325
     allocate(node%case_stmt)
324326
     node%case_stmt%word = word
327
+    if (present(word_len)) then
328
+      node%case_stmt%word_len = word_len
329
+    else
330
+      node%case_stmt%word_len = len_trim(word)
331
+    end if
325332
     allocate(node%case_stmt%items(num_items))
326333
     node%case_stmt%items = items
327334
     node%case_stmt%num_items = num_items
src/parsing/grammar_parser.f90modified
@@ -861,7 +861,7 @@ contains
861861
     type(command_node_t), pointer :: node, case_cmds
862862
     character(len=MAX_TOKEN_LEN) :: word, patterns(10)
863863
     type(case_item_t) :: items(20)
864
-    integer :: num_items, num_patterns, i
864
+    integer :: num_items, num_patterns, i, word_len
865865
     type(token_t) :: tok
866866
     nullify(node)
867867
     num_items = 0
@@ -869,6 +869,8 @@ contains
869869
     tok = current_token(state)
870870
     if (tok%token_type /= TOKEN_WORD) return
871871
     word = tok%value
872
+    word_len = tok%value_length
873
+    if (word_len == 0) word_len = len_trim(word)
872874
     call advance(state)
873875
     call skip_newlines(state)
874876
     if (.not. expect(state, 'in')) return
@@ -935,7 +937,7 @@ contains
935937
     end do
936938
 
937939
     if (.not. expect(state, 'esac')) return
938
-    node => create_case_statement(word, items, num_items)
940
+    node => create_case_statement(word, items, num_items, word_len)
939941
   end function
940942
 
941943
   ! Parse commands in a case item until ;; or esac