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

Function getTokenFromCode

lib/filbert.js:766–843  ·  view source on GitHub ↗
(code)

Source from the content-addressed store, hash-verified

764 }
765
766 function getTokenFromCode(code) {
767 switch(code) {
768
769 case 13: case 10: case 8232: case 8233:
770 ++tokPos;
771 if (code === 13 && input.charCodeAt(tokPos) === 10) ++tokPos;
772 if (options.locations) {
773 ++tokCurLine;
774 tokLineStart = tokPos;
775 }
776 return finishToken(_newline);
777
778 case 35: // '#'
779 skipLineComment();
780 return readToken();
781
782 // The interpretation of a dot depends on whether it is followed
783 // by a digit.
784 case 46: // '.'
785 return readToken_dot();
786
787 // Punctuation tokens.
788 case 40: ++tokPos; return finishToken(_parenL);
789 case 41: ++tokPos; return finishToken(_parenR);
790 case 59: ++tokPos; return finishToken(_semi);
791 case 44: ++tokPos; return finishToken(_comma);
792 case 91: ++tokPos; return finishToken(_bracketL);
793 case 93: ++tokPos; return finishToken(_bracketR);
794 case 123: ++tokPos; return finishToken(_braceL);
795 case 125: ++tokPos; return finishToken(_braceR);
796 case 58: ++tokPos; return finishToken(_colon);
797 case 63: ++tokPos; return finishToken(_question);
798
799 // '0x' is a hexadecimal number.
800 case 48: // '0'
801 var next = input.charCodeAt(tokPos + 1);
802 if (next === 120 || next === 88) return readHexNumber();
803 // Anything else beginning with a digit is an integer, octal
804 // number, or float.
805 case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: // 1-9
806 return readNumber(false);
807
808 // Quotes produce strings.
809 case 34: case 39: // '"', "'"
810 return readString(code);
811
812 // Operators are parsed inline in tiny state machines. '=' (61) is
813 // often referred to. `finishOp` simply skips the amount of
814 // characters it is given as second argument, and returns a token
815 // of the type given by its first argument.
816
817 case 47: // '/'
818 return readToken_slash(code);
819
820 case 42: case 37: // '*%'
821 return readToken_mult_modulo(code);
822
823 case 124: case 38: // '|&'

Callers 1

readTokenFunction · 0.85

Calls 15

finishTokenFunction · 0.85
skipLineCommentFunction · 0.85
readTokenFunction · 0.85
readToken_dotFunction · 0.85
readHexNumberFunction · 0.85
readNumberFunction · 0.85
readStringFunction · 0.85
readToken_slashFunction · 0.85
readToken_mult_moduloFunction · 0.85
readToken_pipe_ampFunction · 0.85
readToken_caretFunction · 0.85
readToken_plus_minFunction · 0.85

Tested by

no test coverage detected