Skip to content

Instantly share code, notes, and snippets.

@barucAlmaguer
Last active February 28, 2021 21:42
Show Gist options
  • Save barucAlmaguer/c7a1531a667ccfbe316272db6085899e to your computer and use it in GitHub Desktop.
Save barucAlmaguer/c7a1531a667ccfbe316272db6085899e to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const locCounterMachine = Machine({
id: 'locCounter',
initial: 'parsing_global',
context: {
total: 0,
global: 0,
blocks: {
// functionX: 0
},
currentBlock: null,
bracketDepth: 0
},
states: {
parsing_global: {
on: {
EOF_FOUND: 'finished',
GLOBAL_FOUND: {
target: 'parsing_global',
actions: ['countGlobal', 'countTotal']
},
BLOCK_FOUND: {
target: 'parsing_block',
actions: [
'initBlock',
'resetBracketDepth',
'countCurrentBlock',
'countTotal'
]
},
MULTILINE_COMMENT_FOUND: 'parsing_multicomment',
COMMENT_FOUND: {
target: 'parsing_global'
},
WHITESPACE_FOUND: {
target: 'parsing_global'
},
END_OF_BLOCK_FOUND: {
target: 'finished_with_error'
}
}
},
parsing_multicomment: {
on: {
MULTILINE_COMMENT_SEGMENT_FOUND: {
target: 'parsing_multicomment'
},
WHITESPACE_FOUND: {
target: 'parsing_multicomment'
},
END_OF_BLOCK_FOUND: {
target: 'parsing_multicomment'
},
MULTILINE_END_FOUND: [{
target: 'parsing_block',
cond: 'isInsideBlock'
}, {
target: 'parsing_global'
}],
EOF_FOUND: 'finished_with_error'
}
},
parsing_block: {
on: {
BLOCK_SECTION: {
target: 'parsing_block',
actions: [
'countCurrentBlock',
'countTotal',
'updateBracketDepth'
]
},
END_OF_BLOCK_FOUND: [{
target: 'parsing_block',
actions: [
'countCurrentBlock',
'countTotal',
'updateBracketDepth'
],
cond: 'isNestedBlock'
}, {
target: 'parsing_global',
actions: ['clearCurrentBlock']
}],
MULTILINE_COMMENT_FOUND: 'parsing_multicomment',
COMMENT_FOUND: {
target: 'parsing_block'
},
WHITESPACE_FOUND: {
target: 'parsing_block'
},
EOF_FOUND: 'finished_with_error'
}
},
finished: {
type: 'final'
},
finished_with_error: {
type: 'final'
}
}
}, {
guards: {
isInsideBlock: (ctx) => !!ctx.currentBlock
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment