Skip to content

Commit

Permalink
feat: add _f suffix for float literals
Browse files Browse the repository at this point in the history
  • Loading branch information
aboeglin committed Apr 14, 2024
1 parent 31f4a56 commit 17b9efc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions compiler/main/Parse/Madlib/Grammar.y
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ module Parse.Madlib.Grammar where

import Text.Printf
import Control.Monad.Except
import qualified Data.Map as M
import qualified Data.Map as M
import qualified Data.List as List
import Data.Char(isUpper)

import Parse.Madlib.Lexer
import Infer.Type
import qualified AST.Source as Src
import qualified AST.Source as Src
import Explain.Location
import Run.Target
import Debug.Trace
import Text.Show.Pretty
import Debug.Trace
import Text.Show.Pretty
}

%name parseMadlib ast
Expand Down Expand Up @@ -672,7 +673,7 @@ literal :: { Src.Exp }
| byte %shift { Src.Source (tokenArea $1) (tokenTarget $1) (Src.LByte $ init $ init (strV $1)) }
| short %shift { Src.Source (tokenArea $1) (tokenTarget $1) (Src.LShort $ init $ init (strV $1)) }
| int %shift { Src.Source (tokenArea $1) (tokenTarget $1) (Src.LInt $ init $ init (strV $1)) }
| float %shift { Src.Source (tokenArea $1) (tokenTarget $1) (Src.LFloat $ strV $1) }
| float %shift { Src.Source (tokenArea $1) (tokenTarget $1) (Src.LFloat $ if "_f" `List.isSuffixOf` (strV $1) then init (init (strV $1)) else strV $1) }
| str %shift { Src.Source (tokenArea $1) (tokenTarget $1) (Src.LStr $ strV $1) }
| char %shift { Src.Source (tokenArea $1) (tokenTarget $1) (Src.LChar $ charData $1) }
| true %shift { Src.Source (tokenArea $1) (tokenTarget $1) (Src.LBool $ strV $1) }
Expand Down
2 changes: 1 addition & 1 deletion compiler/main/Parse/Madlib/Lexer.x
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ $digit = 0-9 -- digits
@decimal = $digit($digit)* -- decimal
@negative = \-
@signed = @negative ?
@floating = @decimal \. @decimal | @decimal -- floating point
@floating = @decimal \. @decimal (_f)? | @decimal (_f)? -- floating point

tokens :-
<0, jsxOpeningTag, jsxAutoClosed, jsxText> $head*\/\* { beginComment }
Expand Down

0 comments on commit 17b9efc

Please sign in to comment.