@@ -60,6 +60,7 @@ add_id_and_short <- function(pd) {
60
60
# ' for potential reparsing.
61
61
# ' @keywords internal
62
62
ensure_correct_str_txt <- function (pd , text ) {
63
+ ensure_valid_pd(pd )
63
64
is_problematic_string <- identify_insufficiently_parsed_stings(pd , text )
64
65
problematic_strings <- pd [is_problematic_string , ]
65
66
is_parent_of_problematic_string <-
@@ -101,6 +102,30 @@ ensure_correct_str_txt <- function(pd, text) {
101
102
arrange(pos_id )
102
103
}
103
104
105
+ # ' Ensure that the parse data is valid
106
+ # '
107
+ # ' Test whether all non-termnals have at least one child and throw an error
108
+ # ' otherwise. As this is check is rather expensive, it is only
109
+ # ' carried out for configurations we have good reasons to expect problems.
110
+ # ' @param pd A parse table.
111
+ ensure_valid_pd <- function (pd ) {
112
+ if (getRversion() < " 3.2" ) {
113
+ non_terminals <- pd %> %
114
+ filter(terminal == FALSE )
115
+ valid_pd <- non_terminals $ id %> %
116
+ map_lgl(~ .x %in% pd $ parent ) %> %
117
+ all()
118
+ if (! valid_pd ) {
119
+ stop(paste(
120
+ " The parse data is not valid and the problem is most likely related" ,
121
+ " to the parser in base R. Please install R >= 3.2 and try again." ,
122
+ call. = FALSE
123
+ ))
124
+ }
125
+ }
126
+ TRUE
127
+ }
128
+
104
129
# ' Indentify strings that were not fully parsed
105
130
# '
106
131
# ' Indentifies strings that were not fully parsed due to their vast length.
0 commit comments