Skip to content

Commit

Permalink
docs: add docstring for parse_variable
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed Nov 19, 2024
1 parent fc13ecd commit 8712f99
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/systems/abstractsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3285,18 +3285,25 @@ function dump_unknowns(sys::AbstractSystem)
end
end

# syntax:
# varname = "D(" varname ")" | arrvar | maybe_dummy_var
# arrvar = maybe_dummy_var "[idxs...]"
# idxs = int | int "," idxs
# maybe_dummy_var = namespacedvar | namespacedvar "(t)" |
# namespacedvar "(t)" "ˍ" ts | namespacedvar "ˍ" ts |
# namespacedvar "ˍ" ts "(t)"
# ts = "t" | "t" ts
# namespacedvar = ident "₊" namespacedvar | ident "." namespacedvar | ident
#
# I'd write a regex to validate this, but https://xkcd.com/1171/
"""
$(TYPEDSIGNATURES)
Return the variable in `sys` referred to by its string representation `str`.
Roughly supports the following CFG:
```
varname = "D(" varname ")" | arrvar | maybe_dummy_var
arrvar = maybe_dummy_var "[idxs...]"
idxs = int | int "," idxs
maybe_dummy_var = namespacedvar | namespacedvar "(t)" |
namespacedvar "(t)" "ˍ" ts | namespacedvar "ˍ" ts |
namespacedvar "ˍ" ts "(t)"
ts = "t" | "t" ts
namespacedvar = ident "₊" namespacedvar | ident "." namespacedvar | ident
```
"""
function parse_variable(sys::AbstractSystem, str::AbstractString)
# I'd write a regex to validate `str`, but https://xkcd.com/1171/
str = strip(str)
derivative_level = 0
while startswith(str, "D(") && endswith(str, ")")
Expand Down

0 comments on commit 8712f99

Please sign in to comment.