Skip to content

Commit

Permalink
fix a bug on saving and loading terminals mixed with alphabets and sy…
Browse files Browse the repository at this point in the history
…mbols such as zero?
  • Loading branch information
kwanghoon committed Apr 4, 2022
1 parent e8ed981 commit 8613da8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: yapb
version: 0.2.1
version: 0.2.2
github: "kwanghoon/yapb"
license: BSD3
author: "Kwanghoon Choi"
Expand Down
9 changes: 8 additions & 1 deletion src/parserlib/LoadAutomaton.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import AutomatonType
import SaveProdRules(tokenizeLhs)
import System.IO
import Text.Read (readMaybe)
import Data.Char (isSpace)

loadAutomaton :: String -> String -> String
-> IO (ActionTable, GotoTable, ProdRules)
Expand Down Expand Up @@ -35,7 +36,12 @@ tokenizeStateNumInAction str =

tokenizeTerminalInAction :: String -> IO (String, Action, ActionTable)
tokenizeTerminalInAction str =
case lex str of
let str' = dropWhile Data.Char.isSpace str
terminal = takeWhile (not . Data.Char.isSpace) str'
str'' = drop (length terminal) str'
lexRes = if length terminal > 0 then [(terminal,str'')] else [("",str'')]
in
case lexRes of
[] -> fail "No terminal found (1)"
[("", therest)] -> fail "No terminal found (2)"
[(terminal, therest)] -> do
Expand All @@ -56,6 +62,7 @@ tokenizeActioninAction str =
"Accept" -> do
actTbl <- tokenizeStateNumInAction therest
return (Accept, actTbl)
_ -> fail ("Unexpected action: " ++ action)

tokenizeShiftReduceStateNumInAction :: String -> (Int -> Action)
-> IO (Action, ActionTable)
Expand Down
10 changes: 5 additions & 5 deletions src/parserlib/SaveProdRules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ tokenizeArrow str =
[(token,therest)] -> error ("No arrow found: " ++ token)

tokenizeRhs :: String -> [String]
tokenizeRhs str =
case lex str of
[] -> []
[("",therest)] -> []
[(token,therest)] -> token : tokenizeRhs therest
tokenizeRhs str = words str -- Terminals and nonterminls are space-separated words in RHS
-- case lex str of
-- [] -> []
-- [("",therest)] -> []
-- [(token,therest)] -> token : tokenizeRhs therest

-- Utility
concatWith :: [String] -> String -> String
Expand Down
4 changes: 2 additions & 2 deletions yapb.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
-- hash: 32f1cadd82bb926fdd3eb1f2135b5f51d9810df76c812b40a242371ea1ae14e0
-- hash: d0b9a77c0d67fbcf2f0f940bd558e929e1fa2e0e1ca4d08e171c07c0244e03ad

name: yapb
version: 0.2.1
version: 0.2.2
synopsis: Yet Another Parser Builder (YAPB)
description: A programmable LALR(1) parser builder system. Please see the README on GitHub at <https://github.com/kwanghoon/yapb#readme>
category: parser builder
Expand Down

0 comments on commit 8613da8

Please sign in to comment.