@@ -110,10 +110,10 @@ macro reaction_network(expr::Expr)
110110 return make_rs_expr (:(gensym (:ReactionSystem )), expr)
111111end
112112
113- # Ideally, it would have been possible to combine the @reaction_network and @network_component macros.
114- # However, this issue: https://github.com/JuliaLang/julia/issues/37691 causes problem with interpolations
115- # if we make the @reaction_network macro call the @network_component macro. Instead, these uses the
116- # same input, but passes `complete = false` to `make_rs_expr`.
113+ # Ideally, it would have been possible to combine the @reaction_network and @network_component
114+ # macros. However, this issue: https://github.com/JuliaLang/julia/issues/37691 causes problem
115+ # with interpolations if we make the @reaction_network macro call the @network_component macro.
116+ # Instead, these use the same input, but pass `complete = false` to `make_rs_expr`.
117117"""
118118 @network_component
119119
@@ -151,7 +151,7 @@ function make_rs_expr(name; complete = true)
151151 return Expr (:block , :(@parameters t), rs_expr)
152152end
153153
154- # When both a name and a network expression is generated, dispatches these to the internal
154+ # When both a name and a network expression are generated, dispatch these to the internal
155155# `make_reaction_system` function.
156156function make_rs_expr (name, network_expr; complete = true )
157157 rs_expr = make_reaction_system (striplines (network_expr), name)
@@ -167,7 +167,7 @@ struct DSLReactant
167167 stoichiometry:: ExprValues
168168end
169169
170- # Internal structure containing information about one Reaction. Contain all its substrates and
170+ # Internal structure containing information about one Reaction. Contains all its substrates and
171171# products as well as its rate and potential metadata. Uses a specialized constructor.
172172struct DSLReaction
173173 substrates:: Vector{DSLReactant}
188188# Recursive function that loops through the reaction line and finds the reactants and their
189189# stoichiometry. Recursion makes it able to handle weird cases like 2(X + Y + 3(Z + XY)). The
190190# reactants are stored in the `reactants` vector. As the expression tree is parsed, the
191- # stoichiometry is updated and new reactants added.
191+ # stoichiometry is updated and new reactants are added.
192192function recursive_find_reactants! (ex:: ExprValues , mult:: ExprValues ,
193193 reactants:: Vector{DSLReactant} )
194194 # We have reached the end of the expression tree and can finalise and return the reactants.
@@ -271,7 +271,7 @@ function make_reaction_system(ex::Expr, name)
271271 # Handle interpolation of variables in the input.
272272 ex = esc_dollars! (ex)
273273
274- # Extracts the lines with reactions, the lines with options, and the options. Check for input errors.
274+ # Extract the lines with reactions, the lines with options, and the options. Check for input errors.
275275 reaction_lines = Expr[x for x in ex. args if x. head == :tuple ]
276276 option_lines = Expr[x for x in ex. args if x. head == :macrocall ]
277277 options = Dict (Symbol (String (arg. args[1 ])[2 : end ]) => arg for arg in option_lines)
@@ -282,8 +282,8 @@ function make_reaction_system(ex::Expr, name)
282282 any (! in (option_keys), keys (options)) &&
283283 error (" The following unsupported options were used: $(filter (opt_in-> ! in (opt_in,option_keys), keys (options))) " )
284284
285- # Read options that explicitly declares some symbol (e.g. `@species`). Compiles a list of
286- # all declared symbols and checks that there has been no double-declarations.
285+ # Read options that explicitly declare some symbol (e.g. `@species`). Compiles a list of
286+ # all declared symbols and checks that there have been no double-declarations.
287287 sps_declared = extract_syms (options, :species )
288288 ps_declared = extract_syms (options, :parameters )
289289 vs_declared = extract_syms (options, :variables )
@@ -297,7 +297,7 @@ function make_reaction_system(ex::Expr, name)
297297 error (" The following symbols $(unique (nonunique_syms)) have explicitly been declared as multiple types of components (e.g. occur in at least two of the `@species`, `@parameters`, `@variables`, `@ivs`, `@compounds`, `@differentials`). This is not allowed." )
298298 end
299299
300- # Reads the reactions and equation. From these, infers species, variables, and parameters.
300+ # Reads the reactions and equation. From these, infer species, variables, and parameters.
301301 requiredec = haskey (options, :require_declaration )
302302 reactions = get_reactions (reaction_lines)
303303 sps_inferred, ps_pre_inferred = extract_sps_and_ps (reactions, syms_declared; requiredec)
@@ -319,16 +319,16 @@ function make_reaction_system(ex::Expr, name)
319319 psexpr_init = get_psexpr (ps_inferred, options)
320320 spsexpr_init = get_usexpr (sps_inferred, options; ivs)
321321 vsexpr_init = get_usexpr (vs_inferred, options, :variables ; ivs)
322- psexpr, psvar = scalarize_macro (psexpr_init, " ps" )
323- spsexpr, spsvar = scalarize_macro (spsexpr_init, " specs" )
324- vsexpr, vsvar = scalarize_macro (vsexpr_init, " vars" )
325- cmpsexpr, cmpsvar = scalarize_macro (cmpexpr_init, " comps" )
322+ psexpr, psvar = assign_var_to_symvar_declaration (psexpr_init, " ps" )
323+ spsexpr, spsvar = assign_var_to_symvar_declaration (spsexpr_init, " specs" )
324+ vsexpr, vsvar = assign_var_to_symvar_declaration (vsexpr_init, " vars" )
325+ cmpsexpr, cmpsvar = assign_var_to_symvar_declaration (cmpexpr_init, " comps" )
326326 rxsexprs = get_rxexprs (reactions, equations, all_syms)
327327
328328 # Assemblies the full expression that declares all required symbolic variables, and
329329 # then the output `ReactionSystem`.
330330 MacroTools. flatten (striplines (quote
331- # Inserts the expressions which generates the `ReactionSystem` input.
331+ # Inserts the expressions which generate the `ReactionSystem` input.
332332 $ ivsexpr
333333 $ psexpr
334334 $ spsexpr
@@ -357,12 +357,12 @@ end
357357
358358# ## DSL Reaction Reading Functions ###
359359
360- # Generates a vector of reaction structures, each containing the information about one reaction.
360+ # Generates a vector of reaction structures, each containing information about one reaction.
361361function get_reactions (exprs:: Vector{Expr} )
362362 # Declares an array to which we add all found reactions.
363363 reactions = Vector {DSLReaction} (undef, 0 )
364364
365- # Loops through each line of reactions. Extracts and adds each lines 's reactions to `reactions`.
365+ # Loops through each line of reactions. Extracts and adds each line 's reactions to `reactions`.
366366 for line in exprs
367367 # Reads core reaction information.
368368 arrow, rate, reaction, metadata = read_reaction_line (line)
@@ -391,10 +391,10 @@ function get_reactions(exprs::Vector{Expr})
391391 return reactions
392392end
393393
394- # Extracts the rate, reaction, and metadata fields (the last one optional) from a reaction line.
394+ # Extract the rate, reaction, and metadata fields (the last one optional) from a reaction line.
395395function read_reaction_line (line:: Expr )
396- # Handles rate, reaction, and arrow. Special routine required for the`-->` case, which
397- # creates an expression different what the other arrows creates .
396+ # Handles rate, reaction, and arrow. A special routine is required for the`-->` case,
397+ # which creates an expression different from what the other arrows create .
398398 rate = line. args[1 ]
399399 reaction = line. args[2 ]
400400 if reaction. head == :-->
450450# When the user have used the @species (or @parameters) options, extract species (or
451451# parameters) from its input.
452452function extract_syms (opts, vartype:: Symbol )
453- # If the corresponding option have been used, uses `Symbolics._parse_vars` to find all
453+ # If the corresponding option has been used, use `Symbolics._parse_vars` to find all
454454 # variable within it (returning them in a vector).
455455 return if haskey (opts, vartype)
456456 ex = opts[vartype]
464464# Function looping through all reactions, to find undeclared symbols (species or
465465# parameters) and assign them to the right category.
466466function extract_sps_and_ps (reactions, excluded_syms; requiredec = false )
467- # Loops through all reactant, extract undeclared ones as species.
467+ # Loops through all reactants and extract undeclared ones as species.
468468 species = OrderedSet {Union{Symbol, Expr}} ()
469469 for reaction in reactions
470470 for reactant in Iterators. flatten ((reaction. substrates, reaction. products))
509509
510510# ## DSL Output Expression Builders ###
511511
512- # Given the extracted species (or variables) and the option dictionary, creates the
512+ # Given the extracted species (or variables) and the option dictionary, create the
513513# `@species ...` (or `@variables ..`) expression which would declare these.
514514# If `key = :variables`, does this for variables (and not species).
515515function get_usexpr (us_extracted, options, key = :species ; ivs = (DEFAULT_IV_SYM,))
@@ -541,7 +541,7 @@ function get_psexpr(parameters_extracted, options)
541541end
542542
543543# From the system reactions (as `DSLReaction`s) and equations (as expressions),
544- # creates the expressions that evaluates to the reaction (+ equations) vector.
544+ # creates the expression that evaluates to the reaction (+ equations) vector.
545545function get_rxexprs (reactions, equations, all_syms)
546546 rxsexprs = :(Catalyst. CatalystEqType[])
547547 foreach (rx -> push! (rxsexprs. args, get_rxexpr (rx)), reactions)
@@ -576,14 +576,14 @@ end
576576
577577# Takes a ModelingToolkit declaration macro (like @parameters ...) and return and expression:
578578# That calls the macro and then scalarizes all the symbols created into a vector of Nums.
579- # stores the created symbolic variables in a variable (which name is generated from `name`).
579+ # stores the created symbolic variables in a variable (whose name is generated from `name`).
580580# It will also return the name used for the variable that stores the symbolic variables.
581- function scalarize_macro (expr_init, name)
581+ function assign_var_to_symvar_declaration (expr_init, name)
582582 # Generates a random variable name which (in generated code) will store the produced
583583 # symbolic variables (e.g. `var"##ps#384"`).
584584 namesym = gensym (name)
585585
586- # If the input expression is non-empty, wraps it with additional information.
586+ # If the input expression is non-empty, wrap it with additional information.
587587 if expr_init != :(())
588588 symvec = gensym ()
589589 expr = quote
613613# more generic to account for other default reaction metadata. Practically, this will likely
614614# be the only relevant reaction metadata to have a default value via the DSL. If another becomes
615615# relevant, the code can be rewritten to take this into account.
616- # Checks if the `@default_noise_scaling` option is used. If so, uses it as the default value of
616+ # Checks if the `@default_noise_scaling` option is used. If so, use it as the default value of
617617# the `default_noise_scaling` reaction metadata, otherwise, returns an empty vector.
618618function read_default_noise_scaling_option (options)
619619 if haskey (options, :default_noise_scaling )
@@ -625,7 +625,7 @@ function read_default_noise_scaling_option(options)
625625end
626626
627627# When compound species are declared using the "@compound begin ... end" option, get a list
628- # of the compound species, and also the expression that crates them.
628+ # of the compound species, and also the expression that creates them.
629629function read_compound_option (options)
630630 # If the compound option is used, retrieve a list of compound species and the option line
631631 # that creates them (used to declare them as compounds at the end). Due to some expression
@@ -678,10 +678,10 @@ function read_events_option(options, event_type::Symbol)
678678end
679679
680680# Reads the variables options. Outputs a list of the variables inferred from the equations,
681- # as well as the equation vector. If the default differential was used, updates the `diffsexpr`
681+ # as well as the equation vector. If the default differential was used, update the `diffsexpr`
682682# expression so that this declares this as well.
683683function read_equations_option! (diffsexpr, options, syms_unavailable, tiv; requiredec = false )
684- # Prepares the equations. First, extracts equations from provided option (converting to block form if required).
684+ # Prepares the equations. First, extract equations from the provided option (converting to block form if required).
685685 # Next, uses MTK's `parse_equations!` function to split input into a vector with the equations.
686686 eqs_input = haskey (options, :equations ) ? get_block_option (options[:equations ]) : :(begin end )
687687 eqs_input = option_block_form (eqs_input)
@@ -696,7 +696,7 @@ function read_equations_option!(diffsexpr, options, syms_unavailable, tiv; requi
696696 add_default_diff = false
697697 for eq in equations
698698 if (eq. head != :call ) || (eq. args[1 ] != :~ )
699- error (" Malformed equation: \" $eq \" . Equation's left hand and right hand sides should be separated by a \" ~\" ." )
699+ error (" Malformed equation: \" $eq \" . Equation's left hand and right- hand sides should be separated by a \" ~\" ." )
700700 end
701701
702702 # If the default differential (`D`) is used, record that it should be declared later on.
@@ -713,7 +713,7 @@ function read_equations_option!(diffsexpr, options, syms_unavailable, tiv; requi
713713 " Unrecognized symbol $(join (vs_inferred, " , " )) detected in equation expression: \" $(string (eq)) \" . Since the flag @require_declaration is declared, all symbolic variables must be explicitly declared with the @species, @variables, and @parameters options." ))
714714 end
715715
716- # If `D` differential is used, add it to differential expression and inferred differentials list.
716+ # If `D` differential is used, add it to the differential expression and inferred differentials list.
717717 diffs_inferred = Union{Symbol, Expr}[]
718718 if add_default_diff && ! any (diff_dec. args[1 ] == :D for diff_dec in diffsexpr. args)
719719 diffs_inferred = [:D ]
@@ -723,7 +723,7 @@ function read_equations_option!(diffsexpr, options, syms_unavailable, tiv; requi
723723 return collect (vs_inferred), diffs_inferred, equations
724724end
725725
726- # Searches an expression `expr` and returns true if it have any subexpression `D(...)` (where `...` can be anything).
726+ # Searches an expression `expr` and returns true if it has any subexpression `D(...)` (where `...` can be anything).
727727# Used to determine whether the default differential D has been used in any equation provided to `@equations`.
728728function find_D_call (expr)
729729 return if Base. isexpr (expr, :call ) && expr. args[1 ] == :D
739739# which is used by the default differential (if it is used).
740740function read_differentials_option (options)
741741 # Creates the differential expression.
742- # If differentials was provided as options, this is used as the initial expression.
742+ # If differentials were provided as options, this is used as the initial expression.
743743 # If the default differential (D(...)) was used in equations, this is added to the expression.
744744 diffsexpr = (haskey (options, :differentials ) ?
745745 get_block_option (options[:differentials ]) : striplines (:(begin end )))
@@ -793,7 +793,7 @@ function read_observed_option(options, all_ivs, us_declared, all_syms; requirede
793793 ((obs_name in us_declared) || is_escaped_expr (obs_eq. args[2 ])) && ! isnothing (metadata) &&
794794 error (" Metadata was provided to observable $obs_name in the `@observables` macro. However, the observable was also declared separately (using either @species or @variables). When this is done, metadata should instead be provided within the original @species or @variable declaration." )
795795
796- # This bits adds the observables to the @variables vector which is given as output.
796+ # This bit adds the observables to the @variables vector which is given as output.
797797 # For Observables that have already been declared using @species/@variables,
798798 # or are interpolated, this parts should not be carried out.
799799 if ! ((obs_name in us_declared) || is_escaped_expr (obs_eq. args[2 ]))
@@ -825,7 +825,7 @@ function read_observed_option(options, all_ivs, us_declared, all_syms; requirede
825825 (striplines (obsexpr) == striplines (Expr (:block , :(@variables )))) &&
826826 (obsexpr = :())
827827 else
828- # If option is not used, return empty expression and vector.
828+ # If observables option is not used, return empty expression and vector.
829829 obsexpr = :()
830830 obs_eqs = :([])
831831 obs_syms = :([])
@@ -834,7 +834,7 @@ function read_observed_option(options, all_ivs, us_declared, all_syms; requirede
834834 return obsexpr, obs_eqs, obs_syms
835835end
836836
837- # From the input to the @observables options, creates a vector containing one equation for
837+ # From the input to the @observables options, create a vector containing one equation for
838838# each observable. `option_block_form` handles if single line declaration of `@observables`,
839839# i.e. without a `begin ... end` block, was used.
840840function make_obs_eqs (observables_expr)
@@ -845,7 +845,7 @@ function make_obs_eqs(observables_expr)
845845end
846846
847847# Reads the combinatorial ratelaw options, which determines if a combinatorial rate law should
848- # be used or not. If not provides, uses the default (true).
848+ # be used or not. If not provided, use the default (true).
849849function read_combinatoric_ratelaws_option (options)
850850 return haskey (options, :combinatoric_ratelaws ) ?
851851 get_block_option (options[:combinatoric_ratelaws ]) : true
@@ -938,7 +938,7 @@ function make_reaction(ex::Expr)
938938 reaction = get_reaction (ex)
939939 species, parameters = extract_sps_and_ps ([reaction], [])
940940
941- # Checks for input errors. Needed here but not in `@reaction_network` as `ReactionSystem` perform this check but `Reaction` don 't.
941+ # Checks for input errors. Needed here but not in `@reaction_network` as `ReactionSystem` performs this check but `Reaction` doesn 't.
942942 forbidden_symbol_check (union (species, parameters))
943943
944944 # Creates expressions corresponding to code for declaring the parameters, species, and reaction.
@@ -978,14 +978,14 @@ function recursive_escape_functions!(expr::ExprValues, syms_skip = [])
978978 expr
979979end
980980
981- # Returns the length of a expression tuple, or 1 if it is not an expression tuple (probably a Symbol/Numerical).
981+ # Returns the length of an expression tuple, or 1 if it is not an expression tuple (probably a Symbol/Numerical).
982982function tup_leng (ex:: ExprValues )
983983 (typeof (ex) == Expr && ex. head == :tuple ) && (return length (ex. args))
984984 return 1
985985end
986986
987- # Gets the ith element in a expression tuple, or returns the input itself if it is not an expression tuple
988- # (probably a Symbol/Numerical). This is used to handle bundled reaction (like `d, (X,Y) --> 0`).
987+ # Gets the ith element in an expression tuple, or returns the input itself if it is not an expression tuple
988+ # (probably a Symbol/Numerical). This is used to handle bundled reactions (like `d, (X,Y) --> 0`).
989989function get_tup_arg (ex:: ExprValues , i:: Int )
990990 (tup_leng (ex) == 1 ) && (return ex)
991991 return ex. args[i]
0 commit comments