GithubHelp home page GithubHelp logo

Comments (1)

webbnh avatar webbnh commented on August 11, 2024

Unfortunately, the hyperlink above to the comment is not working. I think this one does, though. However, the comment's link to the "earlier comment" doesn't work either; try this one instead. (The reasons why are a long story, the short of which is that I've reported this to GitHub as a bug.)

In any case, here's what the second comment says [slightly edited]:

I have a suggestion for reworking this function, which I think will make it simpler and easier to understand:

  • before entering the loop, look for and remove the opening parenthesis -- it's supposed to be there, and it's an error if it's not;
  • then, if the current token is not a closing paren, enter the loop (i.e., don't enter the loop if there are no arguments in the list); inside the loop, parse the argument; then exit the loop if the next token is not a comma; inside the loop, continue to remove the comma and iterate;
  • after the loop, look for and remove the closing parenthesis -- it's supposed to be there, and it's an error if it's not.
    This saves you from having to have a loop iterator and from having to have special cases for the first iteration of the loop. The only conditional is the exit condition in the middle of the loop if you encounter a closing paren instead of a comma after an argument.

If we were writing out the detailed grammar, it would look like this:

<function_call> := <identifier> <argument_list>
<argument_list> := "(" [ <arguments> ] ")"
<arguments> := <argument> [ "," <argument_list> ]

in specific, the opening and closing parens are part of the argument_list production but not part of the arguments production, and so they should be parsed independently of the arguments. (E.g., the loop should arguably be in a separate function.)

So, to summarize, it would be better if parseFunctionArgs() managed the opening and closing parentheses and parseArgs() managed only the sequence of zero or more arguments separated by commas and left everything else to its caller.

from arcaflow-expressions.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.