guida-lang / compiler

Guida is a functional programming language that builds upon the solid foundation of Elm, offering backward compatibility with all existing Elm 0.19.1 projects
https://guida-lang.org
Other
40 stars 2 forks source link

fix `getCharWidth` #14

Closed decioferreira closed 1 month ago

decioferreira commented 1 month ago

Currently the implementation of Parse.Primitives.getCharWidth is very poor. We need to fix it.

One of the current issue shows up when trying to compile examples/src/HttpQuotes.elm:

% cd examples
% % guida make src/HttpQuotes.elm                 
Compiled in DEBUG mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
Detected problems in 1 module.
-- ENDLESS STRING ------------------------------------------ /src/HttpQuotes.elm

I got to the end of the line without seeing the closing double quote:

115|                     [ text "ā€” "

                                  ^

Strings look like "this" with double quotes on each end. Is the closing double quote missing in your code?

Note: For a string that spans multiple lines, you can use the multi-line string syntax like this:

    """

    # Multi-line Strings

    - start with triple double quotes

    - write whatever you want

    - no need to escape newlines or double quotes

    - end with triple double quotes

    """
decioferreira commented 1 month ago

miniBill/elm-unicode#3 might have the solution for this

MartinSStewart commented 1 month ago

The fact that getCharWidth 'ā¤' returns 1 while getCharWidth 'šŸŒˆ' returns 4 leaves me stumped. Maybe we need a script that just compiles

module Hello exposing (main)

import Html exposing (text)

main =
    text "<insert unicode char here>"

for various unicode chars until we have enough examples that a pattern emerges.

decioferreira commented 1 month ago

There must some issue somewhere else on the code, because if I try to parse this šŸ™ˆ on https://github.com/elm/core/blob/1.0.5/src/Char.elm#L44 it gives me NaN on getCharWidth, but when trying it separately, it seems to work fine. Running the following on https://elm-lang.org/try:

import Html exposing (text)

main =
  text (Debug.toString (Char.toCode 'šŸ™ˆ'))

Returns 128584

decioferreira commented 1 month ago

finally found the fix for this one, the issue related to elm/core#977. Parse.Primitives. unsafeIndex and elm-tests have been updated as part of this change.