<commit_before>! Copyright (C) 2008, 2009 <NAME>, <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien alien.c-types arrays assocs
combinators combinators.short-circuit effects grouping
kernel parser sequences splitting words fry locals lexer
namespaces summary math vocabs.parser ;
IN: alien.parser

: parse-c-type-name ( name -- word/string )
    [ search ] keep or ;

: parse-c-type ( string -- array )
    {
        { [ dup "void" =            ] [ drop void ] }
        { [ CHAR: ] over member?    ] [ parse-array-type parse-c-type-name prefix ] }
        { [ dup search c-type-word? ] [ parse-c-type-name ] }
        { [ dup c-types get at      ] [ ] }
        { [ "*" ?tail               ] [ parse-c-type-name resolve-pointer-type ] }
        [ no-c-type ]
    } cond ;

: scan-c-type ( -- c-type )
    scan dup "{" =
    [ drop \ } parse-until >array ]
    [ parse-c-type ] if ; 

: reset-c-type ( word -- )
    { "c-type" "pointer-c-type" "callback-effect" "callback-abi" } reset-props ;

: CREATE-C-TYPE ( -- word )
    scan current-vocab create dup reset-c-type ;

: normalize-c-arg ( type name -- type' name' )
    [ length ]
    [
        [ CHAR: * = ] trim-head
        [ length - CHAR: * <array> append ] keep
    ] bi
    [ parse-c-type ] dip ;

: parse-arglist ( parameters return -- types effect )
    [
        2 group [ first2 normalize-c-arg 2array ] map
        unzip [ "," ?tail drop ] map
    ]
    [ [ { } ] [ 1array ] if-void ]<commit_msg>disable parsing of string c-types<commit_after>! Copyright (C) 2008, 2009 <NAME>, <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien alien.c-types arrays assocs
combinators combinators.short-circuit effects grouping
kernel parser sequences splitting words fry locals lexer
namespaces summary math vocabs.parser ;
IN: alien.parser

: parse-c-type-name ( name -- word )
    dup search [ nip ] [ no-word ] if* ;

: parse-c-type ( string -- array )
    {
        { [ dup "void" =            ] [ drop void ] }
        { [ CHAR: ] over member?    ] [ parse-array-type parse-c-type-name prefix ] }
        { [ dup search c-type-word? ] [ parse-c-type-name ] }
        { [ "**" ?tail              ] [ drop void* ] }
        { [ "*" ?tail               ] [ parse-c-type-name resolve-pointer-type ] }
        [ parse-c-type-name no-c-type ]
    } cond ;

: scan-c-type ( -- c-type )
    scan dup "{" =
    [ drop \ } parse-until >array ]
    [ parse-c-type ] if ; 

: reset-c-type ( word -- )
    { "c-type" "pointer-c-type" "callback-effect" "callback-abi" } reset-props ;

: CREATE-C-TYPE ( -- word )
    scan current-vocab create dup reset-c-type ;

: normalize-c-arg ( type name -- type' name' )
    [ length ]
    [
        [ CHAR: * = ] trim-head
        [ length - CHAR: * <array> append ] keep
    ] bi
    [ parse-c-type ] dip ;

: parse-arglist ( parameters return -- types effect )
    [
        2 group [ first2 normalize-c-arg 2array ] map
        unzip [ "," ?tail drop ] map
    ]
    [ [ { } ] [ 1array ] if-void ]
{'fraction_non_alphanumeric': 0.1537958115183246, 'fraction_numerical': 0.007853403141361256, 'mean_word_length': 2.0, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1762275', 'n_tokens_mistral': 1061, 'n_tokens_neox': 1013, 'n_words': 254}