簡體   English   中英

Happy項目中“ templates / wrappers.hs”在哪里?

[英]Where does “templates/wrappers.hs” live, in a Happy project?

我正在嘗試使用帶有Happy的Alex進行解析器。 我正在按照這篇文章中的說明進行操作,但是遇到了麻煩。 我試圖追蹤以下類型錯誤的來源:

templates/wrappers.hs:234:9:
    Couldn't match type ‘Token’ with ‘Int -> Alex Token’
    Expected type: AlexInput -> Int -> Alex Token
      Actual type: String -> Token
    In a stmt of a 'do' block: action (ignorePendingBytes inp) len
    In the expression:
      do { alexSetInput inp';
           action (ignorePendingBytes inp) len }
    In a case alternative:
        AlexToken inp' len action
          -> do { alexSetInput inp';
                  action (ignorePendingBytes inp) len }

我的詞法分析器位於src / AnsiParser / FrontEnd / Lex.x中。 所以我看了看dist / build / AnsiParser / FrontEnd / Lex.hs,發現的是:

{-# LINE 1 "templates/wrappers.hs" #-}
{-# LINE 1 "templates/wrappers.hs" #-}

但是我在系統上找不到任何名為“ wrapper.hs”的文件。 我如何找到此錯誤的原因?

如果有用,這是我的Parse.y的簡化版本:

{
module AnsiParser.FrontEnd.Parse where
import AnsiParser.FrontEnd.Lex
}

%name parseTokens
%tokentype { Token }
%lexer { lexWrap } { alexEOF }
%monad { Alex }
%error { parseError }

%token
  -- tokens

%%
-- rules

{
parseError :: Token -> Alex a
parseError tokens = error ("Error!" ++ show tokens)
}

和Lex.x:

{
module AnsiParser.FrontEnd.Lex where
}

%wrapper "monad"

tokens :-
  -- tokens

{
data Token
  = -- token types
  | TokenEOF
  deriving (Show)

scanTokens = alexMonadScan

lexWrap :: (Token -> Alex a) -> Alex a
lexWrap = (alexMonadScan >>=)

alexEOF :: Alex Token
alexEOF = return TokenEOF
}

您可以在alex存儲庫中找到template/wrappers.hs的源代碼:

https://github.com/simonmar/alex/tree/master/templates

在您提供的Lex.x上運行alex給了我這個錯誤:

alex: (Array.!): undefined array element

如果您給我一個可行的例子,我可以找出您的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM