Giter Site home page Giter Site logo

Block parsing bug about language-c-quote HOT 10 CLOSED

mainland avatar mainland commented on August 30, 2024
Block parsing bug

from language-c-quote.

Comments (10)

mchakravarty avatar mchakravarty commented on August 30, 2024

Did you declare 'CGRect' as a type name? If not, you need to write

[self.codeText addKeyboardPanningWithActionHandler:^(typename CGRect keyboardFrameInView) {
        /*
         */
    }];

Identifiers that are type names and those that are not are different syntactic categories in C. (We really should start slurping in header files to automatically get all defined names, but for the moment you need to do it manually.)

from language-c-quote.

mxswd avatar mxswd commented on August 30, 2024

Ok, putting the typename into the block param like that isn't working either.

[self.codeText addKeyboardPanningWithActionHandler:^(typename CGRect keyboardFrameInView) {
}];

Errors with:

parse error on `typename'

from language-c-quote.

mxswd avatar mxswd commented on August 30, 2024

For initializers:

typename NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

Errors with:

expected ';' but got `NSArray'

from language-c-quote.

mchakravarty avatar mchakravarty commented on August 30, 2024

What quoter are you using?

Prelude Language.C.Quote.ObjC> [cunit|typename NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);|]
[DecDef (InitGroup (DeclSpec [] [] (Tnamed (Id "NSArray" ) [] ) ) [] [Init (Id "paths" ) (Ptr [] (DeclRoot ) ) Nothing (Just (ExpInitializer (FnCall (Var (Id "NSSearchPathForDirectoriesInDomains" ) ) [Var (Id "NSDocumentDirectory" ) ,Var (Id "NSUserDomainMask" ) ,Var (Id "YES" ) ] ) )) [] ] ) ]

from language-c-quote.

mchakravarty avatar mchakravarty commented on August 30, 2024

Also

Prelude Language.C.Quote.ObjC> [cexp|[self.codeText addKeyboardPanningWithActionHandler:^(typename CGRect keyboardFrameInView) { }] |]
ObjCMsg (ObjCRecvExp (Member (Var (Id "self" ) ) (Id "codeText" ) ) ) [ObjCArg (Just (Id "addKeyboardPanningWithActionHandler" )) (Just (BlockLit (BlockParam [Param (Just (Id "keyboardFrameInView" )) (DeclSpec [] [] (Tnamed (Id "CGRect" ) [] ) ) (DeclRoot ) ] ) [] [] )) ] [] 

from language-c-quote.

mxswd avatar mxswd commented on August 30, 2024
import qualified Language.C.Syntax as C
import qualified Language.C.Parser as P
import qualified Data.ByteString.Char8 as B
import Data.Loc

parseFile :: String -> IO [C.Definition]
parseFile s = do
    let exts = [C.ObjC] -- TODO: Add C.QInit when supported
    case P.parse exts [] P.parseUnit (B.pack s) start of
      Left err   -> error $ show err
      Right defs -> return defs
  where
    start :: Pos
    start = startPos "<>"

main = do
  x <- parseFile "typename NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);"
  print x

from language-c-quote.

mchakravarty avatar mchakravarty commented on August 30, 2024

Does it work for you if you use quasi quotes (as in my example) as opposed to invoking the parser explicitly?

from language-c-quote.

mxswd avatar mxswd commented on August 30, 2024

Yeah it does. Maybe I'm missing an extension?

from language-c-quote.

mainland avatar mainland commented on August 30, 2024

typename is only permitted when using quasiquoting. The whole-file parser is only to be used with preprocessed files.

from language-c-quote.

mxswd avatar mxswd commented on August 30, 2024

Ah of course. Thanks.

from language-c-quote.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.