@@ -15,7 +15,6 @@ Haskell parser into the Elm ecosystem.
15
15
import Combine
16
16
import Combine.Char
17
17
import Flip exposing (flip )
18
- import Hex
19
18
import Language.GLSL.Syntax
20
19
exposing
21
20
( CaseLabel (..)
@@ -49,6 +48,7 @@ import Language.GLSL.Syntax
49
48
, TypeSpecifierNoPrecision (..)
50
49
, TypeSpecifierNonArray (..)
51
50
)
51
+ import ParseInt
52
52
53
53
54
54
try : P a -> P a
@@ -388,13 +388,21 @@ This function attempts to parse a given GLSL shader and returns either the parse
388
388
as a `TranslationUnit` type or an error message if parsing fails.
389
389
390
390
-}
391
- parse : String -> Result String TranslationUnit
392
- parse =
393
- Combine . parse
394
- ( Combine . skipMany blank
395
- |> Combine . keep translationUnit
396
- |> Combine . ignore Combine . end
397
- )
391
+ parse : String -> Result { position : Int , messages : List String } TranslationUnit
392
+ parse str =
393
+ case Combine . parse program str of
394
+ Ok ( _, _, res ) ->
395
+ Ok res
396
+
397
+ Err ( _, { position }, ms ) ->
398
+ Err { position = position, messages = ms }
399
+
400
+
401
+ program : Combine .Parser S TranslationUnit
402
+ program =
403
+ Combine . skipMany blank
404
+ |> Combine . keep translationUnit
405
+ |> Combine . ignore Combine . end
398
406
399
407
400
408
@@ -584,12 +592,12 @@ hexadecimal =
584
592
Combine . maybe ( Combine . Char . oneOf [ ' U', ' u' ] )
585
593
|> Combine . andThen
586
594
( \ _ ->
587
- case Hex . fromString ( String . fromList d) of
595
+ case ParseInt . parseIntHex ( String . fromList d) of
588
596
Ok val ->
589
597
Combine . succeed ( IntConstant Hexadecimal val)
590
598
591
599
Err err ->
592
- Combine . fail err
600
+ Combine . fail ( parseIntErrorToString err)
593
601
)
594
602
)
595
603
)
@@ -611,22 +619,30 @@ octal =
611
619
Combine . maybe ( Combine . Char . oneOf [ ' U', ' u' ] )
612
620
|> Combine . andThen
613
621
( \ _ ->
614
- case octFromString ( String . fromList d) of
622
+ case ParseInt . parseIntOct ( String . fromList d) of
615
623
Ok val ->
616
624
Combine . succeed ( IntConstant Octal val)
617
625
618
626
Err err ->
619
- Combine . fail err
627
+ Combine . fail ( parseIntErrorToString err)
620
628
)
621
629
)
622
630
)
623
631
)
624
632
)
625
633
626
634
627
- octFromString : String -> Result String Int
628
- octFromString _ =
629
- Debug . todo " octFromString"
635
+ parseIntErrorToString : ParseInt .Error -> String
636
+ parseIntErrorToString err =
637
+ case err of
638
+ ParseInt . InvalidChar char ->
639
+ " Invalid char: " ++ String . fromChar char
640
+
641
+ ParseInt . OutOfRange char ->
642
+ " Out of range: " ++ String . fromChar char
643
+
644
+ ParseInt . InvalidRadix int ->
645
+ " Invalid radix: " ++ String . fromInt int
630
646
631
647
632
648
badOctal : P ()
0 commit comments