{"id":21976377,"url":"https://github.com/aviralg/tastr","last_synced_at":"2026-05-19T04:36:53.162Z","repository":{"id":73360131,"uuid":"242819212","full_name":"aviralg/tastr","owner":"aviralg","description":"Type AST for R","archived":false,"fork":false,"pushed_at":"2020-05-07T18:27:33.000Z","size":1336,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-28T03:28:53.000Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aviralg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-24T19:05:49.000Z","updated_at":"2020-05-07T18:27:36.000Z","dependencies_parsed_at":"2023-03-24T06:47:48.048Z","dependency_job_id":null,"html_url":"https://github.com/aviralg/tastr","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aviralg%2Ftastr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aviralg%2Ftastr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aviralg%2Ftastr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aviralg%2Ftastr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aviralg","download_url":"https://codeload.github.com/aviralg/tastr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245036121,"owners_count":20550661,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-29T16:03:42.452Z","updated_at":"2026-05-19T04:36:48.141Z","avatar_url":"https://github.com/aviralg.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tastr: Type AST for R\n\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n[![Build Status](https://travis-ci.org/aviralg/tastr.svg?branch=master)](https://travis-ci.org/aviralg/tastr)\n\n`tastr` is a library that implements a grammar for R types. It provides functions to parse types from input streams (files, strings, etc.) to C++ objects. It also provides the reverse functionality to unparse these objects. \nThe Type AST is modeled using C++ classes. The design relies heavily on unique ownership, i.e., an AST node holds unique references to its child nodes.\nThe grammar is implemented using [`flex`](https://westes.github.io/flex/manual/) and [`bison`](https://www.gnu.org/software/bison/manual/bison.html).\n\n## Installation\n\nTo obtain the project source, run:\n\n`$` `git clone https://github.com/aviralg/tastr.git`\n\nTo build the project, run:\n\n`$` `make`\n\nThis will build the following artifacts:\n- **Static library**: `build/lib/libtastr.a`\n- **Shared library**: `build/lib/libtastr.so`\n- **Executable**:     `build/bin/tastr`\n\nTo clean the build artifacts, run:\n\n`$` `make clean`\n\n\nTo execute tests, run:\n\n$ make test\n\nFor building and testing in parallel, invoke `make` with `-j` flag.\n\n## Usage\n\nThe `tastr` executable (`build/bin/tastr`) parses type declarations from different sources and unparses them back.\n\n```\n\u003e build/bin/tastr --help\nParse type declarations.\nUsage:\ntastr [OPTION...]\n\n-h, --help    Print usage\n-l, --lexer   Debug lexer\n-p, --parser  Debug parser\n-a, --ast     Show AST structure\n-s, --style   Style output\n```\n\n### Render input\n\nPass the filename to render the input as is (retains spaces, newlines and comments):\n\n![](docs/images/vanilla-input.png \"Vanilla Output\")\n\nPass `--style` flag to render with styling.\n\n![](docs/images/style-input.png \"Styled Output\")\n\nTo read the input from stdin pass `-` argument (press `Ctrl-D` to simulate end of input).\n\n![](docs/images/stdin-input.png \"Input read from stdin\")\n\nInput can also be directly parsed from the argument if it is quoted using `\"` or `'`.\n\n![](docs/images/argument-single-quoted.png \"Reading argument directly\")\n\n![](docs/images/argument-double-quoted.png \"Reading argument directly\")\n\n\n### View AST structure\n\nUse `--ast` flag to view the ast structure without any styling.\n\n![](docs/images/vanilla-ast.png \"Vanilla AST\")\n\nUse `--style` flag along with `--ast` to view the ast structure with styling.\n\n![](docs/images/style-ast.png \"Styled AST\")\n\n\n## Type Grammar\n\n```\n\n\u003cinteger\u003e: \"integer\"\n         | \"int\"\n         | \"i\"\n\n\u003cdouble\u003e: \"double\"\n        | \"dbl\"\n        | \"d\"\n\n\u003ccomplex\u003e: \"complex\"\n         | \"clx\"\n         | \"x\"\n\n\u003ccharacter\u003e: \"character\"\n           | \"chr\"\n           | \"s\"\n\n\u003clogical\u003e: \"logical\"\n         | \"lgl\"\n         | \"l\"\n\n\u003craw\u003e: \"raw\"\n     | \"r\"\n\n\u003cascalar\u003e: \u003cinteger\u003e\n         | \u003cdouble\u003e\n         | \u003ccomplex\u003e\n         | \u003ccharacter\u003e\n         | \u003clogical\u003e\n\n\u003cnascalar\u003e:  \"^\" \u003cascalar\u003e\n\n\u003cscalar\u003e: \u003cascalar\u003e\n        | \u003craw\u003e\n        | \u003cnascalar\u003e\n\n\u003cenvironment\u003e: \"environment\"\n             | \"env\"\n             | \"t\"\n\n\u003cexpression\u003e: \"expression\"\n            | \"exr\"\n            | \"e\"\n\n\u003clanguage\u003e: \"language\"\n          | \"lng\"\n          | \"g\"\n\n\u003csymbol\u003e: \"symbol\"\n        | \"sym\"\n        | \"y\"\n\n\u003cexternalptr\u003e: \"externalptr\"\n             | \"ept\"\n             | \"p\"\n\n\u003cbytecode\u003e: \"bytecode\"\n          | \"bcd\"\n          | \"b\"\n\n\u003cpairlist\u003e: \"pairlist\"\n          | \"plt\"\n\n\u003cs4\u003e: \"s4\"\n\n\u003cweakref\u003e: \"weakref\"\n         | \"wrf\"\n         | \"w\"\n\n\u003cdataframe\u003e: \"dataframe\"\n           | \"df\"\n\n\u003cany\u003e: \"any\"\n     | \"*\"\n\n\u003cunknown\u003e : \"???\"\n\n\u003cvector\u003e: \u003cscalar\u003e \"[\" \"]\"\n\n\u003clist\u003e: \"list\" \"\u003c\" \u003ctype\u003e \"\u003e\"\n      | \"lst\" \"\u003c\" \u003ctype\u003e \"\u003e\"\n\n\u003cstruct\u003e: \"struct\" \"\u003c\" \u003cnamedtypeseq\u003e \"\u003e\"\n        | \"srt\" \"\u003c\" \u003cnamedtypeseq\u003e \"\u003e\"\n        | \"struct\" \"\u003c\" \"\u003e\"\n        | \"srt\" \"\u003c\" \"\u003e\"\n\n\u003ctuple\u003e: \"tuple\" \"\u003c\" \u003ctypeseq\u003e \"\u003e\"\n       | \"tpl\" \"\u003c\" \u003ctypeseq\u003e \"\u003e\"\n       | \"tuple\" \"\u003c\" \"\u003e\"\n       | \"tpl\" \"\u003c\" \"\u003e\"\n\n\u003ctypeseq\u003e: \u003ctype\u003e\n         | \u003ctypeseq\u003e \",\" \u003ctype\u003e\n\n\u003cnamedtype\u003e: \u003cidentifier\u003e \":\" \u003ctype\u003e\n           | \"^\" \":\" \u003ctype\u003e\n\n\u003cnamedtypeseq\u003e : \u003cnamedtype\u003e\n               | \u003cnamedtypeseq\u003e \",\" \u003cnamedtype\u003e\n\n\u003cparam\u003e: \u003ctype\u003e\n       | \"...\"\n\n\u003cparamseq\u003e: \u003cparam\u003e\n          | \u003cparamseq\u003e \",\" \u003cparam\u003e\n\n\u003cparams\u003e: \"\u003c\" \u003cparamseq\u003e \"\u003e\"\n        | \"\u003c\" \"\u003e\"\n        | \"any\"\n\n\u003cfunction\u003e: \u003cparams\u003e \"=\u003e\" \u003ctype\u003e\n\n\u003cgroup\u003e: \"(\" \u003ctype\u003e \")\"\n\n\u003cnonunion\u003e: \u003cscalar\u003e\n          | \u003cenvironment\u003e\n          | \u003cexpression\u003e\n          | \u003clanguage\u003e\n          | \u003csymbol\u003e\n          | \u003cexternalptr\u003e\n          | \u003cbytecode\u003e\n          | \u003cpairlist\u003e\n          | \u003cs4\u003e\n          | \u003cweakref\u003e\n          | \u003cdataframe\u003e\n          | \u003cvector\u003e\n          | \u003cfunction\u003e\n          | \u003cstruct\u003e\n          | \u003clist\u003e\n          | \u003ctuple\u003e\n          | \u003cgroup\u003e\n          | \u003cunknown\u003e\n\n\u003cunion\u003e: \u003cnonunion\u003e\n       | \u003cunion\u003e \"|\" \u003cnonunion\u003e\n\n\u003cnull\u003e: \"?\"\n      | \"?\" \u003cunion\u003e\n\n\u003ctype\u003e: \u003cunion\u003e\n      | \u003cnull\u003e\n      | \u003cany\u003e\n\n\u003cdecl\u003e: \"type\" \u003cidentifier\u003e \u003ctype\u003e \";\"\n\n\u003cdeclseq\u003e: \u003cdecl\u003e\n         | \u003cdeclseq\u003e \u003cdecl\u003e\n\n```\n\n\n## Useful Resources\n\n### Bison and Flex\n- [Flex Token Order](https://stackoverflow.com/questions/22444094/flex-token-order)\n- [UTK Bison Notes](http://web.eecs.utk.edu/~bvanderz/teaching/cs461Sp11/notes/bison/)\n- [Parsing rule for empty files](https://stackoverflow.com/questions/11047227/no-error-while-parsing-empty-file-yacc-lex)\n- [Dynamic file loading in Flex](https://stackoverflow.com/questions/31839746/loading-external-files-flex-bison-yyin)\n- [Redefine `YY_INPUT` in Flex](https://stackoverflow.com/questions/1920604/how-to-make-yy-input-point-to-a-string-rather-than-stdin-in-lex-yacc-solaris)\n- [C++ istream with Flex](https://stackoverflow.com/questions/9628099/c-istream-with-lex)\n- [Bison/Flex Example](https://github.com/ezaquarii/bison-flex-cpp-example)\n- [Read from C++ streams in Flex](https://stackoverflow.com/questions/780676/string-input-to-flex-lexer)\n- [Lex and Yacc Tutorial](https://www.epaperpress.com/lexandyacc/index.html)\n- [Parsing strings in Flex](http://dinosaur.compilertools.net/flex/flex_11.html)\n- [Bison/Flex Example](https://coldfix.eu/2015/05/16/bison-c++11/)\n- [Unique Pointer as a Semantic Value in Bison](http://www.comrite.com/wp/c11-stdunique_ptr-as-semantic-value-in-bison-c-mode/)\n- [Resolving Grammar Conflicts](https://efxa.org/2014/05/17/techniques-for-resolving-common-grammar-conflicts-in-parsers/)\n- [Bison/Flex Example](http://www.kylheku.com/cgit/txr/tree/parser.l)\n- [Bison/Flex Example](http://www.jonathanbeard.io/tutorials/FlexBisonC++)\n- [Bison/Flex Example](http://panthema.net/2007/flex-bison-cpp-example/)\n- [Bison/Flex Example](https://panthema.net/2007/flex-bison-cpp-example/flex-bison-cpp-example-0.1/doxygen-html/index.html)\n- [Bison/Flex Example](https://github.com/EmilGedda/Leonardo)\n\n### C++: Unique Pointers and Polymorphism\n- [Arguments and Unique Pointers](https://vladris.com/blog/2016/03/11/arguments-and-smart-pointers.html)\n- [Smart Pointer Parameters](https://herbsutter.com/2013/06/05/gotw-91-solution-smart-pointer-parameters/)\n- [Move Constructors and Multiple Inheritance](https://stackoverflow.com/questions/10114701/move-constructors-and-multiple-inheritance)\n- [Copy Constructors and Unique Pointer](https://stackoverflow.com/questions/16030081/copy-constructor-for-a-class-with-unique-ptr)\n- [Rules for Smart Pointers](https://www.modernescpp.com/index.php/c-core-guidelines-rules-to-smart-pointers)\n- [Using Smart Pointers as Class Members](https://stackoverflow.com/questions/15648844/using-smart-pointers-for-class-members)\n- [Cloning, Covariant Return and Smart Pointer](https://www.fluentcpp.com/2017/09/12/how-to-return-a-smart-pointer-and-use-covariance/)\n- [How I Declare my Class and Why](http://howardhinnant.github.io/classdecl.html)\n- [Polymorphic Cloning and CRTP](https://katyscode.wordpress.com/2013/08/22/c-polymorphic-cloning-and-the-crtp-curiously-recurring-template-pattern/)\n- [Delegating Constructors](https://arne-mertz.de/2015/08/new-c-features-inherited-and-delegating-constructors/)\n- [`==` operator and Polymorphism](https://stackoverflow.com/a/565785)\n- [Move constructors and inheritance](https://stackoverflow.com/questions/15351341/move-constructors-and-inheritance)\n- [Move assignment operator and inheritance](https://stackoverflow.com/questions/50854598/inheritence-of-the-move-assignment-operator-in-c)\n- [Move assignment on self](https://stackoverflow.com/questions/9322174/move-assignment-operator-and-if-this-rhs)\n- [C++ `final` keyword](https://smartbear.com/blog/develop/use-c11-inheritance-control-keywords-to-prevent-in/)\n\n### Make and Code Compilation\n- [Compiling a static library in linux](https://stackoverflow.com/questions/2734719/how-to-compile-a-static-library-in-linux)\n- [Compiling C/C++ software](https://gist.github.com/gubatron/32f82053596c24b6bec6)\n\n### R\n- [Various uses of quoting in R](https://stat.ethz.ch/R-manual/R-devel/library/base/html/Quotes.html)\n\n### Miscellaneous\n- [Unicode Characters in the 'Punctuation, Open' Category](https://www.fileformat.info/info/unicode/category/Ps/list.htm)\n- http://www.fileformat.info/info/unicode/block/control_pictures/images.htm\n- https://www.htmlsymbols.xyz/arrow-symbols\n\n\n## TODO\n\n1. Check `clone_impl`, it should be empty for abstract base classes and defined for concrete classes.\n\n    \\\\u[0-9A-Fa-f]{1,4}     { get_identifier().push_back(yytext); }\n    \\\\U[0-9A-Fa-f]{1,8}     { get_identifier().push_back(yytext); }\n    \\\\u{LBRACE}[0-9A-Fa-f]{1,4}{RBRACE} { get_identifier().push_back(yytext); }\n    \\\\U{LBRACE}[0-9A-Fa-f]{1,8}{RBRACE} { get_identifier().push_back(yytext); }\n\n\n\n\n\n    \\\\[0-7]{2}              { get_identifier().append(\"0\"); get_identifier().push_back(yytext[1]); get_identifier().push_back(yytext[2]); }\n    \\\\[0-7]{3}              { get_identifier().append(yytext); }\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faviralg%2Ftastr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faviralg%2Ftastr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faviralg%2Ftastr/lists"}