]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/scintilla/src/LexAsn1.cxx
be6c3f2aeacc89b9c5a75c4e8b34bb775ae5a52f
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"
23 // Some char test functions
24 static bool isAsn1Number(int ch
)
26 return (ch
>= '0' && ch
<= '9');
29 static bool isAsn1Letter(int ch
)
31 return (ch
>= 'A' && ch
<= 'Z') || (ch
>= 'a' && ch
<= 'z');
34 static bool isAsn1Char(int ch
)
36 return (ch
== '-' ) || isAsn1Number(ch
) || isAsn1Letter (ch
);
40 // Function determining the color of a given code portion
43 static void ColouriseAsn1Doc(unsigned int startPos
, int length
, int initStyle
, WordList
*keywordLists
[], Accessor
&styler
)
46 WordList
&Keywords
= *keywordLists
[0];
47 WordList
&Attributes
= *keywordLists
[1];
48 WordList
&Descriptors
= *keywordLists
[2];
49 WordList
&Types
= *keywordLists
[3];
51 // Parse the whole buffer character by character using StyleContext
52 StyleContext
sc(startPos
, length
, initStyle
, styler
);
53 for (; sc
.More(); sc
.Forward())
58 case SCE_ASN1_DEFAULT
: // Plain characters
60 if (sc
.ch
== '-' && sc
.chNext
== '-')
61 // A comment begins here
62 sc
.SetState(SCE_ASN1_COMMENT
);
63 else if (sc
.ch
== '"')
64 // A string begins here
65 sc
.SetState(SCE_ASN1_STRING
);
66 else if (isAsn1Number (sc
.ch
))
67 // A number starts here (identifier should start with a letter in ASN.1)
68 sc
.SetState(SCE_ASN1_SCALAR
);
69 else if (isAsn1Char (sc
.ch
))
70 // An identifier starts here (identifier always start with a letter)
71 sc
.SetState(SCE_ASN1_IDENTIFIER
);
72 else if (sc
.ch
== ':')
73 // A ::= operator starts here
74 sc
.SetState(SCE_ASN1_OPERATOR
);
76 case SCE_ASN1_COMMENT
: // A comment
77 if (sc
.ch
== '\r' || sc
.ch
== '\n')
78 // A comment ends here
79 sc
.SetState(SCE_ASN1_DEFAULT
);
81 case SCE_ASN1_IDENTIFIER
: // An identifier (keyword, attribute, descriptor or type)
82 if (!isAsn1Char (sc
.ch
))
84 // The end of identifier is here: we can look for it in lists by now and change its state
86 sc
.GetCurrent(s
, sizeof(s
));
87 if (Keywords
.InList(s
))
88 // It's a keyword, change its state
89 sc
.ChangeState(SCE_ASN1_KEYWORD
);
90 else if (Attributes
.InList(s
))
91 // It's an attribute, change its state
92 sc
.ChangeState(SCE_ASN1_ATTRIBUTE
);
93 else if (Descriptors
.InList(s
))
94 // It's a descriptor, change its state
95 sc
.ChangeState(SCE_ASN1_DESCRIPTOR
);
96 else if (Types
.InList(s
))
97 // It's a type, change its state
98 sc
.ChangeState(SCE_ASN1_TYPE
);
100 // Set to default now
101 sc
.SetState(SCE_ASN1_DEFAULT
);
104 case SCE_ASN1_STRING
: // A string delimited by ""
107 // A string ends here
108 sc
.ForwardSetState(SCE_ASN1_DEFAULT
);
110 // To correctly manage a char sticking to the string quote
114 case SCE_ASN1_SCALAR
: // A plain number
115 if (!isAsn1Number (sc
.ch
))
116 // A number ends here
117 sc
.SetState(SCE_ASN1_DEFAULT
);
119 case SCE_ASN1_OPERATOR
: // The affectation operator ::= and wath follows (eg: ::= { org 6 } OID or ::= 12 trap)
122 // An OID definition starts here: enter the sub loop
123 for (; sc
.More(); sc
.Forward())
125 if (isAsn1Number (sc
.ch
) && (!isAsn1Char (sc
.chPrev
) || isAsn1Number (sc
.chPrev
)))
126 // The OID number is highlighted
127 sc
.SetState(SCE_ASN1_OID
);
128 else if (isAsn1Char (sc
.ch
))
129 // The OID parent identifier is plain
130 sc
.SetState(SCE_ASN1_IDENTIFIER
);
132 sc
.SetState(SCE_ASN1_DEFAULT
);
135 // Here ends the OID and the operator sub loop: go back to main loop
139 else if (isAsn1Number (sc
.ch
))
141 // A trap number definition starts here: enter the sub loop
142 for (; sc
.More(); sc
.Forward())
144 if (isAsn1Number (sc
.ch
))
145 // The trap number is highlighted
146 sc
.SetState(SCE_ASN1_OID
);
149 // The number ends here: go back to main loop
150 sc
.SetState(SCE_ASN1_DEFAULT
);
155 else if (sc
.ch
!= ':' && sc
.ch
!= '=' && sc
.ch
!= ' ')
156 // The operator doesn't imply an OID definition nor a trap, back to main loop
157 goto asn1_default
; // To be sure to handle actually the state change
164 static void FoldAsn1Doc(unsigned int, int, int, WordList
*[], Accessor
&styler
)
166 // No folding enabled, no reason to continue...
167 if( styler
.GetPropertyInt("fold") == 0 )
170 // No folding implemented: doesn't make sense for ASN.1
173 static const char * const asn1WordLists
[] = {
181 LexerModule
lmAsn1(SCLEX_ASN1
, ColouriseAsn1Doc
, "asn1", FoldAsn1Doc
, asn1WordLists
);