From ffd7b27abd050dc50f5986c9b94f8fb5d120c2db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20K=C3=A4llberg?= Date: Mon, 11 Sep 2023 12:29:13 +0200 Subject: [PATCH 1/4] Improve syntax error messages Now you will get error messages like these: example.gf:1:21: Syntax error: Unexpected token '}'. Expected one of: - '{' - 'open' - an identifier --- src/compiler/GF/Grammar/Lexer.x | 11 +++++++++-- src/compiler/GF/Grammar/Parser.y | 17 +++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/compiler/GF/Grammar/Lexer.x b/src/compiler/GF/Grammar/Lexer.x index 3653887269..b3d271dddb 100644 --- a/src/compiler/GF/Grammar/Lexer.x +++ b/src/compiler/GF/Grammar/Lexer.x @@ -4,7 +4,7 @@ module GF.Grammar.Lexer ( Token(..), Posn(..) , P, runP, runPartial, token, lexer, getPosn, failLoc - , isReservedWord + , isReservedWord, invMap ) where import Control.Applicative @@ -134,7 +134,7 @@ data Token | T_Double Double -- double precision float literals | T_Ident Ident | T_EOF --- deriving Show -- debug + deriving (Eq, Ord, Show) -- debug res = eitherResIdent eitherResIdent :: (Ident -> Token) -> Ident -> Token @@ -224,6 +224,13 @@ resWords = Map.fromList ] where b s t = (identS s, t) +invMap :: Map.Map Token String +invMap = res + where + lst = Map.toList resWords + flp = map (\(k,v) -> (v,showIdent k)) lst + res = Map.fromList flp + unescapeInitTail :: String -> String unescapeInitTail = unesc . tail where unesc s = case s of diff --git a/src/compiler/GF/Grammar/Parser.y b/src/compiler/GF/Grammar/Parser.y index 85b081cd7e..6aedcd3994 100644 --- a/src/compiler/GF/Grammar/Parser.y +++ b/src/compiler/GF/Grammar/Parser.y @@ -37,6 +37,9 @@ import PGF(mkCId) %name pBNFCRules ListCFRule %name pEBNFRules ListEBNFRule +%errorhandlertype explist +%error { happyError } + -- no lexer declaration %monad { P } { >>= } { return } %lexer { lexer } { T_EOF } @@ -702,8 +705,18 @@ Posn { -happyError :: P a -happyError = fail "syntax error" +happyError :: (Token, [String]) -> P a +happyError (t,strs) = fail $ + "Syntax error:\n Unexpected " ++ showToken t ++ ".\n Expected one of:\n" + ++ unlines (map ((" - "++).cleanupToken) strs) + + where + cleanupToken "Ident" = "an identifier" + cleanupToken x = x + showToken (T_Ident i) = "identifier '" ++ showIdent i ++ "'" + showToken t = case Map.lookup t invMap of + Nothing -> show t + Just s -> "token '" ++ s ++"'" mkListId,mkConsId,mkBaseId :: Ident -> Ident mkListId = prefixIdent "List" From 003ab57576c5f1fccb2a7e712bf342c771ab7fec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20K=C3=A4llberg?= Date: Mon, 11 Sep 2023 18:43:14 +0800 Subject: [PATCH 2/4] Bump version of haskell github action The old one was failing --- .github/workflows/build-all-versions.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-all-versions.yml b/.github/workflows/build-all-versions.yml index ecbcfff99e..d7cac5ce48 100644 --- a/.github/workflows/build-all-versions.yml +++ b/.github/workflows/build-all-versions.yml @@ -33,7 +33,7 @@ jobs: - uses: actions/checkout@v2 if: github.event.action == 'opened' || github.event.action == 'synchronize' || github.event.ref == 'refs/heads/master' - - uses: haskell/actions/setup@v1.2.9 + - uses: haskell/actions/setup@v2 id: setup-haskell-cabal name: Setup Haskell with: @@ -73,7 +73,7 @@ jobs: - uses: actions/checkout@v2 if: github.event.action == 'opened' || github.event.action == 'synchronize' || github.event.ref == 'refs/heads/master' - - uses: haskell/actions/setup@v1.2.9 + - uses: haskell/actions/setup@v2 name: Setup Haskell Stack with: ghc-version: ${{ matrix.ghc }} From 88db715c3d93b15341b055469f6d470de9273616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20K=C3=A4llberg?= Date: Mon, 11 Sep 2023 13:03:05 +0200 Subject: [PATCH 3/4] Fix ghc-7.10.3 build in gh-actions ghc-7.10.3 is not supported in the latest builder, so we need an older version of ubuntu for it to work --- .github/workflows/build-all-versions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-all-versions.yml b/.github/workflows/build-all-versions.yml index d7cac5ce48..eea778daa1 100644 --- a/.github/workflows/build-all-versions.yml +++ b/.github/workflows/build-all-versions.yml @@ -62,7 +62,7 @@ jobs: stack: name: stack / ghc ${{ matrix.ghc }} - runs-on: ubuntu-latest + runs-on: ${{ matrix.ghc == '7.10.3' && 'ubuntu-2004' || 'ubuntu-latest' }} strategy: matrix: stack: ["latest"] From b90666455efd3b83345ad4b77eac4b64373e4c83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20K=C3=A4llberg?= Date: Mon, 11 Sep 2023 13:17:19 +0200 Subject: [PATCH 4/4] Fix typo --- .github/workflows/build-all-versions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-all-versions.yml b/.github/workflows/build-all-versions.yml index eea778daa1..f6f1b82a7d 100644 --- a/.github/workflows/build-all-versions.yml +++ b/.github/workflows/build-all-versions.yml @@ -62,7 +62,7 @@ jobs: stack: name: stack / ghc ${{ matrix.ghc }} - runs-on: ${{ matrix.ghc == '7.10.3' && 'ubuntu-2004' || 'ubuntu-latest' }} + runs-on: ${{ matrix.ghc == '7.10.3' && 'ubuntu-20.04' || 'ubuntu-latest' }} strategy: matrix: stack: ["latest"]