Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
snobol.py83 linesDownload Raw Back to lexers
1"""2    pygments.lexers.snobol3    ~~~~~~~~~~~~~~~~~~~~~~4 5    Lexers for the SNOBOL language.6 7    :copyright: Copyright 2006-2024 by the Pygments team, see AUTHORS.8    :license: BSD, see LICENSE for details.9"""10 11from pygments.lexer import RegexLexer, bygroups12from pygments.token import Text, Comment, Operator, Keyword, Name, String, \13    Number, Punctuation14 15__all__ = ['SnobolLexer']16 17 18class SnobolLexer(RegexLexer):19    """20    Lexer for the SNOBOL4 programming language.21 22    Recognizes the common ASCII equivalents of the original SNOBOL4 operators.23    Does not require spaces around binary operators.24    """25 26    name = "Snobol"27    aliases = ["snobol"]28    filenames = ['*.snobol']29    mimetypes = ['text/x-snobol']30    url = 'https://www.regressive.org/snobol4'31    version_added = '1.5'32 33    tokens = {34        # root state, start of line35        # comments, continuation lines, and directives start in column 136        # as do labels37        'root': [38            (r'\*.*\n', Comment),39            (r'[+.] ', Punctuation, 'statement'),40            (r'-.*\n', Comment),41            (r'END\s*\n', Name.Label, 'heredoc'),42            (r'[A-Za-z$][\w$]*', Name.Label, 'statement'),43            (r'\s+', Text, 'statement'),44        ],45        # statement state, line after continuation or label46        'statement': [47            (r'\s*\n', Text, '#pop'),48            (r'\s+', Text),49            (r'(?<=[^\w.])(LT|LE|EQ|NE|GE|GT|INTEGER|IDENT|DIFFER|LGT|SIZE|'50             r'REPLACE|TRIM|DUPL|REMDR|DATE|TIME|EVAL|APPLY|OPSYN|LOAD|UNLOAD|'51             r'LEN|SPAN|BREAK|ANY|NOTANY|TAB|RTAB|REM|POS|RPOS|FAIL|FENCE|'52             r'ABORT|ARB|ARBNO|BAL|SUCCEED|INPUT|OUTPUT|TERMINAL)(?=[^\w.])',53             Name.Builtin),54            (r'[A-Za-z][\w.]*', Name),55            # ASCII equivalents of original operators56            # | for the EBCDIC equivalent, ! likewise57            # \ for EBCDIC negation58            (r'\*\*|[?$.!%*/#+\-@|&\\=]', Operator),59            (r'"[^"]*"', String),60            (r"'[^']*'", String),61            # Accept SPITBOL syntax for real numbers62            # as well as Macro SNOBOL463            (r'[0-9]+(?=[^.EeDd])', Number.Integer),64            (r'[0-9]+(\.[0-9]*)?([EDed][-+]?[0-9]+)?', Number.Float),65            # Goto66            (r':', Punctuation, 'goto'),67            (r'[()<>,;]', Punctuation),68        ],69        # Goto block70        'goto': [71            (r'\s*\n', Text, "#pop:2"),72            (r'\s+', Text),73            (r'F|S', Keyword),74            (r'(\()([A-Za-z][\w.]*)(\))',75             bygroups(Punctuation, Name.Label, Punctuation))76        ],77        # everything after the END statement is basically one78        # big heredoc.79        'heredoc': [80            (r'.*\n', String.Heredoc)81        ]82    }83 
codekingpro/portable-devtools · Team Ai