Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
98b3072d
Commit
98b3072d
authored
8 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
py/lexer: Simplify handling of indenting of very first token.
parent
b0599de4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
py/lexer.c
+10
-15
10 additions, 15 deletions
py/lexer.c
with
10 additions
and
15 deletions
py/lexer.c
+
10
−
15
View file @
98b3072d
...
...
@@ -283,7 +283,7 @@ STATIC bool get_hex(mp_lexer_t *lex, mp_uint_t num_digits, mp_uint_t *result) {
return
true
;
}
STATIC
void
mp_lexer_next
_token_into
(
mp_lexer_t
*
lex
,
bool
first_token
)
{
void
mp_lexer_
to_
next
(
mp_lexer_t
*
lex
)
{
// start new token text
vstr_reset
(
&
lex
->
vstr
);
...
...
@@ -322,14 +322,7 @@ STATIC void mp_lexer_next_token_into(mp_lexer_t *lex, bool first_token) {
lex
->
tok_line
=
lex
->
line
;
lex
->
tok_column
=
lex
->
column
;
if
(
first_token
&&
lex
->
line
==
1
&&
lex
->
column
!=
1
)
{
// check that the first token is in the first column
// if first token is not on first line, we get a physical newline and
// this check is done as part of normal indent/dedent checking below
// (done to get equivalence with CPython)
lex
->
tok_kind
=
MP_TOKEN_INDENT
;
}
else
if
(
lex
->
emit_dent
<
0
)
{
if
(
lex
->
emit_dent
<
0
)
{
lex
->
tok_kind
=
MP_TOKEN_DEDENT
;
lex
->
emit_dent
+=
1
;
...
...
@@ -705,7 +698,7 @@ mp_lexer_t *mp_lexer_new(qstr src_name, mp_reader_t reader) {
vstr_init
(
&
lex
->
vstr
,
32
);
// check for memory allocation error
// note: vstr_init above may fail on malloc, but so may mp_lexer_next
_token_into
below
// note: vstr_init above may fail on malloc, but so may mp_lexer_
to_
next below
if
(
lex
->
indent_level
==
NULL
)
{
mp_lexer_free
(
lex
);
return
NULL
;
...
...
@@ -737,7 +730,13 @@ mp_lexer_t *mp_lexer_new(qstr src_name, mp_reader_t reader) {
}
// preload first token
mp_lexer_next_token_into
(
lex
,
true
);
mp_lexer_to_next
(
lex
);
// Check that the first token is in the first column. If it's not then we
// convert the token kind to INDENT so that the parser gives a syntax error.
if
(
lex
->
tok_column
!=
1
)
{
lex
->
tok_kind
=
MP_TOKEN_INDENT
;
}
return
lex
;
}
...
...
@@ -785,10 +784,6 @@ void mp_lexer_free(mp_lexer_t *lex) {
}
}
void
mp_lexer_to_next
(
mp_lexer_t
*
lex
)
{
mp_lexer_next_token_into
(
lex
,
false
);
}
#if 0
// This function is used to print the current token and should only be
// needed to debug the lexer, so it's not available via a config option.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment