MCPcopy Create free account
hub / github.com/davidkingzyb/SCAST / parse_define

Function parse_define

js/SCAST.js:350–407  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

348 return tok && tok.type == "kw" && ((!ch && keywords.indexOf(tok.value)>=0) || tok.value == ch) && tok;
349 }
350 function parse_define(){
351 var r={
352 type:'',
353 level:input.peek().value,
354 is_sp:false,
355 ids:[],
356 return_type:null,
357 value:null,
358 nodes:[],
359 poi:{start:input.peek().poi.start,line:input.peek().poi.line},
360 }
361 while(!(is_punc('(')||is_punc('{')||is_op('=')||is_sp(';'))){
362 r.nodes.push(input.peek())
363 if(is_sp(':')||is_kw("extends")||is_kw("implements")){
364 r.is_sp=true
365 }else if(is_kw("class")){
366 r.type="ClassDefine"
367 }else if(is_kw("interface")){
368 r.type='InterfaceDefine'
369 }else if(is_kw("namespace")){
370 r.type='NamespaceDefine'
371 }else if(is_kw("void")){
372 r.return_type="void"
373 }
374 var n=input.next()//after next() not call peek()
375 if(n.type=='id'){
376 r.ids.push(n.value)
377 }
378 }
379 if(is_punc('(')){
380 r.type="MethodDefine"
381 r.value=r.ids.slice(-1)[0]
382 if(!r.return_type){
383 r.return_type=r.ids[0]//can ignore
384 }
385 r.parameter=parse_arguments()//todo parameter
386 if(is_sp(':')){//charp constructor with extended class
387 input.next();
388 r.base=input.peek()
389 input.next();
390 if(is_punc('('))r.base.parameter=parse_arguments();
391 }
392 if(is_punc('{'))r.body=parse_block().body
393 }else if(r.type=="ClassDefine"||r.type=="InterfaceDefine"||r.type=="NamespaceDefine"){
394 r.value=r.ids[0]
395 if(r.is_sp){
396 r.extends=r.ids.slice(1)
397 }
398 if(is_punc('{'))r.body=parse_block().body
399 }else if(!r.type){
400 r.type="PropertyDefine"
401 r.value=r.ids.slice(-1)[0]
402 if(is_op('=')){
403 r.body=[parse_variable(r.value)]
404 }
405 }
406 return r
407 }

Callers 1

parse_statementFunction · 0.70

Calls 7

is_puncFunction · 0.70
is_opFunction · 0.70
is_spFunction · 0.70
is_kwFunction · 0.70
parse_argumentsFunction · 0.70
parse_blockFunction · 0.70
parse_variableFunction · 0.70

Tested by

no test coverage detected