@@ -928,38 +928,29 @@ static unsigned analysis_state__recursion_depth(const AnalysisState *self) {
928928 return result ;
929929}
930930
931- static inline int analysis_state__compare_position (
931+ static inline int analysis_state__compare (
932932 AnalysisState * const * self ,
933933 AnalysisState * const * other
934934) {
935+ if ((* self )-> depth < (* other )-> depth ) return 1 ;
935936 for (unsigned i = 0 ; i < (* self )-> depth ; i ++ ) {
936937 if (i >= (* other )-> depth ) return -1 ;
937- if ((* self )-> stack [i ].child_index < (* other )-> stack [i ].child_index ) return -1 ;
938- if ((* self )-> stack [i ].child_index > (* other )-> stack [i ].child_index ) return 1 ;
938+ AnalysisStateEntry s1 = (* self )-> stack [i ];
939+ AnalysisStateEntry s2 = (* other )-> stack [i ];
940+ if (s1 .child_index < s2 .child_index ) return -1 ;
941+ if (s1 .child_index > s2 .child_index ) return 1 ;
942+ if (s1 .parent_symbol < s2 .parent_symbol ) return -1 ;
943+ if (s1 .parent_symbol > s2 .parent_symbol ) return 1 ;
944+ if (s1 .parse_state < s2 .parse_state ) return -1 ;
945+ if (s1 .parse_state > s2 .parse_state ) return 1 ;
946+ if (s1 .field_id < s2 .field_id ) return -1 ;
947+ if (s1 .field_id > s2 .field_id ) return 1 ;
939948 }
940- if ((* self )-> depth < (* other )-> depth ) return 1 ;
941949 if ((* self )-> step_index < (* other )-> step_index ) return -1 ;
942950 if ((* self )-> step_index > (* other )-> step_index ) return 1 ;
943951 return 0 ;
944952}
945953
946- static inline int analysis_state__compare (
947- AnalysisState * const * self ,
948- AnalysisState * const * other
949- ) {
950- int result = analysis_state__compare_position (self , other );
951- if (result != 0 ) return result ;
952- for (unsigned i = 0 ; i < (* self )-> depth ; i ++ ) {
953- if ((* self )-> stack [i ].parent_symbol < (* other )-> stack [i ].parent_symbol ) return -1 ;
954- if ((* self )-> stack [i ].parent_symbol > (* other )-> stack [i ].parent_symbol ) return 1 ;
955- if ((* self )-> stack [i ].parse_state < (* other )-> stack [i ].parse_state ) return -1 ;
956- if ((* self )-> stack [i ].parse_state > (* other )-> stack [i ].parse_state ) return 1 ;
957- if ((* self )-> stack [i ].field_id < (* other )-> stack [i ].field_id ) return -1 ;
958- if ((* self )-> stack [i ].field_id > (* other )-> stack [i ].field_id ) return 1 ;
959- }
960- return 0 ;
961- }
962-
963954static inline AnalysisStateEntry * analysis_state__top (AnalysisState * self ) {
964955 if (self -> depth == 0 ) {
965956 return & self -> stack [0 ];
@@ -1247,7 +1238,7 @@ static void ts_query__perform_analysis(
12471238 // the states that have made the least progress. Avoid advancing states that have already
12481239 // made more progress.
12491240 if (analysis -> next_states .size > 0 ) {
1250- int comparison = analysis_state__compare_position (
1241+ int comparison = analysis_state__compare (
12511242 & state ,
12521243 array_back (& analysis -> next_states )
12531244 );
@@ -1349,7 +1340,12 @@ static void ts_query__perform_analysis(
13491340 // Determine if this hypothetical child node would match the current step
13501341 // of the query pattern.
13511342 bool does_match = false;
1352- if (visible_symbol ) {
1343+
1344+ // ERROR nodes can appear anywhere, so if the step is
1345+ // looking for an ERROR node, consider it potentially matchable.
1346+ if (step -> symbol == ts_builtin_sym_error ) {
1347+ does_match = true;
1348+ } else if (visible_symbol ) {
13531349 does_match = true;
13541350 if (step -> symbol == WILDCARD_SYMBOL ) {
13551351 if (
0 commit comments