MCPcopy Index your code
hub / github.com/stemkoski/stemkoski.github.com / advance

Function advance

MathBox/mathbox-core.js:32723–32772  ·  view source on GitHub ↗
(id)

Source from the content-addressed store, hash-verified

32721}
32722
32723function advance(id) {
32724 var next
32725 , value
32726 , type
32727 , output
32728
32729 if(id && token.data !== id) {
32730 return state.unexpected('expected `'+ id + '`, got `'+token.data+'`')
32731 }
32732
32733 if(idx >= tokens.length) {
32734 token = symbol_table['(end)']
32735 return
32736 }
32737
32738 next = tokens[idx++]
32739 value = next.data
32740 type = next.type
32741
32742 if(type === 'ident') {
32743 output = state.scope.find(value) || state.create_node()
32744 type = output.type
32745 } else if(type === 'builtin') {
32746 output = symbol_table['(builtin)']
32747 } else if(type === 'keyword') {
32748 output = symbol_table['(keyword)']
32749 } else if(type === 'operator') {
32750 output = symbol_table[value]
32751 if(!output) {
32752 return state.unexpected('unknown operator `'+value+'`')
32753 }
32754 } else if(type === 'float' || type === 'integer') {
32755 type = 'literal'
32756 output = symbol_table['(literal)']
32757 } else {
32758 return state.unexpected('unexpected token.')
32759 }
32760
32761 if(output) {
32762 if(!output.nud) { output.nud = itself }
32763 if(!output.children) { output.children = [] }
32764 }
32765
32766 output = Object.create(output)
32767 output.token = next
32768 output.type = type
32769 if(!output.data) output.data = value
32770
32771 return token = output
32772}
32773
32774function fail(message) {
32775 return function() { return state.unexpected(message) }

Callers 3

mathbox-core.jsFile · 0.70
expressionFunction · 0.70
setup_stative_parsersFunction · 0.70

Calls 1

assertFunction · 0.70

Tested by

no test coverage detected