419419
420420function make_node (node:: Node , span′:: Integer , tags = node. tags)
421421 @assert is_leaf (node)
422- return Node (head (node), span′, () , tags)
422+ return Node (head (node), span′, nothing , tags)
423423end
424424
425425# TODO : Remove?
540540# Assignment node but exclude loop variable assignment
541541function is_variable_assignment (ctx, node:: Node )
542542 return ! is_leaf (node) && is_assignment (node) &&
543- ! (ctx. lineage_kinds[end ] in KSet " for generator cartesian_iterator filter" )
543+ ! (ctx. lineage_kinds[end ] in KSet " for generator filter" )
544544end
545545
546546# K"global" and K"local" nodes can be either `global a, b, c` or `global a = 1`. This method
@@ -587,29 +587,24 @@ function is_infix_op_call(node::Node)
587587 return kind (node) in KSet " call dotcall" && JuliaSyntax. is_infix_op_call (node)
588588end
589589
590- # Extract the operator of an infix op call node
591- function infix_op_call_op (node:: Node )
592- @assert is_infix_op_call (node) || kind (node) === K " ||"
590+ # Extract the specific operator kind by reading the source bytes. In JuliaSyntax version 1
591+ # operators are just K"Identifier" so we can't look at the kind directly.
592+ # Note: ctx.fmt_io must be positioned at the start of node when this is called.
593+ function infix_op_call_op (ctx, node:: Node )
593594 kids = verified_kids (node)
594595 first_operand_index = findfirst (! JuliaSyntax. is_whitespace, kids):: Int
595- op_index = findnext (JuliaSyntax. is_operator, kids, first_operand_index + 1 ):: Int
596- return kids[op_index]
597- end
598-
599- # Comparison leaf or a dotted comparison leaf (.<)
600- function is_comparison_leaf (node:: Node )
601- if is_leaf (node) && JuliaSyntax. is_prec_comparison (node)
602- return true
603- elseif ! is_leaf (node) && kind (node) === K " ." &&
604- meta_nargs (node) == 2 && is_comparison_leaf (verified_kids (node)[2 ])
605- return true
606- else
607- return false
596+ op_index = findnext (! JuliaSyntax. is_whitespace, kids, first_operand_index + 1 ):: Int
597+ off = position (ctx. fmt_io)
598+ for i in 1 : (op_index - 1 )
599+ off += span (kids[i])
608600 end
609- end
610-
611- function is_operator_leaf (node:: Node )
612- return is_leaf (node) && JuliaSyntax. is_operator (node)
601+ pos = position (ctx. fmt_io)
602+ seek (ctx. fmt_io, off)
603+ bytes = read (ctx. fmt_io, span (kids[op_index]))
604+ seek (ctx. fmt_io, pos)
605+ str = String (bytes)
606+ i = get (JuliaSyntax. _kind_str_to_int, str, nothing )
607+ return i === nothing ? K " Identifier" : JuliaSyntax. Kind (i)
613608end
614609
615610function first_non_whitespace_kid (node:: Node )
@@ -783,7 +778,7 @@ function is_string_macro(node)
783778 @assert ! is_leaf (node)
784779 kids = verified_kids (node)
785780 return length (kids) >= 2 &&
786- kind (kids[1 ]) in KSet " StringMacroName CmdMacroName core_@cmd " &&
781+ kind (kids[1 ]) in KSet " StringMacroName CmdMacroName" &&
787782 kind (kids[2 ]) in KSet " string cmdstring"
788783end
789784
@@ -796,7 +791,7 @@ function is_triple_string_macro(node)
796791 if kind (node) === K " macrocall"
797792 kids = verified_kids (node)
798793 if length (kids) >= 2 &&
799- kind (kids[1 ]) in KSet " StringMacroName CmdMacroName core_@cmd " &&
794+ kind (kids[1 ]) in KSet " StringMacroName CmdMacroName" &&
800795 is_triple_string (kids[2 ])
801796 return true
802797 end
806801
807802function is_triple_thing (node)
808803 return is_triple_string (node) || is_triple_string_macro (node) ||
809- (kind (node) === K " juxtapose" && is_triple_string_macro (verified_kids (node)[1 ]))
804+ (kind (node) === K " juxtapose" && is_triple_string (verified_kids (node)[1 ]))
805+ end
806+
807+ function is_any_op_call (node)
808+ return JuliaSyntax. is_infix_op_call (node) || JuliaSyntax. is_prefix_op_call (node) ||
809+ JuliaSyntax. is_postfix_op_call (node)
810+ end
811+
812+ function is_short_form_function_definition (node)
813+ return kind (node) === K " function" &&
814+ JuliaSyntax. has_flags (node, JuliaSyntax. SHORT_FORM_FUNCTION_FLAG)
810815end
811816
812817# Check whether the sequence of kinds in `kinds` exist in `kids` starting at index `i`.
826831function macrocall_name (ctx, node)
827832 @assert kind (node) === K " macrocall"
828833 kids = verified_kids (node)
829- pred = x -> kind (x) in KSet " MacroName StringMacroName CmdMacroName core_@cmd "
834+ pred = x -> kind (x) in KSet " MacroName StringMacroName CmdMacroName"
830835 mkind = kind (first_leaf_predicate (node, pred):: Node )
831836 if kmatch (kids, KSet " @ MacroName" )
832837 p = position (ctx. fmt_io)
@@ -842,10 +847,6 @@ function macrocall_name(ctx, node)
842847 append! (bytes, " _str" )
843848 end
844849 return String (bytes)
845- elseif kmatch (kids, KSet " core_@cmd" )
846- bytes = read_bytes (ctx, kids[1 ])
847- @assert length (bytes) == 0
848- return " core_@cmd"
849850 else
850851 # Don't bother looking in more complex expressions, just return unknown
851852 return " <unknown macro>"
0 commit comments