Skip to content

Commit

Permalink
added: rule to objectpascal lexer (#888)
Browse files Browse the repository at this point in the history
* added: another rule for objectpascal lexer

* updated: objectpascal lexer testdata

* fixed: processing of control (escape) characters

* updated: test data for objectpascal lexer
  • Loading branch information
codiacdev committed Nov 23, 2023
1 parent c5948a6 commit d9f6ed6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
8 changes: 6 additions & 2 deletions lexers/embedded/objectpascal.xml
Expand Up @@ -28,7 +28,7 @@
<token type="Text"/>
</rule>
<!-- Compiler Directive -->
<rule pattern="\{[$].*?\}|\{[-](NOD|EXT|OBJ).*?\}">
<rule pattern="\{[$].*?\}|\{[-](NOD|EXT|OBJ).*?\}|\([*][$].*?[*]\)">
<token type="CommentPreproc" />
</rule>
<!-- Comment Single -->
Expand All @@ -50,8 +50,12 @@
<rule pattern="(?i:(\.\.))">
<token type="Operator" />
</rule>
<!-- Control Character -->
<rule pattern="[\#][0-9a-fA-F]*|[0-9]+[xX][0-9a-fA-F]*">
<token type="LiteralStringEscape" />
</rule>
<!-- Numbers -->
<rule pattern="[\$][0-9a-fA-F]*[xX][0-9a-fA-F]*|[\$][0-9a-fA-F]*|[\#][0-9a-fA-F]*|[0-9]+[xX][0-9a-fA-F]*|([0-9]+[0-9a-fA-F]+(?=[hH]))">
<rule pattern="[\$][0-9a-fA-F]*[xX][0-9a-fA-F]*|[\$][0-9a-fA-F]*|([0-9]+[0-9a-fA-F]+(?=[hH]))">
<token type="LiteralNumberHex" />
</rule>
<rule pattern="[0-9]+(\&#39;[0-9]+)*\.[0-9]+(\&#39;[0-9]+)*[eE][+-]?[0-9]+(\&#39;[0-9]+)*|[0-9]+(\&#39;[0-9]+)*\.[0-9]+(\&#39;[0-9]+)*|\d+[eE][+-]?[0-9]+">
Expand Down
2 changes: 2 additions & 0 deletions lexers/testdata/objectpascal.actual
Expand Up @@ -83,6 +83,8 @@ var
{-NODEFINE string 'String' } {$OBJTYPENAME string 'NUnicodeString'} { defined in ustring.h }
{-EXTERNALSYM ShortInt 'signed char' } {-OBJTYPENAME ShortInt 'Bzc'}

(*$hints off*) // another valid compiler directive

const
CLineBreak = {$IFDEF POSIX} _AnsiStr(#10) {$ENDIF}
{$IFDEF MSWINDOWS} _AnsiStr(#13#10) {$ENDIF};
Expand Down
13 changes: 9 additions & 4 deletions lexers/testdata/objectpascal.expected
Expand Up @@ -409,6 +409,11 @@
{"type":"TextWhitespace","value":" "},
{"type":"CommentPreproc","value":"{-OBJTYPENAME ShortInt 'Bzc'}"},
{"type":"Text","value":"\n\n"},
{"type":"CommentPreproc","value":"(*$hints off*)"},
{"type":"TextWhitespace","value":" "},
{"type":"CommentSingle","value":"// another valid compiler directive"},
{"type":"TextWhitespace","value":"\n"},
{"type":"Text","value":"\n"},
{"type":"KeywordReserved","value":"const"},
{"type":"Text","value":"\n"},
{"type":"TextWhitespace","value":" "},
Expand All @@ -420,7 +425,7 @@
{"type":"TextWhitespace","value":" "},
{"type":"Text","value":"_AnsiStr"},
{"type":"Operator","value":"("},
{"type":"LiteralNumberHex","value":"#10"},
{"type":"LiteralStringEscape","value":"#10"},
{"type":"Operator","value":")"},
{"type":"TextWhitespace","value":" "},
{"type":"CommentPreproc","value":"{$ENDIF}"},
Expand All @@ -430,7 +435,7 @@
{"type":"TextWhitespace","value":" "},
{"type":"Text","value":"_AnsiStr"},
{"type":"Operator","value":"("},
{"type":"LiteralNumberHex","value":"#13#10"},
{"type":"LiteralStringEscape","value":"#13#10"},
{"type":"Operator","value":")"},
{"type":"TextWhitespace","value":" "},
{"type":"CommentPreproc","value":"{$ENDIF}"},
Expand Down Expand Up @@ -1725,7 +1730,7 @@
{"type":"TextWhitespace","value":" "},
{"type":"Text","value":"Ord"},
{"type":"Operator","value":"("},
{"type":"LiteralNumberHex","value":"#10"},
{"type":"LiteralStringEscape","value":"#10"},
{"type":"Operator","value":")"},
{"type":"Punctuation","value":"."},
{"type":"Text","value":"ToExtended"},
Expand Down Expand Up @@ -1947,7 +1952,7 @@
{"type":"Operator","value":"%"},
{"type":"Text","value":"fs"},
{"type":"Operator","value":":("},
{"type":"LiteralNumberHex","value":"0x2c"},
{"type":"LiteralStringEscape","value":"0x2c"},
{"type":"Operator","value":")"},
{"type":"Punctuation","value":","},
{"type":"Operator","value":"%"},
Expand Down

0 comments on commit d9f6ed6

Please sign in to comment.