($ tag)
Defines a state tag, which can be correlated to a reducer function using compile
.
Defines a state tag, which can be correlated to a reducer function using `compile`.
(* & args)
Returns an automaton that accepts zero or more of the given automata.
Returns an automaton that accepts zero or more of the given automata.
(+ & args)
Returns an automaton that accepts one or more of the given automaton.
Returns an automaton that accepts one or more of the given automaton.
(? & args)
Returns an automaton that accepts zero or one of the given automaton.
Returns an automaton that accepts zero or one of the given automaton.
(advance fsm state input)
(advance fsm state input reject-value)
Advances a single position in the automaton. Takes a compiled fsm
, a state
which is either an initial reduce
value or a CompiledAutomatonState previously returned by advance
, and an input.
If a reject-value
is specified, it will be returned if an invalid input is given. Otherwise an IllegalArgumentException is thrown.
Advances a single position in the automaton. Takes a compiled `fsm`, a `state` which is either an initial reduce value or a CompiledAutomatonState previously returned by `advance`, and an input. If a `reject-value` is specified, it will be returned if an invalid input is given. Otherwise an IllegalArgumentException is thrown.
(advance-stream fsm state stream reject-value)
Advances through the the stream, stopping if the stream is accepted or rejected. If the input state is accepted?
,
proceeds anyway. If rejected, reject-value
is returned in lieu of the new state.
If an input state is already accepted and reject-value
is returned, this means that inputs beyond the accepted sub-sequence
have been consumed. As such, be careful when using impure functions and input sources.
Advances through the the stream, stopping if the stream is accepted or rejected. If the input state is `accepted?`, proceeds anyway. If rejected, `reject-value` is returned in lieu of the new state. If an input state is already accepted and `reject-value` is returned, this means that inputs beyond the accepted sub-sequence have been consumed. As such, be careful when using impure functions and input sources.
(and & args)
Returns an automaton that accepts the intersection the given automata.
Returns an automaton that accepts the intersection the given automata.
Returns an automaton that accepts any single input value.
Returns an automaton that accepts any single input value.
(compile fsm)
(compile fsm {:keys [backend action-comparator] :as options})
Compiles the fsm into something that can be used with find
, advance-stream
, greedy-find
, and advance
. Optionally takes an option map, which may contain:
reducers
- a map or function of actions defined via $
onto reducer functions which take two arguments, the current reduction value and the input.
signal
- a function that takes an input and returns the signal that will be used to advance the automaton. The input passed into reducer functions will not be affected by this.
action-comparator
- an optional comparator function used to sort actions. The default is compare
.
Compiles the fsm into something that can be used with `find`, `advance-stream`, `greedy-find`, and `advance`. Optionally takes an option map, which may contain: `reducers` - a map or function of actions defined via `$` onto reducer functions which take two arguments, the current reduction value and the input. `signal` - a function that takes an input and returns the signal that will be used to advance the automaton. The input passed into reducer functions will not be affected by this. `action-comparator` - an optional comparator function used to sort actions. The default is `compare`.
(complement & args)
Returns the complement of the given automaton.
Returns the complement of the given automaton.
(difference & args)
Returns an automaton that accepts the disjoint of the first automaton and the subsequent automata.
Returns an automaton that accepts the disjoint of the first automaton and the subsequent automata.
(find fsm state stream)
Searches for a accepted sub-sequence within the stream. If an input sequence is rejected, begins again at the automaton's
start state. If the input state is accepted?
, returns immediately.
If the returned state has accepted?
set to true, the matching sub-sequence is from start-index
to stream-index
. Since
no inputs past the match are consumed, this can be safely used with impure functions and input sources.
Searches for a accepted sub-sequence within the stream. If an input sequence is rejected, begins again at the automaton's start state. If the input state is `accepted?`, returns immediately. If the returned state has `accepted?` set to true, the matching sub-sequence is from `start-index` to `stream-index`. Since no inputs past the match are consumed, this can be safely used with impure functions and input sources.
(greedy-find fsm state stream)
Greedily find the largest possible accepted sub-sequence. Will only return an accepted?
state once subsequent
inputs have been rejected. Since this always consumes more inputs than the accepted sub-sequence, be careful when
using impure functions or input sources.
Greedily find the largest possible accepted sub-sequence. Will only return an `accepted?` state once subsequent inputs have been rejected. Since this always consumes more inputs than the accepted sub-sequence, be careful when using impure functions or input sources.
(interpose-$ tag fsm)
Applies a state tag to all states within the given automaton.
Applies a state tag to all states within the given automaton.
(matching-inputs fsm)
Returns a lazy sequence of input sequences which the automaton will match.
Returns a lazy sequence of input sequences which the automaton will match.
Returns an automaton that immediately accepts.
Returns an automaton that immediately accepts.
(not & args)
Returns the complement of any zero or one-transition automata. Equivalent to the character
negation ^
operator in regular expressions.
Returns the complement of any zero or one-transition automata. Equivalent to the character negation `^` operator in regular expressions.
(or & args)
Returns an automaton that accepts the union of the given automata.
Returns an automaton that accepts the union of the given automata.
(precompile fsm)
Takes an fsm, and returns a data structure where states are represented by
numbers, and the provided keys are :accept, :state->input->state,
and :state->input->actions. The start state will always be 0
.
Takes an fsm, and returns a data structure where states are represented by numbers, and the provided keys are :accept, :state->input->state, and :state->input->actions. The start state will always be `0`.
(range lower upper)
Returns an automaton which matches any input within the inclusive range of [upper, lower].
Returns an automaton which matches any input within the inclusive range of [upper, lower].
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close