{"action":"created","issue":{"url":"https://api.github.com/repos/sourcegraph/scanner/issues/1","labels_url":"https://api.github.com/repos/sourcegraph/scanner/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/sourcegraph/scanner/issues/1/comments","events_url":"https://api.github.com/repos/sourcegraph/scanner/issues/1/events","html_url":"https://github.com/sourcegraph/scanner/issues/1","id":68262095,"number":1,"title":"extend scanner.Definition to support subpatterns/subdefinitions","user":{"login":"alaska","id":926884,"avatar_url":"https://avatars.githubusercontent.com/u/926884?v=3","gravatar_id":"","url":"https://api.github.com/users/alaska","html_url":"https://github.com/alaska","followers_url":"https://api.github.com/users/alaska/followers","following_url":"https://api.github.com/users/alaska/following{/other_user}","gists_url":"https://api.github.com/users/alaska/gists{/gist_id}","starred_url":"https://api.github.com/users/alaska/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alaska/subscriptions","organizations_url":"https://api.github.com/users/alaska/orgs","repos_url":"https://api.github.com/users/alaska/repos","events_url":"https://api.github.com/users/alaska/events{/privacy}","received_events_url":"https://api.github.com/users/alaska/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-04-14T05:01:40Z","updated_at":"2015-04-14T05:05:37Z","closed_at":null,"body":"I'm working on using sourcegraph/scanner and sourcegraph/lexer to create a nice pure go solution for syntax highlighting.  Currently the libraries meet most of my needs, but I feel a couple of additions could make things easier to add nicer functionality and support more languages.\r\n\r\nSpecifically, I think it would be nice to extend scanner.Definition to support subpatterns.  Something like this:\r\n\r\n```go\r\ntype Definition struct {\r\n    Regex *regexp.Regexp\r\n    Type string\r\n    subpatterns []Definition\r\n}\r\n\r\nfunc (d Definition) Contains( s ...Definition) Definition {\r\n    d.subpatterns = append(d.subpatterns, s...)\r\n    return d\r\n}\r\n```\r\n\r\nThis would allow use of the patterns in lexer/common.go, but extending them in a language-specific way to support nice little additions like highlighting verbs and escapes in strings:\r\n\r\n```go\r\n//In lexer/languages.go:\r\nLanguages = map[string]*Language{\r\n\"Go\": &Language{\r\n    Extensions: []string{\"go\"},\r\n    Map: append([]scanner.Definition{\r\n        // Single line comments\r\n        regex[\"comments\"][\"oneline\"],\r\n\r\n        // Multi-line comments\r\n        regex[\"comments\"][\"multiline\"],\r\n\r\n        // Double quote strings\r\n        regex[\"strings\"][\"double\"].Contains(\r\n            scanner.Definition{regexp.MustCompile(`%[#0\\-[:space:]+*]*[vTtbcdoqxXUeEfgGsp]`), \"VERB\"},\r\n        ),\r\n        // ...\r\n```\r\nAny thoughts on whether something like this would make a welcome addition?"},"comment":{"url":"https://api.github.com/repos/sourcegraph/scanner/issues/comments/92599522","html_url":"https://github.com/sourcegraph/scanner/issues/1#issuecomment-92599522","issue_url":"https://api.github.com/repos/sourcegraph/scanner/issues/1","id":92599522,"user":{"login":"shurcooL","id":1924134,"avatar_url":"https://avatars.githubusercontent.com/u/1924134?v=3","gravatar_id":"","url":"https://api.github.com/users/shurcooL","html_url":"https://github.com/shurcooL","followers_url":"https://api.github.com/users/shurcooL/followers","following_url":"https://api.github.com/users/shurcooL/following{/other_user}","gists_url":"https://api.github.com/users/shurcooL/gists{/gist_id}","starred_url":"https://api.github.com/users/shurcooL/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shurcooL/subscriptions","organizations_url":"https://api.github.com/users/shurcooL/orgs","repos_url":"https://api.github.com/users/shurcooL/repos","events_url":"https://api.github.com/users/shurcooL/events{/privacy}","received_events_url":"https://api.github.com/users/shurcooL/received_events","type":"User","site_admin":false},"created_at":"2015-04-14T05:05:37Z","updated_at":"2015-04-14T05:05:37Z","body":"> I'm working on using sourcegraph/scanner and sourcegraph/lexer to create a nice pure go solution for syntax highlighting.\r\n\r\nHi, since I'm not familiar with your work yet, I want to ask this first:\r\n\r\nAre you aware of https://github.com/sourcegraph/syntaxhighlight and https://github.com/sourcegraph/annotate packages? If so, are they not sufficient, and how would your syntax highlighting solution differ?\r\n\r\nI'm just looking to clarify. Thanks!"}}