Skip to content
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

Add Go support #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

Happy-Ferret
Copy link

Initial naive Go language syntax highlighting as of Go 1.18

Based on https://go.dev/ref/spec#Lexical_elements

Initial naive Go language syntax highlighting as of Go 1.18

Based on https://go.dev/ref/spec#Lexical_elements
@Happy-Ferret
Copy link
Author

I'd like to add an example in Go to Examples/ later too, but I first need to master the syntax.

@ganelson
Copy link
Owner

ganelson commented May 2, 2022

Generally speaking we're asking people not to submit new functionality with PRs yet, but this seems like a quite reasonable addition which doesn't complicate anything else, so I'm inclined to accept. Can you in practice use Inweb sensibly on a Go project with just this change?

@Happy-Ferret
Copy link
Author

Generally speaking we're asking people not to submit new functionality with PRs yet, but this seems like a quite reasonable addition which doesn't complicate anything else, so I'm inclined to accept. Can you in practice use Inweb sensibly on a Go project with just this change?

I haven't fully built my example in Go, yet.
Still learning the ins and outs.

I'm coming from srcweave (which would've been the ideal tool for me if not for the fact it's written in Lisp and there's some issues with it under WSL1) so the syntax is quite different.

Would you mind telling me how to make parts of text bold (if that's possible) and how to include one part of code in another?

In srcweave I can just name a code snippet (i e --- hello world), then include it with @{hello world}. Is something similar available inside inweb?

@Happy-Ferret
Copy link
Author

image

I just gave the tangling a try (still wondering how to bold text and insert one code snippet into another in inweb).

Out is almost correct, except for the inserted func main( ); in the beginning.
Any idea why this is being inserted?

@Happy-Ferret
Copy link
Author

This is the Web I wrote. Strangely, nothing is displayed at all when I switch to = (text as Go) or even = (text as C)

Title: A Literate Hello, World! 
Author: Mark "Happy-Ferret" Bauermeister
Language: Go

@h Introduction

// Go -> https://go.dev // is a modern programming language with a C-like syntax focused on concurrency, modularity and ease-of-use.

// Hello World -> https://en.wikipedia.org/wiki/%22Hello,_World!%22_program#Go // is a basic programming exercise done to showcase a programming language's syntax.


@h Test 

=
// ## Package definition
// Every executable uses the package name **`main`** as an entry point. 
package main

// ## Imports
// Here we import the **`fmt`** (short for "format") module. <br/>
// **`fmt`** contains simple routines to format and output text.
import "fmt"

// The **`Hello`** struct is a slight complication over simply running **`fmt.Println("Hello World")`**. <br/>
// This is done to showcase structs. One of the defining features of the Go programming language.

// While Go itself is not Object-Oriented, structs can act similar to classes by binding data and methods together.

// **`Text`** provides a simple string type.
type Hello struct {
	Text string
}

// **`hello()`** implements the **`Hello`** type struct. <br/>
// It returns **`Text`**.
func (a Hello) hello() {
	fmt.Println(a.Text)
}

// **`main()`** is mandatory in every Go program. <br/>
// It's the function initially run on program startup.
func main() {
	// **`a`** is a variable (pseudo-object) of type **`Hello`**. <br/>
	// We initialize it by feeding the **`Text`** field.
	a := Hello {
		Text: "Hello World",
	}
	// Finally, we call the struct's **`hello()`** method to display the text fed on struct/object initialization.
	a.hello()
}
=

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants