Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
SublimeCodeIntel/libs/codeintel2/shared_parser.py at development · SourceCode/SublimeCodeIntel · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
SourceCode
/
SublimeCodeIntel
Public
forked from
SublimeCodeIntel/SublimeCodeIntel
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Files
Expand file tree
development
Breadcrumbs
SublimeCodeIntel
/
libs
/
codeintel2
/
shared_parser.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
182 lines (148 loc) · 6.65 KB
development
Breadcrumbs
SublimeCodeIntel
/
libs
/
codeintel2
/
shared_parser.py
Copy path
Top
File metadata and controls
Code
Blame
182 lines (148 loc) · 6.65 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.1 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
# License for the specific language governing rights and limitations
# under the License.
#
# The Original Code is Komodo code.
#
# The Initial Developer of the Original Code is ActiveState Software Inc.
# Portions created by ActiveState Software Inc are Copyright (C) 2000-2007
# ActiveState Software Inc. All Rights Reserved.
#
# Contributor(s):
# ActiveState Software Inc
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
#
# Contributors:
# Eric Promislow (EricP@ActiveState.com)
#
""" Many CILE parsers have to allow for tokens to arrive with
either native Scintilla types, or UDL types (and there might be
more in the future.
This module defines the abstraction layer over the UDL types.
Some routines can't fulfill a request just by looking at the type,
and need to examine the actual text of the token. But a common
UDL layer can't do that, as each SSL language has different properties.
So callbacks that return to the SSL CILE are used for that purpose.
See ruby_parser.py for examples on writing callbacks for
get_builtin_type, is_interpolating_string, and
tokenStyleToContainerStyle (if any of these are called, that is).
"""
import
re
from
SilverCity
import
ScintillaConstants
GENERIC_TYPE_UNKNOWN
=
0
GENERIC_TYPE_NUMBER
=
1
GENERIC_TYPE_STRING
=
2
GENERIC_TYPE_REGEX
=
3
class
CommonClassifier
:
_quote_patterns
=
{}
def
get_quote_patterns
(
self
,
tok
,
callback
=
None
):
ttype
=
tok
[
'style'
]
if
ttype
in
self
.
_quote_patterns
:
return
[
self
.
_quote_patterns
[
ttype
]]
elif
callback
:
return
callback
(
tok
)
else
:
return
list
(
self
.
_quote_patterns
.
values
())
def
is_identifier_or_keyword
(
self
,
tok
):
return
self
.
is_identifier
(
tok
,
True
)
class
UDLClassifier
(
CommonClassifier
):
def
get_builtin_type
(
self
,
tok
,
callback
):
if
self
.
is_number
(
tok
):
return
callback
(
tok
,
GENERIC_TYPE_NUMBER
)
elif
self
.
is_string
(
tok
):
return
callback
(
tok
,
GENERIC_TYPE_STRING
)
elif
tok
[
'style'
]
==
ScintillaConstants
.
SCE_UDL_SSL_REGEX
:
return
callback
(
tok
,
GENERIC_TYPE_REGEX
)
else
:
return
callback
(
tok
,
GENERIC_TYPE_UNKNOWN
)
def
is_any_operator
(
self
,
tok
):
return
tok
[
'style'
]
==
ScintillaConstants
.
SCE_UDL_SSL_OPERATOR
def
is_comment
(
self
,
tok
):
return
tok
[
'style'
]
in
(
ScintillaConstants
.
SCE_UDL_SSL_COMMENT
,
ScintillaConstants
.
SCE_UDL_SSL_COMMENTBLOCK
)
def
is_comment_structured
(
self
,
tok
,
callback
):
return
self
.
is_comment
(
tok
)
and
callback
and
callback
(
tok
)
def
is_identifier
(
self
,
tok
,
allow_keywords
=
False
):
return
(
tok
[
'style'
]
==
ScintillaConstants
.
SCE_UDL_SSL_IDENTIFIER
or
(
allow_keywords
and
tok
[
'style'
]
==
ScintillaConstants
.
SCE_UDL_SSL_WORD
))
def
is_index_op
(
self
,
tok
,
pattern
=
None
):
if
tok
[
'style'
]
!=
ScintillaConstants
.
SCE_UDL_SSL_OPERATOR
:
return
False
elif
not
pattern
:
return
True
return
len
(
tok
[
'text'
])
>
0
and
pattern
.
search
(
tok
[
'text'
])
# Everything gets lexed as a string, so we need to look at its structure.
# We call back to the main CILE parser, which knows more about which kinds
# of strings can interpolate other values. This routine assumes all regexes
# can interpolate.
def
is_interpolating_string
(
self
,
tok
,
callback
):
if
tok
[
'style'
]
==
ScintillaConstants
.
SCE_UDL_SSL_REGEX
:
return
callback
(
tok
,
GENERIC_TYPE_REGEX
)
elif
not
self
.
is_string
(
tok
):
return
False
else
:
return
callback
(
tok
,
GENERIC_TYPE_STRING
)
def
is_keyword
(
self
,
tok
,
target
):
return
tok
[
'style'
]
==
ScintillaConstants
.
SCE_UDL_SSL_WORD
and
tok
[
'text'
]
==
target
def
is_number
(
self
,
tok
):
return
tok
[
'style'
]
==
ScintillaConstants
.
SCE_UDL_SSL_NUMBER
def
is_operator
(
self
,
tok
,
target
):
return
tok
[
'style'
]
==
ScintillaConstants
.
SCE_UDL_SSL_OPERATOR
and
tok
[
'text'
]
==
target
def
is_string
(
self
,
tok
):
return
tok
[
'style'
]
==
ScintillaConstants
.
SCE_UDL_SSL_STRING
def
is_string_qw
(
self
,
tok
,
callback
=
None
):
return
(
tok
[
'style'
]
==
ScintillaConstants
.
SCE_UDL_SSL_STRING
and
callback
and
callback
(
tok
))
def
is_symbol
(
self
,
tok
,
callback
=
None
):
return
(
tok
[
'style'
]
==
ScintillaConstants
.
SCE_UDL_SSL_STRING
and
callback
and
callback
(
tok
))
def
is_variable
(
self
,
tok
):
return
tok
[
'style'
]
in
(
ScintillaConstants
.
SCE_UDL_SSL_VARIABLE
,
ScintillaConstants
.
SCE_UDL_SSL_IDENTIFIER
)
# Types of variables
def
is_variable_array
(
self
,
tok
,
callback
=
None
):
if
not
self
.
is_variable
(
tok
):
return
False
else
:
return
callback
and
callback
(
tok
)
def
is_variable_scalar
(
self
,
tok
,
callback
=
None
):
if
not
self
.
is_variable
(
tok
):
return
False
else
:
return
callback
and
callback
(
tok
)
def
tokenStyleToContainerStyle
(
self
,
tok
,
callback
):
return
callback
(
tok
,
tok
[
'style'
]
==
ScintillaConstants
.
SCE_UDL_SSL_VARIABLE
)
# Accessors for where we'd rather work with a style than call a predicate
# fn
@
property
def
style_identifier
(
self
):
return
ScintillaConstants
.
SCE_UDL_SSL_IDENTIFIER
@
property
def
style_operator
(
self
):
return
ScintillaConstants
.
SCE_UDL_SSL_OPERATOR
@
property
def
style_word
(
self
):
return
ScintillaConstants
.
SCE_UDL_SSL_WORD
You can’t perform that action at this time.