Skip to content

Commit a8ee37c

Browse files
committed
Grammar improvements:
-Support control characters in a string (^M, #13 and combination) -Support double pointer (^^) reference
1 parent 33d5f6f commit a8ee37c

File tree

4 files changed

+9182
-8830
lines changed

4 files changed

+9182
-8830
lines changed

src/main/antlr3/org/sonar/plugins/delphi/antlr/Delphi.g

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ package org.sonar.plugins.delphi.antlr;
6464
**/
6565
}
6666

67+
@lexer::members {
68+
private boolean isControlchar() {
69+
// TODO
70+
// - check if there are actually 2 chars ahead and not an EOF
71+
// - perhaps something else than a regex match here
72+
return ((char)input.LA(1) + "" + (char)input.LA(2)).matches("\\w\\W");
73+
}
74+
}
75+
6776
//****************************
6877
//section start
6978
//****************************
@@ -480,15 +489,16 @@ factor : '@' factor
480489
| designator
481490
| typeId '(' expression ')'
482491
;
483-
stringFactor : ControlString (QuotedString ControlString)* (QuotedString)?
484-
| QuotedString (ControlString QuotedString)* (ControlString)?
492+
stringFactor : (ControlString | ControlChar) (QuotedString (ControlString | ControlChar))* (QuotedString)?
493+
| QuotedString ((ControlString | ControlChar) QuotedString)* (ControlString | ControlChar)?
485494
;
486495
setSection : '[' (expression ((',' | '..') expression)*)? ']'
487496
;
488497
489498
designator : ('inherited')? ( (qualifiedIdent | typeId) )? (designatorItem)*
490499
;
491500
designatorItem : '^'
501+
| '^^'
492502
| ('.' | '@') ident //CHANGED added '@'
493503
| ('<' genericTypeIdent (',' genericTypeIdent)* '>') //ADDED for proc<sth, sth>.foo;
494504
| '[' expressionList ']'
@@ -940,14 +950,15 @@ TkRealNum : Digitseq ( ((DOT Digitseq)? (('e'|'E') ('+'|'-')? Digi
940950
;
941951
TkHexNum : '$' Hexdigitseq
942952
;
943-
QuotedString : '\'' ('\'\'' | ~('\''))* '\'' //taken from PASCAL grammar
953+
ControlChar : '^' ( {isControlchar()}?=> Alpha
954+
| {$type=POINTER2;}
955+
)
956+
| '#' Digitseq
957+
| '#' '$' Hexdigitseq
944958
;
945-
ControlString : Controlchar (Controlchar)*
959+
QuotedString : '\'' ('\'\'' | ~('\''))* '\'' //taken from PASCAL grammar
946960
;
947-
948-
fragment
949-
Controlchar : '#' Digitseq
950-
| '#' '$' Hexdigitseq
961+
ControlString : ControlChar (ControlChar)*
951962
;
952963
fragment
953964
Alpha : 'a'..'z'

0 commit comments

Comments
 (0)