parallaxinc / Parallax-IDE

Parallax microcontroller development environment based on Chrome applications.
MIT License
36 stars 12 forks source link

BASIC Stamp Syntax Style Details #71

Open PropGit opened 9 years ago

PropGit commented 9 years ago

Here's some detail about PBASIC Syntax Styles.

As I said in our hangout, the reserved-word list (which includes every element that need be syntax highlighted) is a dynamic list that changes depending on the exact module (BS2, BS2e, BS2sx, etc.) as well as the version of the PBASIC Language (2.0 or 2.5) that the code is actually written for. The mode of operation for the app is to invoke the GetReservedWord function from the tokenizer, on the code that is visible in the App, to retrieve the proper reserved word list, then apply the syntax highlighting styles according to the defined types as specified in the reserved word list. This must happen every time the code in the visible editor is loaded or syntax checked, as well as any time the $STAMP or $PBASIC directives are automatically changed by the App.

Here's the enumerations and arrays defined in the BASIC Stamp Editor which help map the GetReservedWord's response to the styles and rules.

NOTE: SynCommand through SynVariableType are enumerated IDs representing syntax types. I didn't include that enumeration here because it's confusingly large since it's part of a bit preference setting enumerated set.

{==============================================================================}
{========================== TTokenStyleID Type ================================}
{==============================================================================}
  {Note, this list MUST appear in the same order as the token code constants, starting from tokNone.
  Starting with tsCustom, any additional style IDs can be added.}
  TTokenStyleID = (tsNone = -1, tsEOF, tsString, tsComment, tsSymbol, tsDecimal, tsHexadecimal, tsBinary, tsNormal, tsCustom);

  {Define Custom Token Styles.  These are defined in the order that they are presented by the GetReservedWord function of
  the tokenizer.}
  CTSTokenStyle = (ctsDirective = ord(tsCustom), ctsTargetModule, ctsCCDirective, ctsInstruction, ctsDeclaration,
                   ctsVariable, ctsVariableType, ctsVariableMod, ctsIOFormatter, ctsConditionalOp, ctsBinaryOp,
                   ctsUnaryOp, ctsConstant, ctsPeriod, ctsComma, ctsQuestionMark, ctsBackslash, ctsAtSign,
                   ctsParentheses, ctsBrackets);

The DScheme array is a two-dimensional array that defines the default syntax highlighting schemes for Plain Text, Simple, and PBASIC syntax schemes. Each of these are pre-defined so that customers can choose to use a plain, very "light" highlighting, or full syntax highlighting; however, we are only targeting PBASIC syntax highlighting at this time in this Chrome IDE project. Be sure to read the comments below as they relate to the hex and decimal values for each row of the default array. Note that each row has a comment (in curly braces { and }) that indicates the scheme and the element style.

  {Define default (built-in) syntax highlighting schemes.
   Note: Order is: Font Color, Background Color, Text Style, Case Style.
         The Color styles are actual color values ($0000000..$0FFFFFF) or indicates a default value ($1000000).
         Text Style is a 6-bit value consisting of 3 2-bit pairs.  For each pair, the LSB indicates if that attribute is
         enabled or not.  The MSB is unused here, but is used to indicate if a parent's children differ in that setting.
         The pair order, from left to right is: fsUnderline, fsItalic, fsBold (ie: Bit0=fsBold, Bit2=fsItalic, Bit4=fsUnderline).
         Case Style is a number from 0 to 3, 0=No Change, 1=Upper case, 2=Lower Case, 3=Capitalize.}
  DScheme: array [0..2, SynCommand..SynVariableType] of String =      {The default schemes settings}
    ( ( {Plain Text, SynCommand}               '$1000000,$1000000,$00,0',
        {Plain Text, SynComment}               '$1000000,$1000000,$00,0',
        {Plain Text, SynConstantBinary}        '$1000000,$1000000,$00,0',
        {Plain Text, SynConstantDecimal}       '$1000000,$1000000,$00,0',
        {Plain Text, SynConstantHexadecimal}   '$1000000,$1000000,$00,0',
        {Plain Text, SynConstantPredefined}    '$1000000,$1000000,$00,0',
        {Plain Text, SynConstantString}        '$1000000,$1000000,$00,0',
        {Plain Text, SynDefault}               '$0000000,$0FFFFFF,$00,0',
        {Plain Text, SynOperatorBinary}        '$1000000,$1000000,$00,0',
        {Plain Text, SynOperatorConditional}   '$1000000,$1000000,$00,0',
        {Plain Text, SynOperatorUnary}         '$1000000,$1000000,$00,0',
        {Plain Text, SynDeclaration}           '$1000000,$1000000,$00,0',
        {Plain Text, SynDirectiveCondCompile}  '$1000000,$1000000,$00,0',
        {Plain Text, SynDirectiveEditor}       '$1000000,$1000000,$00,0',
        {Plain Text, SynDirectiveTargetModule} '$1000000,$1000000,$00,0',
        {Plain Text, SynIOFormatter}           '$1000000,$1000000,$00,0',
        {Plain Text, SynSelectionMarkedBlock}  '$0FFFFFF,$0800000,$00,0',
        {Plain Text, SynSelectionSearchMatch}  '$000FF00,$0000000,$00,0',
        {Plain Text, SynVariableModifier}      '$1000000,$1000000,$00,0',
        {Plain Text, SynVariablePredefined}    '$1000000,$1000000,$00,0',
        {Plain Text, SynVariableType}          '$1000000,$1000000,$00,0'
      ),
      ( {Simple, SynCommand}                   '$1000000,$1000000,$00,1',
        {Simple, SynComment}                   '$0008000,$1000000,$00,0',
        {Simple, SynConstantBinary}            '$1000000,$1000000,$00,0',
        {Simple, SynConstantDecimal}           '$1000000,$1000000,$00,0',
        {Simple, SynConstantHexadecimal}       '$1000000,$1000000,$00,0',
        {Simple, SynConstantPredefined}        '$1000000,$1000000,$00,1',
        {Simple, SynConstantString}            '$1000000,$1000000,$00,0',
        {Simple, SynDefault}                   '$0000000,$0FFFFFF,$00,0',
        {Simple, SynOperatorBinary}            '$1000000,$1000000,$00,1',
        {Simple, SynOperatorConditional}       '$1000000,$1000000,$00,1',
        {Simple, SynOperatorUnary}             '$1000000,$1000000,$00,1',
        {Simple, SynDeclaration}               '$1000000,$1000000,$00,1',
        {Simple, SynDirectiveCondCompile}      '$1000000,$1000000,$00,1',
        {Simple, SynDirectiveEditor}           '$1000000,$1000000,$00,1',
        {Simple, SynDirectiveTargetModule}     '$1000000,$1000000,$00,1',
        {Simple, SynIOFormatter}               '$1000000,$1000000,$00,1',
        {Simple, SynSelectionMarkedBlock}      '$0FFFFFF,$0800000,$00,0',
        {Simple, SynSelectionSearchMatch}      '$000FF00,$0000000,$00,0',
        {Simple, SynVariableModifier}          '$1000000,$1000000,$00,1',
        {Simple, SynVariablePredefined}        '$1000000,$1000000,$00,1',
        {Simple, SynVariableType}              '$1000000,$1000000,$00,3'
      ),
      ( {PBASIC, SynCommand}                   '$0FF0000,$1000000,$00,1',
        {PBASIC, SynComment}                   '$0008000,$1000000,$00,0',
        {PBASIC, SynConstantBinary}            '$1000000,$1000000,$00,0',
        {PBASIC, SynConstantDecimal}           '$1000000,$1000000,$00,0',
        {PBASIC, SynConstantHexadecimal}       '$1000000,$1000000,$00,0',
        {PBASIC, SynConstantPredefined}        '$0800080,$1000000,$00,1',
        {PBASIC, SynConstantString}            '$00000FF,$1000000,$00,0',
        {PBASIC, SynDefault}                   '$0000000,$0FFFFFF,$00,0',
        {PBASIC, SynOperatorBinary}            '$1000000,$1000000,$00,1',
        {PBASIC, SynOperatorConditional}       '$1000000,$1000000,$00,1',
        {PBASIC, SynOperatorUnary}             '$1000000,$1000000,$00,1',
        {PBASIC, SynDeclaration}               '$1000000,$1000000,$00,1',
        {PBASIC, SynDirectiveCondCompile}      '$0808080,$1000000,$01,1',
        {PBASIC, SynDirectiveEditor}           '$0808000,$1000000,$01,1',
        {PBASIC, SynDirectiveTargetModule}     '$0808000,$1000000,$01,1',
        {PBASIC, SynIOFormatter}               '$0800000,$1000000,$00,1',
        {PBASIC, SynSelectionMarkedBlock}      '$0FFFFFF,$0800000,$00,0',
        {PBASIC, SynSelectionSearchMatch}      '$000FF00,$0000000,$00,0',
        {PBASIC, SynVariableModifier}          '$1000000,$1000000,$00,1',
        {PBASIC, SynVariablePredefined}        '$0800080,$1000000,$00,1',
        {PBASIC, SynVariableType}              '$1000000,$1000000,$00,3'
      )
    );

Note: the ctsInstruction, tsComment, etc. values are ordinals that represent (align to) the values delivered by the tokenizer's GetReservedWord function

  {Define Token Style translations.  This translates the ordinal "Syn" preference entities into the respective token
  style "ts" or custom token style "cts" ordinals for use with the ConfigureStyle Editor routine.}
  TokenStyleTranslation: array [SynCommand..SynVariableType] of Integer =
    ( {SynCommand}               ord(ctsInstruction),
      {SynComment}               ord(tsComment),
      {SynConstantBinary}        ord(tsBinary),
      {SynConstantDecimal}       ord(tsDecimal),
      {SynConstantHexadecimal}   ord(tsHexadecimal),
      {SynConstantPredefined}    ord(ctsConstant),
      {SynConstantString}        ord(tsString),
      {SynDefault}               ord(tsSymbol),
      {SynOperatorBinary}        ord(ctsBinaryOp),
      {SynOperatorConditional}   ord(ctsConditionalOp),
      {SynOperatorUnary}         ord(ctsUnaryOp),
      {SynDeclaration}           ord(ctsDeclaration),
      {SynDirectiveCondCompile}  ord(ctsCCDirective),
      {SynDirectiveEditor}       ord(ctsDirective),
      {SynDirectiveTargetModule} ord(ctsTargetModule),
      {SynIOFormatter}           ord(ctsIOFormatter),
      {SynSelectionMarkedBlock}  ord(tsNormal),        {This is just a placeholder since MarkedBlock is not really a syntax style. tsNormal is manually overwritten in the SetEditorTokenStyles routine.}
      {SynSelectionSearchMatch}  ord(tsNormal),        {This is just a placeholder since SearchMatch is not really a syntax style. tsNormal is manually overwritten in the SetEditorTokenStyles routine.}
      {SynVariableModifier}      ord(ctsVariableMod),
      {SynVariablePredefined}    ord(ctsVariable),
      {SynVariableType}          ord(ctsVariableType)
    );

Here's some code that registers custom parsers or certain types of elements. Not sure this code is helpful at all because it related directly to the low-level parser that I used in the original editor, but here it is anyway in case a little information can be gleaned... like binary numbers start is %.

{##############################################################################}
{############################ TPBASICParser Routines ##########################}
{##############################################################################}

{ºººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººº}
{ºººººººººººººººººººººººººº     Private Routines     ºººººººººººººººººººººººººº}
{ºººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººº}

procedure TPBASICParser.InitPBASICSyntax;
{Set up parsers}
begin
  InitCommon;
  RegisterProc([psNormal], [''''], ParseComment);
  RegisterProc([psNormal], FirstSymChar, ParseReservedWord);
  RegisterProc([psNormal], ['"'], ParseString);
  RegisterProc([psNormal], ['$'], ParseHexadecimalConstant);
  RegisterProc([psNormal], ['%'], ParseBinaryConstant);
  RegisterProc([psNormal], DecDigit, ParseDecimalConstant);
end;

{ºººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººº}
{ººººººººººººººººººººººººº     Protected Routines     ººººººººººººººººººººººººº}
{ºººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººº}

function TPBASICParser.ParseComment: Integer;
{Parse single-line comment}
begin
  DCIncPtr(FSourcePtr);     {Move to next character (after the apostrophe ('))}
  Result := RestIsComment;  {Mark all to EOL as comment}
end;

{------------------------------------------------------------------------------}

function TPBASICParser.ParseReservedWord: Integer;
{Parse reserved words}
var
  SChar      : Integer;
  ResWordID  : Integer;
begin
  with Editor.TPCustomDCMemo(EditPage.ActivePage.Controls[1]).MemoSource do
    begin
    SChar := Self.CharPos;             {Remember start of token}
    Result := ord(tsSymbol);           {Assume it is not a reserved word}
    repeat DCIncPtr(FSourcePtr) until not (FSourcePtr^ in NextSymChar);
    if ReservedWords.IsReservedWord(TokenString, ResWordID) then
      begin                            {Otherwise, mark as reserved word and set Uppercase Token flag if necessary}
      Result := ResWordID;

      if not (TokenCaseUpdating) and (moColorSyntax in FEditor.FEditSheet[FEditor.ActiveIdx].FEdit1.Options) and
         (FEditor.FEditSheet[FEditor.ActiveIdx].Edit1.TextStyles.Items[Result].CaseStyle <> csNoChange) and
         (TokenString <> SetStringCase(TokenString, FEditor.FEditSheet[FEditor.ActiveIdx].Edit1.TextStyles.Items[Result].CaseStyle)) and
         (not ((Self.LinePos = CurLinePos) and (CurCharPos+1 in [SChar+1..Self.CharPos]))) then
        begin {Needs case change, flag it}
        New(TokenCaseUpdateRec);
        TokenCaseUpdateRec^.Line := Self.LinePos;
        TokenCaseUpdateRec^.SChar := SChar+1;
        TokenCaseUpdateRec^.EChar := Self.CharPos;
        TokenCaseUpdateRec^.Style := FEditor.FEditSheet[FEditor.ActiveIdx].Edit1.TextStyles.Items[Result].CaseStyle;
        TokenCaseUpdateList.Add(TokenCaseUpdateRec);    {Add TokenCaseUpdateRec to the list}
        end;
      end
    end;
end;

{------------------------------------------------------------------------------}

function  TPBASICParser.SetStringCase(Str: String; Style: TCaseStyle): String;
{Set str's case to what is indicated by Style}
begin
  Result := Str;
  case Style of
    csUppercase : Result := uppercase(Str);
    csLowercase : Result := lowercase(Str);
    csCapitalize: if length(Str) > 0 then Result := uppercase(Str[1])+lowercase(copy(Str,2,length(Str)-1));
  end;
end;

{------------------------------------------------------------------------------}

procedure TPBASICParser.SetTokenCase;
{Change case of token in source.  This routine is normally called by MemoStateChange and is based on results of the
 ParseReservedWord call(s).  If the token is a reserved word, and its style is not set to csNoChange, the
 ParseReservedWord call will display it in the proper case, but the source can not be changed until the cursor has moved
 away from the word, indicating the user really meant that token (rather than another one that just happened to have
 some common characters). This routine should only be triggered by cursor movement (as determined by MemoStateChange)
 or another source-dependent operation (Save, SaveAs, Print, TabChange) to officially set the source to the appropriate case.}
var
  Token : String;
begin
  with Editor.TPCustomDCMemo(EditPage.ActivePage.Controls[1]).MemoSource do
    begin
    TokenCaseUpdating := True;
    while TokenCaseUpdateList.Count > 0 do
      begin {For all tokens that need their case updated...}
      TokenCaseUpdateRec := TokenCaseUpdateList.Items[0];
      Token := Lines[TokenCaseUpdateRec.Line];
      Token := System.copy(Token,TokenCaseUpdateRec.SChar,TokenCaseUpdateRec.EChar-TokenCaseUpdateRec.SChar+1);
      Lines[TokenCaseUpdateRec.Line] := System.copy(Lines[TokenCaseUpdateRec.Line],1,TokenCaseUpdateRec.SChar-1)+SetStringCase(Token,TokenCaseUpdateRec.Style)+System.copy(Lines[TokenCaseUpdateRec.Line],TokenCaseUpdateRec.EChar+1,length(Lines[TokenCaseUpdateRec.Line])-TokenCaseUpdateRec.EChar);
      Dispose(TokenCaseUpdateRec);
      TokenCaseUpdateList.Delete(0);
      end;
    TokenCaseUpdateList.Capacity := 0;
    Editor.TPCustomDCMemo(EditPage.ActivePage.Controls[1]).UpdateCaret;  {Force edit control to show current caret position}
    Editor.TPCustomDCMemo(EditPage.ActivePage.Controls[1]).Invalidate;   {Force edit control to repaint (shows entire selection block, if one exists)}
    end;
    TokenCaseUpdating := False;
end;

{------------------------------------------------------------------------------}

function TPBASICParser.ParseString: Integer;
{Parse quoted string}
begin
  Result := ParseUniStrConst('"');
end;

{------------------------------------------------------------------------------}

function TPBASICParser.ParseDecimalConstant: Integer;
{Parse decimal number constant}
begin
  while FSourcePtr^ in DecDigit do DCIncPtr(FSourcePtr);
  Result := ord(tsDecimal);
end;

{------------------------------------------------------------------------------}

function TPBASICParser.ParseHexadecimalConstant: Integer;
{Parse hexadecimal number constant, or directive symbol}
var
  StartPtr : PChar;
  ResWordID : Integer;

    {---------------------------------------}

    function ParseHex: Integer;
    begin
      Result := ord(tsNone);
      if FSourcePtr^ in HexDigit then
        begin {If at least one valid hexadecimal character after the '$'...}
        while FSourcePtr^ in HexDigit do DCIncPtr(FSourcePtr);
        Result := ord(tsHexadecimal);
        end;
    end;

    {---------------------------------------}

begin
  StartPtr := FSourcePtr;    {Remember start of token (the '$')}
  DCIncPtr(FSourcePtr);      {Move to next character}
  if not (FSourcePtr^ in NextSymChar) then
    Result := ParseHex       {Look for hexadecimal value}
  else
    begin                    {May be a directive symbol}
    while (FSourcePtr^ in NextSymChar) do DCIncPtr(FSourcePtr);
    if ReservedWords.IsReservedWord(copy(StartPtr,0,FSourcePtr-StartPtr),ResWordID) then
      Result := ord(tsCustom){Found editor directive symbol}
    else
      begin                  {Otherwise, may be hexadecimal value afterall}
      FSourcePtr := StartPtr;{Move back to start}
      DCIncPtr(FSourcePtr);  {Move to next character}
      Result := ParseHex;    {Look for hexadecimal value}
      end;
    end
end;

{------------------------------------------------------------------------------}

function TPBASICParser.ParseBinaryConstant: Integer;
{Parse binary number constant}
begin
  Result := ord(tsNone);
  DCIncPtr(FSourcePtr);
  if FSourcePtr^ in BinDigit then
    begin {If at least one valid binary character after the '%'...}
    while FSourcePtr^ in BinDigit do DCIncPtr(FSourcePtr);
    Result := ord(tsBinary);
    end;
end;

{ºººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººº}
{ººººººººººººººººººººººººººº     Public Routines     ºººººººººººººººººººººººººº}
{ºººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººººº}

constructor TPBASICParser.CreateParented(AOwner: TComponent; AEditor: TEditor);
begin
  Create(AOwner);
  {Set FEditor so we can access the FEditSheet.FSource}
  FEditor := AEditor;
  {Create the Reserved Words interface}
  ReservedWords := TReservedWords.Create(AEditor);
  {Initialize parsing syntax}
  InitPBASICSyntax;
end;

{------------------------------------------------------------------------------}

destructor TPBASICParser.Destroy;
begin
  ReservedWords.Free;
  inherited Destroy;
end;
PropGit commented 9 years ago

Here are the reserved words for the BS2 stamp with PBASIC 2.5. Sorry, this list doesn't include the types or each reserved word- you'll have to get that by calling GetReservedWord from the tokenizer on source code that contains the '{$STAMP BS2} and '{$PBASIC 2.5} directives.

Symbol     Type
--------   ---------------
$STAMP     etDirective       
$PORT      etDirective       
$PBASIC    etDirective       
BS1        etTargetModule    
BS2        etTargetModule    
BS2E       etTargetModule    
BS2SX      etTargetModule    
BS2P       etTargetModule    
BS2PE      etTargetModule    
BS2PX      etTargetModule    
IN0        etVariable
IN1        etVariable
IN2        etVariable
IN3        etVariable
IN4        etVariable
IN5        etVariable
IN6        etVariable
IN7        etVariable
IN8        etVariable
IN9        etVariable
IN10       etVariable
IN11       etVariable
IN12       etVariable
IN13       etVariable
IN14       etVariable
IN15       etVariable
OUT0       etVariable
OUT1       etVariable
OUT2       etVariable
OUT3       etVariable
OUT4       etVariable
OUT5       etVariable
OUT6       etVariable
OUT7       etVariable
OUT8       etVariable
OUT9       etVariable
OUT10      etVariable
OUT11      etVariable
OUT12      etVariable
OUT13      etVariable
OUT14      etVariable
OUT15      etVariable
DIR0       etVariable
DIR1       etVariable
DIR2       etVariable
DIR3       etVariable
DIR4       etVariable
DIR5       etVariable
DIR6       etVariable
DIR7       etVariable
DIR8       etVariable
DIR9       etVariable
DIR10      etVariable
DIR11      etVariable
DIR12      etVariable
DIR13      etVariable
DIR14      etVariable
DIR15      etVariable
INA        etVariable
INB        etVariable
INC        etVariable
IND        etVariable
OUTA       etVariable
OUTB       etVariable
OUTC       etVariable
OUTD       etVariable
DIRA       etVariable
DIRB       etVariable
DIRC       etVariable
DIRD       etVariable
INL        etVariable
INH        etVariable
OUTL       etVariable
OUTH       etVariable
DIRL       etVariable
DIRH       etVariable
B0         etVariable
B1         etVariable
B2         etVariable
B3         etVariable
B4         etVariable
B5         etVariable
B6         etVariable
B7         etVariable
B8         etVariable
B9         etVariable
B10        etVariable
B11        etVariable
B12        etVariable
B13        etVariable
B14        etVariable
B15        etVariable
B16        etVariable
B17        etVariable
B18        etVariable
B19        etVariable
B20        etVariable
B21        etVariable
B22        etVariable
B23        etVariable
B24        etVariable
B25        etVariable
INS        etVariable
OUTS       etVariable
DIRS       etVariable
W0         etVariable
W1         etVariable
W2         etVariable
W3         etVariable
W4         etVariable
W5         etVariable
W6         etVariable
W7         etVariable
W8         etVariable
W9         etVariable
W10        etVariable
W11        etVariable
W12        etVariable
CON        etDeclaration
DATA       etInstruction
VAR        etDeclaration
FOR        etInstruction     
NEXT       etInstruction     
GOTO       etInstruction     
GOSUB      etInstruction     
RETURN     etInstruction     
IF         etInstruction     
BRANCH     etInstruction     
LOOKUP     etInstruction     
LOOKDOWN   etInstruction     
RANDOM     etInstruction     
READ       etInstruction     
WRITE      etInstruction     
PAUSE      etInstruction     
INPUT      etInstruction     
OUTPUT     etInstruction     
LOW        etInstruction     
HIGH       etInstruction     
TOGGLE     etInstruction     
REVERSE    etInstruction     
SEROUT     etInstruction     
SERIN      etInstruction     
PULSOUT    etInstruction     
PULSIN     etInstruction     
COUNT      etInstruction     
SHIFTOUT   etInstruction     
SHIFTIN    etInstruction     
RCTIME     etInstruction     
BUTTON     etInstruction     
PWM        etInstruction     
FREQOUT    etInstruction     
DTMFOUT    etInstruction     
XOUT       etInstruction     
DEBUG      etInstruction     
STOP       etInstruction     
NAP        etInstruction     
SLEEP      etInstruction     
END        etInstruction     
TO         etInstruction
STEP       etInstruction
THEN       etInstruction
SQR        etUnaryOp
ABS        etUnaryOp
~          etUnaryOp
DCD        etUnaryOp
NCD        etUnaryOp
COS        etUnaryOp
SIN        etUnaryOp
HYP        etBinaryOp
ATN        etBinaryOp
&          etBinaryOp
|          etBinaryOp
^          etBinaryOp
MIN        etBinaryOp
MAX        etBinaryOp
+          etBinaryOp
-          etBinaryOp
*/         etBinaryOp
*          etBinaryOp
**         etBinaryOp
//         etBinaryOp
/          etBinaryOp
DIG        etBinaryOp
<<         etBinaryOp
>>         etBinaryOp
REV        etBinaryOp
=>         etConditionalOp
>=         etConditionalOp
<=         etConditionalOp
=<         etConditionalOp
=          etConditionalOp
<>         etConditionalOp
<>         etConditionalOp
>          etConditionalOp
<          etConditionalOp
AND        etConditionalOp
OR         etConditionalOp
XOR        etConditionalOp
NOT        etConditionalOp
BIT        etVariableType
NIB        etVariableType
BYTE       etVariableType
WORD       etVariableType
BIT0       etVariableMod
BIT1       etVariableMod
BIT2       etVariableMod
BIT3       etVariableMod
BIT4       etVariableMod
BIT5       etVariableMod
BIT6       etVariableMod
BIT7       etVariableMod
BIT8       etVariableMod
BIT9       etVariableMod
BIT10      etVariableMod
BIT11      etVariableMod
BIT12      etVariableMod
BIT13      etVariableMod
BIT14      etVariableMod
BIT15      etVariableMod
LOWBIT     etVariableMod
HIGHBIT    etVariableMod
NIB0       etVariableMod
NIB1       etVariableMod
NIB2       etVariableMod
NIB3       etVariableMod
LOWNIB     etVariableMod
HIGHNIB    etVariableMod
BYTE0      etVariableMod
BYTE1      etVariableMod
LOWBYTE    etVariableMod
HIGHBYTE   etVariableMod
ASC        etIOFormatter
STR        etIOFormatter
REP        etIOFormatter
SKIP       etIOFormatter
WAITSTR    etIOFormatter
WAIT       etIOFormatter
NUM        etIOFormatter
SNUM       etIOFormatter
DEC        etIOFormatter
DEC1       etIOFormatter
DEC2       etIOFormatter
DEC3       etIOFormatter
DEC4       etIOFormatter
DEC5       etIOFormatter
SDEC       etIOFormatter
SDEC1      etIOFormatter
SDEC2      etIOFormatter
SDEC3      etIOFormatter
SDEC4      etIOFormatter
SDEC5      etIOFormatter
HEX        etIOFormatter
HEX1       etIOFormatter
HEX2       etIOFormatter
HEX3       etIOFormatter
HEX4       etIOFormatter
SHEX       etIOFormatter
SHEX1      etIOFormatter
SHEX2      etIOFormatter
SHEX3      etIOFormatter
SHEX4      etIOFormatter
IHEX       etIOFormatter
IHEX1      etIOFormatter
IHEX2      etIOFormatter
IHEX3      etIOFormatter
IHEX4      etIOFormatter
ISHEX      etIOFormatter
ISHEX1     etIOFormatter
ISHEX2     etIOFormatter
ISHEX3     etIOFormatter
ISHEX4     etIOFormatter
BIN        etIOFormatter
BIN1       etIOFormatter
BIN2       etIOFormatter
BIN3       etIOFormatter
BIN4       etIOFormatter
BIN5       etIOFormatter
BIN6       etIOFormatter
BIN7       etIOFormatter
BIN8       etIOFormatter
BIN9       etIOFormatter
BIN10      etIOFormatter
BIN11      etIOFormatter
BIN12      etIOFormatter
BIN13      etIOFormatter
BIN14      etIOFormatter
BIN15      etIOFormatter
BIN16      etIOFormatter
SBIN       etIOFormatter
SBIN1      etIOFormatter
SBIN2      etIOFormatter
SBIN3      etIOFormatter
SBIN4      etIOFormatter
SBIN5      etIOFormatter
SBIN6      etIOFormatter
SBIN7      etIOFormatter
SBIN8      etIOFormatter
SBIN9      etIOFormatter
SBIN10     etIOFormatter
SBIN11     etIOFormatter
SBIN12     etIOFormatter
SBIN13     etIOFormatter
SBIN14     etIOFormatter
SBIN15     etIOFormatter
SBIN16     etIOFormatter
IBIN       etIOFormatter
IBIN1      etIOFormatter
IBIN2      etIOFormatter
IBIN3      etIOFormatter
IBIN4      etIOFormatter
IBIN5      etIOFormatter
IBIN6      etIOFormatter
IBIN7      etIOFormatter
IBIN8      etIOFormatter
IBIN9      etIOFormatter
IBIN10     etIOFormatter
IBIN11     etIOFormatter
IBIN12     etIOFormatter
IBIN13     etIOFormatter
IBIN14     etIOFormatter
IBIN15     etIOFormatter
IBIN16     etIOFormatter
ISBIN      etIOFormatter
ISBIN1     etIOFormatter
ISBIN2     etIOFormatter
ISBIN3     etIOFormatter
ISBIN4     etIOFormatter
ISBIN5     etIOFormatter
ISBIN6     etIOFormatter
ISBIN7     etIOFormatter
ISBIN8     etIOFormatter
ISBIN9     etIOFormatter
ISBIN10    etIOFormatter
ISBIN11    etIOFormatter
ISBIN12    etIOFormatter
ISBIN13    etIOFormatter
ISBIN14    etIOFormatter
ISBIN15    etIOFormatter
ISBIN16    etIOFormatter
.          etPeriod
?          etQuestionMark
\          etBackslash
@          etAtSign
(          etParentheses
)          etParentheses
[          etBrackets
]          etBrackets
CLS        etConstant
HOME       etConstant
BELL       etConstant
BKSP       etConstant
TAB        etConstant
CR         etConstant
UNITON     etConstant
UNITOFF    etConstant
UNITSOFF   etConstant
LIGHTSON   etConstant
DIM        etConstant
BRIGHT     etConstant
LSBFIRST   etConstant
MSBFIRST   etConstant
MSBPRE     etConstant
LSBPRE     etConstant
MSBPOST    etConstant
LSBPOST    etConstant
PIN        etDeclaration
DO         etInstruction     
EXIT       etInstruction     
LOOP       etInstruction     
UNTIL      etInstruction
WHILE      etInstruction
#DEFINE    etCCDirective     
#ERROR     etCCDirective     
#IF        etCCDirective     
#THEN      etCCDirective     
ELSE       etInstruction     
ELSEIF     etInstruction     
#ELSE      etCCDirective     
ENDIF      etInstruction     
#ENDIF     etCCDirective     
SELECT     etInstruction     
#SELECT    etCCDirective     
CASE       etInstruction     
#CASE      etCCDirective     
ENDSELECT  etInstruction     
#ENDSELECT etCCDirective     
ON         etInstruction     
DEBUGIN    etInstruction
CRSRXY     etConstant
CRSRLF     etConstant
CRSRRT     etConstant
CRSRUP     etConstant
CRSRDN     etConstant
LF         etConstant
CLREOL     etConstant
CLRDN      etConstant
CRSRX      etConstant
CRSRY      etConstant
PropGit commented 9 years ago

In the DScheme array (code in the first posting), the elements describe the formatting for particular types. For example:

{PBASIC, SynDirectiveCondCompile}      '$0808080,$1000000,$01,1',

This indicates that the "PBASIC" style for "Conditional Compile Directives" is a font color of $808080, a background color of default ($1000000), a character style of bold ($01), and a case style of upper case (1).

The default is indicated by the MSB of the second value ($1000000), and means that the default color is used (instead of an overriding color set locally here). For the editor, the default font color is black and the default background color is white.

The character style can be plain ($00), bold ($01), italic ($04), or underline ($16). The PBASIC syntax style is always plain or bold for any give syntax element, but the existing editor allows the user to set their own style (a feature we can ignore until further notice).

The case style is probably the most odd (and maybe difficult/impossible to do in a reasonable time frame). It specifies whether the syntax element should have no change (0) applied to its character case, or be UPPER-CASED (1), lower cased (2), or Capitalized (3). The PBASIC syntax style is unchanged or UPPER-CASED for most syntax elements, and Capitalized for one of the elements.

PropGit commented 9 years ago

NOTE: Case-modification is likely to be non-trivial. Case-modification is deferred to a later time. See Issue 85.

PropGit commented 9 years ago

Here's a more clearly-defined set of syntax highlighting metrics for PBASIC.

Notes

Syntax Type               ElementType      Font Color      Bg Color       Font Style  Case Style
------------------------  ---------------  --------------  -------------  ----------  ----------
SynCommand                etInstruction    Blue   $0000FF  Default        Plain       Upper
SynComment                                 Green  $008000  Default        Plain       No Change
SynConstantBinary                          Default         Default        Plain       No Change
SynConstantDecimal                         Default         Default        Plain       No Change
SynConstantHexadecimal                     Default         Default        Plain       No Change
SynConstantPredefined     etConstant       Purple $800080  Default        Plain       Upper
SynConstantString                          Red    $FF0000  Default        Plain       No Change
SynDefault                                 Black  $000000  White $FFFFFF  Plain       No Change
SynOperatorBinary         etBinaryOp       Default         Default        Plain       Upper
SynOperatorConditional    etConditionalOp  Default         Default        Plain       Upper
SynOperatorUnary          etUnaryOp        Default         Default        Plain       Upper
SynDeclaration            etDeclaration    Default         Default        Plain       Upper
SynDirectiveCondCompile   etCCDirective    Gray   $808080  Default        Bold        Upper
SynDirectiveEditor        etDirective      Teal   $008080  Default        Bold        Upper
SynDirectiveTargetModule  etTargetModule   Teal   $008080  Default        Bold        Upper
SynIOFormatter            etIOFormatter    Navy   $000080  Default        Plain       Upper
SynSelectionMarkedBlock                    White  $FFFFFF  Navy  $000080  Plain       No Change
SynSelectionSearchMatch                    Lime   $00FF00  Black $000000  Plain       No Change
SynVariableModifier       etVariableMod    Default         Default        Plain       Upper
SynVariablePredefined     etVariable       Purple $800080  Default        Plain       Upper
SynVariableType           etVariableType   Default         Default        Plain       Capitalize