Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
webassembly.py120 linesDownload Raw Back to lexers
1"""2    pygments.lexers.webassembly3    ~~~~~~~~~~~~~~~~~~~~~~~~~~~4 5    Lexers for the WebAssembly text format.6 7    The grammar can be found at https://github.com/WebAssembly/spec/blob/master/interpreter/README.md8    and https://webassembly.github.io/spec/core/text/.9 10 11    :copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.12    :license: BSD, see LICENSE for details.13"""14 15from pygments.lexer import RegexLexer, words, bygroups, default16from pygments.token import Text, Comment, Operator, Keyword, String, Number, Punctuation, Name17 18__all__ = ['WatLexer']19 20keywords = (21    'module', 'import', 'func', 'funcref', 'start', 'param', 'local', 'type',22    'result', 'export', 'memory', 'global', 'mut', 'data', 'table', 'elem',23    'if', 'then', 'else', 'end', 'block', 'loop'24)25 26builtins = (27    'unreachable', 'nop', 'block', 'loop', 'if', 'else', 'end', 'br', 'br_if',28    'br_table', 'return', 'call', 'call_indirect', 'drop', 'select',29    'local.get', 'local.set', 'local.tee', 'global.get', 'global.set',30    'i32.load', 'i64.load', 'f32.load', 'f64.load', 'i32.load8_s',31    'i32.load8_u', 'i32.load16_s', 'i32.load16_u', 'i64.load8_s',32    'i64.load8_u', 'i64.load16_s', 'i64.load16_u', 'i64.load32_s',33    'i64.load32_u', 'i32.store', 'i64.store', 'f32.store', 'f64.store',34    'i32.store8', 'i32.store16', 'i64.store8', 'i64.store16', 'i64.store32',35    'memory.size', 'memory.grow', 'i32.const', 'i64.const', 'f32.const',36    'f64.const', 'i32.eqz', 'i32.eq', 'i32.ne', 'i32.lt_s', 'i32.lt_u',37    'i32.gt_s', 'i32.gt_u', 'i32.le_s', 'i32.le_u', 'i32.ge_s', 'i32.ge_u',38    'i64.eqz', 'i64.eq', 'i64.ne', 'i64.lt_s', 'i64.lt_u', 'i64.gt_s',39    'i64.gt_u', 'i64.le_s', 'i64.le_u', 'i64.ge_s', 'i64.ge_u', 'f32.eq',40    'f32.ne', 'f32.lt', 'f32.gt', 'f32.le', 'f32.ge', 'f64.eq', 'f64.ne',41    'f64.lt', 'f64.gt', 'f64.le', 'f64.ge', 'i32.clz', 'i32.ctz', 'i32.popcnt',42    'i32.add', 'i32.sub', 'i32.mul', 'i32.div_s', 'i32.div_u', 'i32.rem_s',43    'i32.rem_u', 'i32.and', 'i32.or', 'i32.xor', 'i32.shl', 'i32.shr_s',44    'i32.shr_u', 'i32.rotl', 'i32.rotr', 'i64.clz', 'i64.ctz', 'i64.popcnt',45    'i64.add', 'i64.sub', 'i64.mul', 'i64.div_s', 'i64.div_u', 'i64.rem_s',46    'i64.rem_u', 'i64.and', 'i64.or', 'i64.xor', 'i64.shl', 'i64.shr_s',47    'i64.shr_u', 'i64.rotl', 'i64.rotr', 'f32.abs', 'f32.neg', 'f32.ceil',48    'f32.floor', 'f32.trunc', 'f32.nearest', 'f32.sqrt', 'f32.add', 'f32.sub',49    'f32.mul', 'f32.div', 'f32.min', 'f32.max', 'f32.copysign', 'f64.abs',50    'f64.neg', 'f64.ceil', 'f64.floor', 'f64.trunc', 'f64.nearest', 'f64.sqrt',51    'f64.add', 'f64.sub', 'f64.mul', 'f64.div', 'f64.min', 'f64.max',52    'f64.copysign', 'i32.wrap_i64', 'i32.trunc_f32_s', 'i32.trunc_f32_u',53    'i32.trunc_f64_s', 'i32.trunc_f64_u', 'i64.extend_i32_s',54    'i64.extend_i32_u', 'i64.trunc_f32_s', 'i64.trunc_f32_u',55    'i64.trunc_f64_s', 'i64.trunc_f64_u', 'f32.convert_i32_s',56    'f32.convert_i32_u', 'f32.convert_i64_s', 'f32.convert_i64_u',57    'f32.demote_f64', 'f64.convert_i32_s', 'f64.convert_i32_u',58    'f64.convert_i64_s', 'f64.convert_i64_u', 'f64.promote_f32',59    'i32.reinterpret_f32', 'i64.reinterpret_f64', 'f32.reinterpret_i32',60    'f64.reinterpret_i64',61)62 63 64class WatLexer(RegexLexer):65    """Lexer for the WebAssembly text format.66    """67 68    name = 'WebAssembly'69    url = 'https://webassembly.org/'70    aliases = ['wast', 'wat']71    filenames = ['*.wat', '*.wast']72    version_added = '2.9'73 74    tokens = {75        'root': [76            (words(keywords, suffix=r'(?=[^a-z_\.])'), Keyword),77            (words(builtins), Name.Builtin, 'arguments'),78            (words(['i32', 'i64', 'f32', 'f64']), Keyword.Type),79            (r'\$[A-Za-z0-9!#$%&\'*+./:<=>?@\\^_`|~-]+', Name.Variable), # yes, all of the are valid in identifiers80            (r';;.*?$', Comment.Single),81            (r'\(;', Comment.Multiline, 'nesting_comment'),82            (r'[+-]?0x[\dA-Fa-f](_?[\dA-Fa-f])*(.([\dA-Fa-f](_?[\dA-Fa-f])*)?)?([pP][+-]?[\dA-Fa-f](_?[\dA-Fa-f])*)?', Number.Float),83            (r'[+-]?\d.\d(_?\d)*[eE][+-]?\d(_?\d)*', Number.Float),84            (r'[+-]?\d.\d(_?\d)*', Number.Float),85            (r'[+-]?\d.[eE][+-]?\d(_?\d)*', Number.Float),86            (r'[+-]?(inf|nan:0x[\dA-Fa-f](_?[\dA-Fa-f])*|nan)', Number.Float),87            (r'[+-]?0x[\dA-Fa-f](_?[\dA-Fa-f])*', Number.Hex),88            (r'[+-]?\d(_?\d)*', Number.Integer),89            (r'[\(\)]', Punctuation),90            (r'"', String.Double, 'string'),91            (r'\s+', Text),92        ],93        'nesting_comment': [94            (r'\(;', Comment.Multiline, '#push'),95            (r';\)', Comment.Multiline, '#pop'),96            (r'[^;(]+', Comment.Multiline),97            (r'[;(]', Comment.Multiline),98        ],99        'string': [100            (r'\\[\dA-Fa-f][\dA-Fa-f]', String.Escape), # must have exactly two hex digits101            (r'\\t', String.Escape),102            (r'\\n', String.Escape),103            (r'\\r', String.Escape),104            (r'\\"', String.Escape),105            (r"\\'", String.Escape),106            (r'\\u\{[\dA-Fa-f](_?[\dA-Fa-f])*\}', String.Escape),107            (r'\\\\', String.Escape),108            (r'"', String.Double, '#pop'),109            (r'[^"\\]+', String.Double),110        ],111        'arguments': [112            (r'\s+', Text),113            (r'(offset)(=)(0x[\dA-Fa-f](_?[\dA-Fa-f])*)', bygroups(Keyword, Operator, Number.Hex)),114            (r'(offset)(=)(\d(_?\d)*)', bygroups(Keyword, Operator, Number.Integer)),115            (r'(align)(=)(0x[\dA-Fa-f](_?[\dA-Fa-f])*)', bygroups(Keyword, Operator, Number.Hex)),116            (r'(align)(=)(\d(_?\d)*)', bygroups(Keyword, Operator, Number.Integer)),117            default('#pop'),118        ]119    }120 
codekingpro/portable-devtools · Team Ai