Skip to content

add golang and link to online executor #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion de/14-01.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
</p>
<div class="language">
<input type="text" value="regulärer Ausdruck" class="regex"/>
<input type="text" value="Der reguläre Ausdruck durchsucht diesen Text." class="text"/>
<input type="text" value="Ein regulärer Ausdruck durchsucht diesen Text." class="text"/>
</div>
40 changes: 36 additions & 4 deletions js/languages.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,38 @@ function updateLanguageGrep(regularExpression, text) {
return "regex='" + regex + "'\ntext='" + text + "'\necho \"$text\" | grep -E \"$text\"";
}

function updateLanguageGo(regularExpression, text) {
var regex = regularExpression.replace(/"/g, '\"');
var text = text.replace(/"/g, '\"');
return 'package main\n\n' +
'import "fmt"\n' +
'import "regexp"\n\n' +
'func main() {\n' +
' regex := "' + regex + '"\n' +
' text := "' + text + '"\n\n' +
' r, _ := regexp.Compile(regex)\n\n' +
' fmt.Println(r.FindAllString(text, -1))\n' +
'}';
}

updateLanguages = [
{"name": "Python", "update": updateLanguagePython},
{"name": "JavaScript", "update": updateLanguageJavaScript},
{"name": "Grep in Linux Shell", "update": updateLanguageGrep},
{
"name": "Python",
"update": updateLanguagePython,
"online": "http://pythontutor.com/visualize.html#mode=edit",
}, {
"name": "JavaScript",
"update": updateLanguageJavaScript,
"online": "https://jsfiddle.net/",
}, {
"name": "Grep in Linux Shell",
"update": updateLanguageGrep,
"online": "http://www.tutorialspoint.com/execute_bash_online.php",
}, {
"name": "Go",
"update": updateLanguageGo,
"online": "https://play.golang.org/",
},
]

function watchLanguageField(languageField, textElement, regex) {
Expand All @@ -34,7 +62,11 @@ function watchLanguageField(languageField, textElement, regex) {
div.classList.add("programming-language")
var heading = document.createElement("h2");
heading.innerText = lang.name;
div.appendChild(heading);
var link = document.createElement("a");
link.href = lang.online;
link.appendChild(heading)
link.target = "_blank";
div.appendChild(link);
var textarea = document.createElement("textarea");
div.appendChild(textarea);
textareas.push(textarea);
Expand Down