]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/LexAsn1.cxx
36f1d5dc2e67018e0d72e612b8d95fd9c87983ed
1 // Scintilla source code edit control
5 // Copyright 2004 by Herr Pfarrer rpfarrer <at> yahoo <dot> de
6 // Last Updated: 20/07/2004
7 // The License.txt file describes the conditions under which this software may be distributed.
18 #include "StyleContext.h"
20 #include "Scintilla.h"
24 using namespace Scintilla
;
27 // Some char test functions
28 static bool isAsn1Number(int ch
)
30 return (ch
>= '0' && ch
<= '9');
33 static bool isAsn1Letter(int ch
)
35 return (ch
>= 'A' && ch
<= 'Z') || (ch
>= 'a' && ch
<= 'z');
38 static bool isAsn1Char(int ch
)
40 return (ch
== '-' ) || isAsn1Number(ch
) || isAsn1Letter (ch
);
44 // Function determining the color of a given code portion
47 static void ColouriseAsn1Doc(unsigned int startPos
, int length
, int initStyle
, WordList
*keywordLists
[], Accessor
&styler
)
50 WordList
&Keywords
= *keywordLists
[0];
51 WordList
&Attributes
= *keywordLists
[1];
52 WordList
&Descriptors
= *keywordLists
[2];
53 WordList
&Types
= *keywordLists
[3];
55 // Parse the whole buffer character by character using StyleContext
56 StyleContext
sc(startPos
, length
, initStyle
, styler
);
57 for (; sc
.More(); sc
.Forward())
62 case SCE_ASN1_DEFAULT
: // Plain characters
64 if (sc
.ch
== '-' && sc
.chNext
== '-')
65 // A comment begins here
66 sc
.SetState(SCE_ASN1_COMMENT
);
67 else if (sc
.ch
== '"')
68 // A string begins here
69 sc
.SetState(SCE_ASN1_STRING
);
70 else if (isAsn1Number (sc
.ch
))
71 // A number starts here (identifier should start with a letter in ASN.1)
72 sc
.SetState(SCE_ASN1_SCALAR
);
73 else if (isAsn1Char (sc
.ch
))
74 // An identifier starts here (identifier always start with a letter)
75 sc
.SetState(SCE_ASN1_IDENTIFIER
);
76 else if (sc
.ch
== ':')
77 // A ::= operator starts here
78 sc
.SetState(SCE_ASN1_OPERATOR
);
80 case SCE_ASN1_COMMENT
: // A comment
81 if (sc
.ch
== '\r' || sc
.ch
== '\n')
82 // A comment ends here
83 sc
.SetState(SCE_ASN1_DEFAULT
);
85 case SCE_ASN1_IDENTIFIER
: // An identifier (keyword, attribute, descriptor or type)
86 if (!isAsn1Char (sc
.ch
))
88 // The end of identifier is here: we can look for it in lists by now and change its state
90 sc
.GetCurrent(s
, sizeof(s
));
91 if (Keywords
.InList(s
))
92 // It's a keyword, change its state
93 sc
.ChangeState(SCE_ASN1_KEYWORD
);
94 else if (Attributes
.InList(s
))
95 // It's an attribute, change its state
96 sc
.ChangeState(SCE_ASN1_ATTRIBUTE
);
97 else if (Descriptors
.InList(s
))
98 // It's a descriptor, change its state
99 sc
.ChangeState(SCE_ASN1_DESCRIPTOR
);
100 else if (Types
.InList(s
))
101 // It's a type, change its state
102 sc
.ChangeState(SCE_ASN1_TYPE
);
104 // Set to default now
105 sc
.SetState(SCE_ASN1_DEFAULT
);
108 case SCE_ASN1_STRING
: // A string delimited by ""
111 // A string ends here
112 sc
.ForwardSetState(SCE_ASN1_DEFAULT
);
114 // To correctly manage a char sticking to the string quote
118 case SCE_ASN1_SCALAR
: // A plain number
119 if (!isAsn1Number (sc
.ch
))
120 // A number ends here
121 sc
.SetState(SCE_ASN1_DEFAULT
);
123 case SCE_ASN1_OPERATOR
: // The affectation operator ::= and wath follows (eg: ::= { org 6 } OID or ::= 12 trap)
126 // An OID definition starts here: enter the sub loop
127 for (; sc
.More(); sc
.Forward())
129 if (isAsn1Number (sc
.ch
) && (!isAsn1Char (sc
.chPrev
) || isAsn1Number (sc
.chPrev
)))
130 // The OID number is highlighted
131 sc
.SetState(SCE_ASN1_OID
);
132 else if (isAsn1Char (sc
.ch
))
133 // The OID parent identifier is plain
134 sc
.SetState(SCE_ASN1_IDENTIFIER
);
136 sc
.SetState(SCE_ASN1_DEFAULT
);
139 // Here ends the OID and the operator sub loop: go back to main loop
143 else if (isAsn1Number (sc
.ch
))
145 // A trap number definition starts here: enter the sub loop
146 for (; sc
.More(); sc
.Forward())
148 if (isAsn1Number (sc
.ch
))
149 // The trap number is highlighted
150 sc
.SetState(SCE_ASN1_OID
);
153 // The number ends here: go back to main loop
154 sc
.SetState(SCE_ASN1_DEFAULT
);
159 else if (sc
.ch
!= ':' && sc
.ch
!= '=' && sc
.ch
!= ' ')
160 // The operator doesn't imply an OID definition nor a trap, back to main loop
161 goto asn1_default
; // To be sure to handle actually the state change
168 static void FoldAsn1Doc(unsigned int, int, int, WordList
*[], Accessor
&styler
)
170 // No folding enabled, no reason to continue...
171 if( styler
.GetPropertyInt("fold") == 0 )
174 // No folding implemented: doesn't make sense for ASN.1
177 static const char * const asn1WordLists
[] = {
185 LexerModule
lmAns1(SCLEX_ASN1
, ColouriseAsn1Doc
, "asn1", FoldAsn1Doc
, asn1WordLists
);