Skip to content
Open
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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target/*
target
9 changes: 9 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true


[prune]
go-tests = true
unused-packages = true
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.PHONY: test build cover

test:
echo "Not implemented"

cover:
echo "Not implemented"

build:
go build -o target/jave

clean:
go clean
rm -rf target
19 changes: 19 additions & 0 deletions Test.jave
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/\
Jave script to test lexing
\/
/\
Basic function
layout:
operation (<NAME>)<<var type>> (<returnVar type>) <{

}>
\/
//\\ inline comment
operation (<Test>)<<name strand>> (<nameWithText strand>) <{
allow newName 2b=2 name + << surname>>;;
give newName up;;
}>

operation (<entry>)<<>>(<>) <{
Test :< <<My Name>>;;
}>
6 changes: 6 additions & 0 deletions Test2.jave
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/\
Jave script to test v0.1 lexing
\/
//\\ Print something
insist <<This is some text>>
insist <<This allows you to use \>\> as a string!>>
43 changes: 43 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright © 2018 Chedder <[email protected]>
//
// MIT License

package main

import (
"fmt"
"log"
"os"

"github.com/OrcaLLC/jave/src/lexer"
)

func main() {
// Fetch arguments to get the filename
runArgs := os.Args[1:]

// If no arguments exit quietly because we don't have interactive yet
if len(runArgs) < 1 {
log.Fatal("No interactive jave yet.")
}

filePath := runArgs[0]

// Jave can only run one file at a time, dingus
if len(runArgs) > 1 {
log.Printf("Additional arguments ignored. Using: [%s] but found %v\n", filePath, runArgs)
}

// Load what we need then load either the file handler or input getter
thing, err := lexer.NewJaveFile(filePath)
if err != nil {
log.Fatalf("[JAVE FAIL]: %v\n", err)
}
//fmt.Printf("%v", thing)
//fmt.Print("\n")
//fmt.Print("\n")

stuff := lexer.Lex(thing)
fmt.Printf("%v", stuff)
fmt.Print("\n")
}
136 changes: 136 additions & 0 deletions src/lexer/javefile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package lexer

import (
"bytes"
"io/ioutil"
"path/filepath"
"strings"
)

// JaveFile defines incoming jave source
type JaveFile struct {
Path string
Name string
Contents []rune
NewLines []int
Tokens []*Token
}

// NewJaveFile ingests jave source file
func NewJaveFile(path string) (*JaveFile, error) {
// Get the filename
filename := filepath.Base(path)

jf := &JaveFile{Name: filename, Path: path}
jf.NewLines = append(jf.NewLines, -1)
jf.NewLines = append(jf.NewLines, -1)

contents, err := ioutil.ReadFile(jf.Path)
if err != nil {
return nil, err
}

jf.Contents = []rune(string(contents))
return jf, nil
}

// GetLine gets a line of coke
func (s *JaveFile) GetLine(line int) string {
return string(s.Contents[s.NewLines[line]+1 : s.NewLines[line+1]])
}

// TabWidth idk
//const TabWidth = 4

// MarkPos because mark is a pos
func (s *JaveFile) MarkPos(pos Position) string {
buf := new(bytes.Buffer)

lineString := s.GetLine(pos.Line)
lineStringRunes := []rune(lineString)
pad := pos.Char - 1

buf.WriteString(strings.Replace(strings.Replace(lineString, "%", "%%", -1), "\t", " ", -1))
buf.WriteRune('\n')
for i := 0; i < pad; i++ {
spaces := 1

if lineStringRunes[i] == ' ' {
spaces = 1
}

for t := 0; t < spaces; t++ {
buf.WriteRune(' ')
}
}
buf.WriteString("^")
buf.WriteRune('\n')

return buf.String()

}

// MarkSpan ohai mark
func (s *JaveFile) MarkSpan(span Span) string {
// if the span is just one character, use MarkPos instead
spanEnd := span.End()
spanEnd.Char--
if span.Start() == spanEnd {
return s.MarkPos(span.Start())
}

// mark the span
buf := new(bytes.Buffer)

for line := span.StartLine; line <= span.EndLine; line++ {
lineString := s.GetLine(line)
lineStringRunes := []rune(lineString)

var pad int
if line == span.StartLine {
pad = span.StartChar - 1
} else {
pad = 0
}

var length int
if line == span.EndLine {
length = span.EndChar - span.StartChar
} else {
length = len(lineStringRunes)
}

buf.WriteString(strings.Replace(strings.Replace(lineString, "%", "%%", -1), "\t", " ", -1))
buf.WriteRune('\n')

for i := 0; i < pad; i++ {
spaces := 1

if lineStringRunes[i] == ' ' {
spaces = 1
}

for t := 0; t < spaces; t++ {
buf.WriteRune(' ')
}
}

buf.WriteString("[DERP]")
for i := 0; i < length; i++ {
// there must be a less repetitive way to do this but oh well
spaces := 1

if lineStringRunes[i+pad] == ' ' {
spaces = 1
}

for t := 0; t < spaces; t++ {
buf.WriteRune('~')
}
}
//buf.WriteString(util.TEXT_RESET)
buf.WriteRune('\n')
}

return buf.String()
}
Loading