Giter Site home page Giter Site logo

Comments (3)

josevalim avatar josevalim commented on June 10, 2024 1

You have to build the whole list. You can see how we deal with this in Elixir's syntax highlighter: https://github.com/elixir-makeup/makeup_elixir/blob/master/lib/makeup/lexers/elixir_lexer/atoms.ex.exs :)

from nimble_parsec.

josevalim avatar josevalim commented on June 10, 2024

Wouldn't it be utf8_string(not: ?")?

from nimble_parsec.

vincent-lg avatar vincent-lg commented on June 10, 2024

Unfortunately, it doesn't seem to do quite what I want.
Identifiers should be utf-8 letters. I was at a loss about doing it without a regex or at least a true function I could call and which would make sure the string would not be parsed more than necessary. aérien + 5 should accept everything before the space (which is not a valid letter).
I thought I had found the solution with repeat_while:

  vexpr_var =
    repeat_while(
      utf8_char([]),
      {:check_varname, []}
    )
    |> unwrap_and_tag(:var)
    |> label("variable")

  defp check_varname(name, context, _, _) do
    case String.match?(name, ~r/^[[:alpha:]]+$/u) do
      true -> {:cont, context}
      false -> {:halt, context}
    end
  end

But the check_varname function seems to be called only once, after all the characters in the strings have been read. Not exactly what I'd like.
I also tried to play with post_traverse, but I guess this won't do since I need to validate the string.
Perhaps there's no solution. Probably something I just miss.

from nimble_parsec.

Related Issues (20)

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.