# -*- coding: utf-8 -*- ## frozen_string_literal: truemoduleRougemoduleLexersclassBBCBASIC<RegexLexertitle"BBCBASIC"desc"BBC BASIC syntax"tag'bbcbasic'filenames'*,fd1'defself.punctuation@punctuation||=%w(
[,;'~] SPC TAB
)enddefself.function@function||=%w(
ABS ACS ADVAL ASC ASN ATN BEATS BEAT BGET# CHR\$ COS COUNT DEG DIM
EOF# ERL ERR EVAL EXP EXT# FN GET\$# GET\$ GET HIMEM INKEY\$ INKEY
INSTR INT LEFT\$ LEN LN LOG LOMEM MID\$ OPENIN OPENOUT OPENUP PAGE
POINT POS PTR# RAD REPORT\$ RIGHT\$ RND SGN SIN SQR STR\$ STRING\$ SUM
SUMLEN TAN TEMPO TIME\$ TIME TOP USR VAL VPOS
)enddefself.statement@statement||=%w(
BEATS BPUT# CALL CASE CHAIN CLEAR CLG CLOSE# CLS COLOR COLOUR DATA
ELSE ENDCASE ENDIF ENDPROC ENDWHILE END ENVELOPE FOR GCOL GOSUB GOTO
IF INSTALL LET LIBRARY MODE NEXT OFF OF ON ORIGIN OSCI OTHERWISE
OVERLAY PLOT PRINT# PRINT PROC QUIT READ REPEAT REPORT RETURN SOUND
STEP STEREO STOP SWAP SYS THEN TINT TO VDU VOICES VOICE UNTIL WAIT
WHEN WHILE WIDTH
)enddefself.operator@operator||=%w(
<< <= <> < >= >>> >> > [-!$()*+/=?^|] AND DIV EOR MOD NOT OR
)enddefself.constant@constant||=%w(
FALSE TRUE
)endstate:expressiondorule%r/#{BBCBASIC.function.join('|')}/o,Name::Builtin# function or pseudo-variablerule%r/#{BBCBASIC.operator.join('|')}/o,Operatorrule%r/#{BBCBASIC.constant.join('|')}/o,Name::Constantrule%r/"[^"]*"/o,Literal::Stringrule%r/[a-z_`][\w`]*[$%]?/io,Name::Variablerule%r/@%/o,Name::Variablerule%r/[\d.]+/o,Literal::Numberrule%r/%[01]+/o,Literal::Number::Binrule%r/&[\h]+/o,Literal::Number::Hexendstate:rootdorule%r/(:+)( *)(\*)(.*)/dogroupsPunctuation,Text,Keyword,Text# CLI commandendrule%r/(\n+ *)(\*)(.*)/dogroupsText,Keyword,Text# CLI commandendrule%r/(ELSE|OTHERWISE|REPEAT|THEN)( *)(\*)(.*)/dogroupsKeyword,Text,Keyword,Text# CLI commandendrule%r/[ \n]+/o,Textrule%r/:+/o,Punctuationrule%r/[\[]/o,Keyword,:assembly1rule%r/REM *>.*/o,Comment::Specialrule%r/REM.*/o,Commentrule%r/(?:#{BBCBASIC.statement.join('|')}|CIRCLE(?: *FILL)?|DEF *(?:FN|PROC)|DRAW(?: *BY)?|DIM(?!\()|ELLIPSE(?: *FILL)?|ERROR(?: *EXT)?|FILL(?: *BY)?|INPUT(?:#| *LINE)?|LINE(?: *INPUT)?|LOCAL(?: *DATA| *ERROR)?|MOUSE(?: *COLOUR| *OFF| *ON| *RECTANGLE| *STEP| *TO)?|MOVE(?: *BY)?|ON(?! *ERROR)|ON *ERROR *(?:LOCAL|OFF)?|POINT(?: *BY)?(?!\()|RECTANGE(?: *FILL)?|RESTORE(?: *DATA| *ERROR)?|TRACE(?: *CLOSE| *ENDPROC| *OFF| *STEP(?: *FN| *ON| *PROC)?| *TO)?)/o,Keywordmixin:expressionrule%r/#{BBCBASIC.punctuation.join('|')}/o,Punctuationend# Assembly statements are parsed as# {label} {directive|opcode |']' {expressions}} {comment}# Technically, you don't need whitespace between opcodes and arguments,# but this is rare in uncrunched source and trying to enumerate all# possible opcodes here is impractical so we colour it as though# the whitespace is required. Opcodes and directives can only easily be# distinguished from the symbols that make up expressions by looking at# their position within the statement. Similarly, ']' is treated as a# keyword at the start of a statement or as punctuation elsewhere. This# requires a two-state state machine.state:assembly1dorule%r/ +/o,Textrule%r/]/o,Keyword,:pop!rule%r/[:\n]/o,Punctuationrule%r/\.[a-z_`][\w`]*%? */io,Name::Labelrule%r/(?:REM|;)[^:\n]*/o,Commentrule%r/[^ :\n]+/o,Keyword,:assembly2endstate:assembly2dorule%r/ +/o,Textrule%r/[:\n]/o,Punctuation,:pop!rule%r/(?:REM|;)[^:\n]*/o,Comment,:pop!mixin:expressionrule%r/[!#,@\[\]^{}]/,Punctuationendendendend