Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modifying preparse.py to benefit from the Python standard tokenize module #689

Open
williamstein opened this issue Sep 18, 2007 · 0 comments

Comments

@williamstein
Copy link
Contributor

On 9/18/07, Joel B. Mohler <joel@kiwistrawberry.us> wrote:

    I don't have a strong opinion about the original proposition ... although I
    have spent the last week being thoroughly vexed by python being zero-based
    when all the things I would write on paper about math would index things
    one-based.


One solution to that is to just write things 0-based in your math papers. 
I've been doing that in all the mathematics I write for the last 2 years
or so, and nobody complains.   Consider an $n$-dimensional vector
space with basis $v_0, \ldots, v_{n-1}$. 

    However, I did want to say this about the preparser.  My impression is that it
    is written by doing very manual character/string reading.  I think
    the 'tokenize' module could probably make the code much much cleaner.  It has
    annoying (but understandable) semantics.  Here's an example below.


True.  I've been looking forward to somebody rewriting the preparse(...)
function for a long time.  Much to my surprise nobody has.  I don't think
anybody has even tried, though people have suggested they would try
on a few occasions. I would certainly be happy if it were to happen, though
I'm not going to do it myself, since the current version works perfectly
well, is easy to understand, and I have other things that I have to do.
Also, speeding up the preparser might have little noticeable effect on the
speed of Sage, since all actual work / computation happens after preparsing.
That said, if you do
    sage: search_src('sage_eval')
you'll see 83 places in the Sage library code itself that involve calling
the Sage preparser, and those could be faster. 

Using tokenize as you illustrate below would probably be a simple
intermediate way to rewrite the preparser without going nuts trying
to do something too complicated.  E.g., the preparser currently
has code to find string literals in the input line -- the tokenize module
does the same thing, probably much better.   Also the preparser
has code to parse out valid identifiers, and again the tokenize module
below does that automatically.

I think "modifying preparse.py to benefit from the Python standard tokenize module" would be a good trac enhancement ticket:
  

    --
    Joel

    import tokenize

    # helper class to generate a stream from a string
    class line_token_stream:
        def __init__( self, s ):
            self.line = s

        def __call__( self ):
            if self.line:
                s = self.line
                self.line = None
                return s
            raise StopIteration

    def tokenize_line( s ):
        for t in  tokenize.generate_tokens( line_token_stream( s ) ):
            yield t

    for i in tokenize_line( "func(1+2)" ):
        print i

Component: basic arithmetic

Issue created by migration from https://trac.sagemath.org/ticket/689

vbraun pushed a commit that referenced this issue Mar 26, 2023
    
Bumps [codecov/codecov-action](https://github.com/codecov/codecov-
action) from 2 to 3.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/codecov/codecov-
action/releases">codecov/codecov-action's releases</a>.</em></p>
<blockquote>
<h2>v3.0.0</h2>
<h3>Breaking Changes</h3>
<ul>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/689">#689</a> Bump to node16 and small fixes</li>
</ul>
<h3>Features</h3>
<ul>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/688">#688</a> Incorporate <code>gcov</code> arguments for
the Codecov uploader</li>
</ul>
<h3>Dependencies</h3>
<ul>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/548">#548</a> build(deps-dev): bump jest-junit from 12.2.0
to 13.0.0</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/603">#603</a> [Snyk] Upgrade <code>@​actions/core</code>
from 1.5.0 to 1.6.0</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/628">#628</a> build(deps): bump node-fetch from 2.6.1 to
3.1.1</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/634">#634</a> build(deps): bump node-fetch from 3.1.1 to
3.2.0</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/636">#636</a> build(deps): bump openpgp from 5.0.1 to
5.1.0</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/652">#652</a> build(deps-dev): bump
<code>@​vercel/ncc</code> from 0.30.0 to 0.33.3</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/653">#653</a> build(deps-dev): bump
<code>@​types/node</code> from 16.11.21 to 17.0.18</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/659">#659</a> build(deps-dev): bump
<code>@​types/jest</code> from 27.4.0 to 27.4.1</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/667">#667</a> build(deps): bump actions/checkout from 2 to
3</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/673">#673</a> build(deps): bump node-fetch from 3.2.0 to
3.2.3</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/683">#683</a> build(deps): bump minimist from 1.2.5 to
1.2.6</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/685">#685</a> build(deps): bump
<code>@​actions/github</code> from 5.0.0 to 5.0.1</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/681">#681</a> build(deps-dev): bump
<code>@​types/node</code> from 17.0.18 to 17.0.23</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/682">#682</a> build(deps-dev): bump typescript from 4.5.5
to 4.6.3</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/676">#676</a> build(deps): bump
<code>@​actions/exec</code> from 1.1.0 to 1.1.1</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/675">#675</a> build(deps): bump openpgp from 5.1.0 to
5.2.1</li>
</ul>
<h2>v2.1.0</h2>
<h2>2.1.0</h2>
<h3>Features</h3>
<ul>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/515">#515</a> Allow specifying version of Codecov
uploader</li>
</ul>
<h3>Dependencies</h3>
<ul>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/499">#499</a> build(deps-dev): bump
<code>@​vercel/ncc</code> from 0.29.0 to 0.30.0</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/508">#508</a> build(deps): bump openpgp from 5.0.0-5 to
5.0.0</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/514">#514</a> build(deps-dev): bump
<code>@​types/node</code> from 16.6.0 to 16.9.0</li>
</ul>
<h2>v2.0.3</h2>
<h2>2.0.3</h2>
<h3>Fixes</h3>
<ul>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/464">#464</a> Fix wrong link in the readme</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/485">#485</a> fix: Add override OS and linux default to
platform</li>
</ul>
<h3>Dependencies</h3>
<ul>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/447">#447</a> build(deps): bump openpgp from 5.0.0-4 to
5.0.0-5</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/458">#458</a> build(deps-dev): bump eslint from 7.31.0 to
7.32.0</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/465">#465</a> build(deps-dev): bump <code>@​typescript-
eslint/eslint-plugin</code> from 4.28.4 to 4.29.1</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/466">#466</a> build(deps-dev): bump <code>@​typescript-
eslint/parser</code> from 4.28.4 to 4.29.1</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/468">#468</a> build(deps-dev): bump
<code>@​types/jest</code> from 26.0.24 to 27.0.0</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/470">#470</a> build(deps-dev): bump
<code>@​types/node</code> from 16.4.0 to 16.6.0</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/472">#472</a> build(deps): bump path-parse from 1.0.6 to
1.0.7</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/473">#473</a> build(deps-dev): bump
<code>@​types/jest</code> from 27.0.0 to 27.0.1</li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/codecov/codecov-
action/blob/main/CHANGELOG.md">codecov/codecov-action's
changelog</a>.</em></p>
<blockquote>
<h2>3.1.1</h2>
<h3>Fixes</h3>
<ul>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/661">#661</a> Update deprecation warning</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/593">#593</a> Create codeql-analysis.yml</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/712">#712</a> README: fix typo</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/725">#725</a> fix: Remove a blank row</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/726">#726</a> Update README.md with correct badge
version</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/633">#633</a> Create scorecards-analysis.yml</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/747">#747</a> fix: add more verbosity to validation</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/750">#750</a> Regenerate scorecards-analysis.yml</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/774">#774</a> Switch to v3</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/783">#783</a> Fix network entry in table</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/791">#791</a> Trim arguments after splitting them</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/769">#769</a> Plumb failCi into verification
function.</li>
</ul>
<h3>Dependencies</h3>
<ul>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/713">#713</a> build(deps-dev): bump typescript from 4.6.3
to 4.6.4</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/714">#714</a> build(deps): bump node-fetch from 3.2.3 to
3.2.4</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/724">#724</a> build(deps): bump github/codeql-action from
1 to 2</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/717">#717</a> build(deps-dev): bump
<code>@​types/jest</code> from 27.4.1 to 27.5.0</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/729">#729</a> build(deps-dev): bump
<code>@​types/node</code> from 17.0.25 to 17.0.33</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/734">#734</a> build(deps-dev): downgrade
<code>@​types/node</code> to 16.11.35</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/723">#723</a> build(deps): bump actions/checkout from 2 to
3</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/733">#733</a> build(deps): bump
<code>@​actions/github</code> from 5.0.1 to 5.0.3</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/732">#732</a> build(deps): bump
<code>@​actions/core</code> from 1.6.0 to 1.8.2</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/737">#737</a> build(deps-dev): bump
<code>@​types/node</code> from 16.11.35 to 16.11.36</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/749">#749</a> build(deps): bump ossf/scorecard-action from
1.0.1 to 1.1.0</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/755">#755</a> build(deps-dev): bump typescript from 4.6.4
to 4.7.3</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/759">#759</a> build(deps-dev): bump
<code>@​types/node</code> from 16.11.36 to 16.11.39</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/762">#762</a> build(deps-dev): bump
<code>@​types/node</code> from 16.11.39 to 16.11.40</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/746">#746</a> build(deps-dev): bump
<code>@​vercel/ncc</code> from 0.33.4 to 0.34.0</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/757">#757</a> build(deps): bump ossf/scorecard-action from
1.1.0 to 1.1.1</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/760">#760</a> build(deps): bump openpgp from 5.2.1 to
5.3.0</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/748">#748</a> build(deps): bump actions/upload-artifact
from 2.3.1 to 3.1.0</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/766">#766</a> build(deps-dev): bump typescript from 4.7.3
to 4.7.4</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/799">#799</a> build(deps): bump openpgp from 5.3.0 to
5.4.0</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/798">#798</a> build(deps): bump
<code>@​actions/core</code> from 1.8.2 to 1.9.1</li>
</ul>
<h2>3.1.0</h2>
<h3>Features</h3>
<ul>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/699">#699</a> Incorporate <code>xcode</code> arguments for
the Codecov uploader</li>
</ul>
<h3>Dependencies</h3>
<ul>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/694">#694</a> build(deps-dev): bump
<code>@​vercel/ncc</code> from 0.33.3 to 0.33.4</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/696">#696</a> build(deps-dev): bump
<code>@​types/node</code> from 17.0.23 to 17.0.25</li>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/698">#698</a> build(deps-dev): bump jest-junit from 13.0.0
to 13.2.0</li>
</ul>
<h2>3.0.0</h2>
<h3>Breaking Changes</h3>
<ul>
<li><a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/689">#689</a> Bump to node16 and small fixes</li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="codecov/codecov-action@d9f34f8cd5
cb3b3eb79b3e4b5dae3a16df499a70"><code>d9f34f8</code></a> release: update
changelog and version to 3.1.1 (<a href="https://github-
redirect.dependabot.com/codecov/codecov-
action/issues/828">#828</a>)</li>
<li><a href="codecov/codecov-action@0e9e7b4e8a
4cbde89b1d36ffe91a812536089d02"><code>0e9e7b4</code></a> Plumb failCi
into verification function. (<a href="https://github-
redirect.dependabot.com/codecov/codecov-
action/issues/769">#769</a>)</li>
<li><a href="codecov/codecov-action@7f20bd4c41
51750a1d013be0901b7e35a46c2aad"><code>7f20bd4</code></a> build(deps):
bump <code>@​actions/core</code> from 1.8.2 to 1.9.1 (<a
href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/798">#798</a>)</li>
<li><a href="codecov/codecov-action@13bc2536ab
285b021e72dfb3cd53e56f5c1f4e26"><code>13bc253</code></a> build(deps):
bump openpgp from 5.3.0 to 5.4.0 (<a href="https://github-
redirect.dependabot.com/codecov/codecov-
action/issues/799">#799</a>)</li>
<li><a href="codecov/codecov-action@5c0da1b28f
1c589bf17db0088d610ae638f4ccb7"><code>5c0da1b</code></a> Trim arguments
after splitting them (<a href="https://github-
redirect.dependabot.com/codecov/codecov-
action/issues/791">#791</a>)</li>
<li><a href="codecov/codecov-action@68d5f6d0be
32fb7f92b47e97218cf01690e6e3b5"><code>68d5f6d</code></a> Fix
<code>network</code> entry in table (<a href="https://github-
redirect.dependabot.com/codecov/codecov-
action/issues/783">#783</a>)</li>
<li><a href="codecov/codecov-action@2a829b95de
aeea2d11d127cc0358005714ff35ea"><code>2a829b9</code></a> Switch to v3
(<a href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/774">#774</a>)</li>
<li><a href="codecov/codecov-action@8e09eaf1b4
7fbb5da0e32a27bf08cd11929a1b4a"><code>8e09eaf</code></a> build(deps-
dev): bump typescript from 4.7.3 to 4.7.4 (<a href="https://github-
redirect.dependabot.com/codecov/codecov-
action/issues/766">#766</a>)</li>
<li><a href="codecov/codecov-action@39e222921f
d6f8ff1aae5c56948ff1599a2b57d1"><code>39e2229</code></a> build(deps):
bump actions/upload-artifact from 2.3.1 to 3.1.0 (<a
href="https://github-redirect.dependabot.com/codecov/codecov-
action/issues/748">#748</a>)</li>
<li><a href="codecov/codecov-action@b2b7703473
2e1f073c09521d4f31f4db18b099e2"><code>b2b7703</code></a> build(deps):
bump openpgp from 5.2.1 to 5.3.0 (<a href="https://github-
redirect.dependabot.com/codecov/codecov-
action/issues/760">#760</a>)</li>
<li>Additional commits viewable in <a
href="https://github.com/codecov/codecov-action/compare/v2...v3">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-
badges.githubapp.com/badges/compatibility_score?dependency-
name=codecov/codecov-action&package-manager=github_actions&previous-
version=2&new-version=3)](https://docs.github.com/en/github/managing-
security-vulnerabilities/about-dependabot-security-updates#about-
compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>
    
URL: #35183
Reported by: dependabot[bot]
Reviewer(s): Tobias Diez
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant