-
Notifications
You must be signed in to change notification settings - Fork 513
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add src/py_tokens.js. Related to issue #2354
- Loading branch information
1 parent
c7e12b4
commit 1e805df
Showing
1 changed file
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
// Token constants | ||
|
||
(function($B){ | ||
|
||
const tokens = [ | ||
'ENDMARKER', | ||
'NAME', | ||
'NUMBER', | ||
'STRING', | ||
'NEWLINE', | ||
'INDENT', | ||
'DEDENT', | ||
'LPAR', | ||
'RPAR', | ||
'LSQB', | ||
'RSQB', | ||
'COLON', | ||
'COMMA', | ||
'SEMI', | ||
'PLUS', | ||
'MINUS', | ||
'STAR', | ||
'SLASH', | ||
'VBAR', | ||
'AMPER', | ||
'LESS', | ||
'GREATER', | ||
'EQUAL', | ||
'DOT', | ||
'PERCENT', | ||
'LBRACE', | ||
'RBRACE', | ||
'EQEQUAL', | ||
'NOTEQUAL', | ||
'LESSEQUAL', | ||
'GREATEREQUAL', | ||
'TILDE', | ||
'CIRCUMFLEX', | ||
'LEFTSHIFT', | ||
'RIGHTSHIFT', | ||
'DOUBLESTAR', | ||
'PLUSEQUAL', | ||
'MINEQUAL', | ||
'STAREQUAL', | ||
'SLASHEQUAL', | ||
'PERCENTEQUAL', | ||
'AMPEREQUAL', | ||
'VBAREQUAL', | ||
'CIRCUMFLEXEQUAL', | ||
'LEFTSHIFTEQUAL', | ||
'RIGHTSHIFTEQUAL', | ||
'DOUBLESTAREQUAL', | ||
'DOUBLESLASH', | ||
'DOUBLESLASHEQUAL', | ||
'AT', | ||
'ATEQUAL', | ||
'RARROW', | ||
'ELLIPSIS', | ||
'COLONEQUAL', | ||
'EXCLAMATION', | ||
'OP', | ||
'AWAIT', | ||
'ASYNC', | ||
'TYPE_IGNORE', | ||
'TYPE_COMMENT', | ||
'SOFT_KEYWORD', | ||
'FSTRING_START', | ||
'FSTRING_MIDDLE', | ||
'FSTRING_END', | ||
'COMMENT', | ||
'NL', | ||
// These aren't used by the C tokenizer but are needed for tokenize.py | ||
'ERRORTOKEN', | ||
'ENCODING', | ||
'N_TOKENS' | ||
] | ||
|
||
$B.py_tokens = {} | ||
|
||
var pos = 0 | ||
for(var tok of tokens){ | ||
$B.py_tokens[tok] = pos++ | ||
} | ||
|
||
// Special definitions for cooperation with parser | ||
$B.py_tokens['NT_OFFSET'] = 256 | ||
|
||
$B.EXACT_TOKEN_TYPES = { | ||
'!': 'EXCLAMATION', | ||
'!=': 'NOTEQUAL', | ||
'%': 'PERCENT', | ||
'%=': 'PERCENTEQUAL', | ||
'&': 'AMPER', | ||
'&=': 'AMPEREQUAL', | ||
'(': 'LPAR', | ||
')': 'RPAR', | ||
'*': 'STAR', | ||
'**': 'DOUBLESTAR', | ||
'**=': 'DOUBLESTAREQUAL', | ||
'*=': 'STAREQUAL', | ||
'+': 'PLUS', | ||
'+=': 'PLUSEQUAL', | ||
',': 'COMMA', | ||
'-': 'MINUS', | ||
'-=': 'MINEQUAL', | ||
'->': 'RARROW', | ||
'.': 'DOT', | ||
'...': 'ELLIPSIS', | ||
'/': 'SLASH', | ||
'//': 'DOUBLESLASH', | ||
'//=': 'DOUBLESLASHEQUAL', | ||
'/=': 'SLASHEQUAL', | ||
':': 'COLON', | ||
':=': 'COLONEQUAL', | ||
';': 'SEMI', | ||
'<': 'LESS', | ||
'<<': 'LEFTSHIFT', | ||
'<<=': 'LEFTSHIFTEQUAL', | ||
'<=': 'LESSEQUAL', | ||
'=': 'EQUAL', | ||
'==': 'EQEQUAL', | ||
'>': 'GREATER', | ||
'>=': 'GREATEREQUAL', | ||
'>>': 'RIGHTSHIFT', | ||
'>>=': 'RIGHTSHIFTEQUAL', | ||
'@': 'AT', | ||
'@=': 'ATEQUAL', | ||
'[': 'LSQB', | ||
']': 'RSQB', | ||
'^': 'CIRCUMFLEX', | ||
'^=': 'CIRCUMFLEXEQUAL', | ||
'{': 'LBRACE', | ||
'|': 'VBAR', | ||
'|=': 'VBAREQUAL', | ||
'}': 'RBRACE', | ||
'~': 'TILDE' | ||
} | ||
|
||
function ISTERMINAL(x){ | ||
return x < NT_OFFSET | ||
} | ||
|
||
function ISNONTERMINAL(x){ | ||
return x >= NT_OFFSET | ||
} | ||
|
||
function ISEOF(x){ | ||
return x == ENDMARKER | ||
} | ||
|
||
})(__BRYTHON__) |