{"action":"closed","issue":{"url":"https://api.github.com/repos/systemincloud/rly/issues/5","repository_url":"https://api.github.com/repos/systemincloud/rly","labels_url":"https://api.github.com/repos/systemincloud/rly/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/systemincloud/rly/issues/5/comments","events_url":"https://api.github.com/repos/systemincloud/rly/issues/5/events","html_url":"https://github.com/systemincloud/rly/issues/5","id":313631458,"number":5,"title":"dynamic regex in function","user":{"login":"HenricoWitvliet","id":2179781,"avatar_url":"https://avatars1.githubusercontent.com/u/2179781?v=4","gravatar_id":"","url":"https://api.github.com/users/HenricoWitvliet","html_url":"https://github.com/HenricoWitvliet","followers_url":"https://api.github.com/users/HenricoWitvliet/followers","following_url":"https://api.github.com/users/HenricoWitvliet/following{/other_user}","gists_url":"https://api.github.com/users/HenricoWitvliet/gists{/gist_id}","starred_url":"https://api.github.com/users/HenricoWitvliet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HenricoWitvliet/subscriptions","organizations_url":"https://api.github.com/users/HenricoWitvliet/orgs","repos_url":"https://api.github.com/users/HenricoWitvliet/repos","events_url":"https://api.github.com/users/HenricoWitvliet/events{/privacy}","received_events_url":"https://api.github.com/users/HenricoWitvliet/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-04-12T08:46:33Z","updated_at":"2018-04-24T19:26:00Z","closed_at":"2018-04-24T19:26:00Z","author_association":"CONTRIBUTOR","body":"I like this library. But I think I'm using it in a wrong way. I try to build a dynamic parser. I build a regular expression using the labels I expect, and I try to use that variable as the re-argument for a lexer token:\r\n\r\n    reLABEL <- '(label1|label2|....'\r\n    ....\r\n    lexer <- R6Class(\"Lexer\",\r\n      ....\r\n      t_LABEL = function(re = reLABEL, t) {\r\n\r\nIn the function *get_regex* the value is not a string, but is of class \"name\" and has the value reLABEL. \r\n\r\nIt seems that the following change works for me:\r\n\r\n    get_regex = function(func) {\r\n      val <- formals(func)[['re']]\r\n      if (!is(val, 'character')) {\r\n        val <- eval(val, parent.env(environment(func)))\r\n      }\r\n      return(val)\r\n    }\r\n\r\nDo you know a better way to use variables containing the string with the regular expression?\r\n"}}
{"actor":{"display_login":"marekjagielski"}}