Permalink
Browse files

Converted annotate-scxml-json to JavaScript. Removed dead coffeescrip…

…t code.
  • Loading branch information...
jbeard4 committed Mar 29, 2012
1 parent 531a42e commit 562660cb51fa3cf764d7ef4c6cb8e2bad5a38332
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -1,15 +0,0 @@
-# Copyright 2011-2012 Jacob Beard, INFICON, and other SCION contributors
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-module.exports = (state,eventNames,evaluator) -> (t for t in state.transitions when (not t.event or t.event in eventNames) and (not t.cond or evaluator(t)))
View
@@ -1,102 +0,0 @@
-# Copyright 2011-2012 Jacob Beard, INFICON, and other SCION contributors
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-#TODO:move this out
-getDelayInMs = (delayString) ->
- if not delayString
- return 0
- else
- if delayString[-2..] == "ms"
- return parseFloat(delayString[..-3])
- else if delayString[-1..] == "s"
- return parseFloat(delayString[..-2]) * 1000
- else
- #assume milliseconds
- return parseFloat(delayString)
-
-#we alias _event to _events[0] here for convenience
-makeEvaluationFn = (s,isExpression) -> new Function("getData","setData","In","_events","datamodel","var _event = _events[0]; with(datamodel){#{if isExpression then "return" else ""} #{s}}")
-
-stateToString = -> @id
-
-transitionToString = -> "#{@source.id} -> [#{target.id for target in @targets}]"
-
-module.exports = (json) ->
- #build up map of state ids to state objects
- idToStateMap = {}
- for state in json.states
- idToStateMap[state.id] = state
-
- for transition in json.transitions
- transition.toString = transitionToString #tag him with a toString method for more readable trace
- transition.evaluateCondition = makeEvaluationFn transition.cond,true
-
- for state in json.states
- state.toString = stateToString #tag him with a toString method for more readable trace
-
- state.transitions = (json.transitions[transitionNum] for transitionNum in state.transitions)
-
- #TODO: move this block out, make it cleaner
- actions = state.onentry.concat state.onexit
- for transition in state.transitions
- for action in transition.actions
- actions.push action
-
- if transition.lca
- transition.lca = idToStateMap[transition.lca]
-
- for action in actions
- switch action.type
- when "script"
- action.evaluate = makeEvaluationFn action.script
-
- when "assign"
- action.evaluate = makeEvaluationFn action.expr,true
-
- when "send"
-
- for attributeName in ['contentexpr', 'eventexpr', 'targetexpr', 'typeexpr', 'delayexpr']
- if action[attributeName]
- action[attributeName] = { evaluate : makeEvaluationFn action[attributeName],true }
-
- for param in action.params
- if param.expr
- param.expr = { evaluate : makeEvaluationFn param.expr,true }
- when "log"
- action.evaluate = makeEvaluationFn action.expr,true
-
- if action.type is "send" and action.delay
- action.delay = getDelayInMs action.delay
-
-
- state.initial = idToStateMap[state.initial]
- state.history = idToStateMap[state.history]
-
- state.children = (idToStateMap[stateId] for stateId in state.children)
-
- state.parent = idToStateMap[state.parent]
-
- if state.ancestors
- state.ancestors = (idToStateMap[stateId] for stateId in state.ancestors)
-
- if state.descendants
- state.descendants = (idToStateMap[stateId] for stateId in state.descendants)
-
- for t in state.transitions
- t.source = idToStateMap[t.source]
- t.targets = t.targets and (idToStateMap[stateId] for stateId in t.targets)
-
- json.root = idToStateMap[json.root]
-
- return json
View
@@ -1,86 +0,0 @@
-# Copyright 2011-2012 Jacob Beard, INFICON, and other SCION contributors
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-stateKinds = require './state-kinds-enum'
-
-module.exports =
-
- getDepth: (s) ->
- if s.depth isnt undefined then return s.depth
- else
- count = 0
- state = s.parent
- while state
- count = count + 1
- state = state.parent
-
- return count
-
- getAncestors: (s,root) ->
- if s.ancestors
- index = s.ancestors.indexOf(root)
- if index is -1
- s.ancestors
- else
- s.ancestors.slice(0,index)
- else
- ancestors = []
-
- state = s.parent
- while state and not (state is root)
- ancestors.push(state)
- state = state.parent
-
- return ancestors
-
- getAncestorsOrSelf: (s,root) -> [s].concat @getAncestors(s,root)
-
- getDescendants: (s) ->
- if s.descendants then return s.descendants
- else
- descendants = []
- queue = s.children.slice()
-
- while queue.length
- state = queue.shift()
- descendants.push(state)
-
- for child in state.children
- queue.push(child)
-
- return descendants
-
- getDescendantsOrSelf: (s) -> [s].concat @getDescendants(s)
-
- isOrthogonalTo: (s1,s2) ->
- #Two control states are orthogonal if they are not ancestrally
- #related, and their smallest, mutual parent is a Concurrent-state.
- return not @isAncestrallyRelatedTo(s1,s2) and @getLCA(s1,s2).kind is stateKinds.PARALLEL
-
- isAncestrallyRelatedTo: (s1,s2) ->
- #Two control states are ancestrally related if one is child/grandchild of another.
- return s1 in @getAncestorsOrSelf(s2) or s2 in @getAncestorsOrSelf(s1)
-
- getLCA: (tOrS1,s2) ->
- if tOrS1.lca then return tOrS1.lca
- else
- #can take one or two arguments: either 1 transition, or two states
- if arguments.length is 1
- transition = tOrS1
- return @getLCA transition.source,transition.targets[0]
- else
- s1 = tOrS1
- commonAncestors = (a for a in @getAncestors(s1) when s2 in @getDescendants(a))
- return commonAncestors[0]
-
@@ -1,13 +0,0 @@
-eventNameReCache = {}
-
-#this will convert, e.g. "foo.bar.bat" to RegExp "^foo\.bar\.bat(\.[0-9a-zA-Z]+)*$"
-eventNameToRe = (name) -> new RegExp "^#{name.replace(/\./g,"\\.")}(\\.[0-9a-zA-Z]+)*$"
-
-retrieveEventRe = (name) -> eventNameReCache[name] ?= eventNameToRe name
-
-nameMatch = (t,eventNames) ->
- tEvents = t.events
- f = if "*" in tEvents then -> true else (name) -> (tEvent for tEvent in tEvents when retrieveEventRe(tEvent).test(name)).length
- (name for name in eventNames when f name).length
-
-module.exports = (state,eventNames,evaluator) -> (t for t in state.transitions when (not t.events or nameMatch t,eventNames) and (not t.cond or evaluator(t)))
@@ -1,70 +0,0 @@
-# Copyright 2011-2012 Jacob Beard, INFICON, and other SCION contributors
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-class ArraySet
- constructor: (l=[]) ->
- @o = []
-
- for x in l
- @add x
-
- add: (x) ->
- if not @contains x
- @o.push x
-
- remove: (x) ->
- for i in [0...@o.length]
- if @o[i] is x
- @o.splice i,1
- return true
- return false
-
- union: (l) ->
- l = if l.iter then l.iter() else l
-
- for i in l
- @add(i)
-
- return @
-
- difference: (l) ->
- l = if l.iter then l.iter() else l
-
- for i in l
- @remove(i)
-
- return @
-
- contains: (x) -> x in @o
-
- iter: -> @o
-
- isEmpty : -> !@o.length
-
- equals : (s2) ->
- l2 = s2.iter()
-
- for v in @o
- if not s2.contains(v)
- return false
-
- for v in l2
- if not @contains(v)
- return false
-
- return true
-
- toString : -> "Set(" + @o.toString() + ")"
-
-module.exports = ArraySet
Oops, something went wrong.

0 comments on commit 562660c

Please sign in to comment.