Skip to content

Commit adb7683

Browse files
author
Matthias Wahl
committed
first cli stub
1 parent 0a140f0 commit adb7683

File tree

10 files changed

+388
-6
lines changed

10 files changed

+388
-6
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.deps/
2+
/build/

CODE_OF_CONDUCT.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6+
7+
## Our Standards
8+
9+
Examples of behavior that contributes to creating a positive environment include:
10+
11+
* Using welcoming and inclusive language
12+
* Being respectful of differing viewpoints and experiences
13+
* Gracefully accepting constructive criticism
14+
* Focusing on what is best for the community
15+
* Showing empathy towards other community members
16+
17+
Examples of unacceptable behavior by participants include:
18+
19+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
20+
* Trolling, insulting/derogatory comments, and personal or political attacks
21+
* Public or private harassment
22+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
23+
* Other conduct which could reasonably be considered inappropriate in a professional setting
24+
25+
## Our Responsibilities
26+
27+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28+
29+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30+
31+
## Scope
32+
33+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34+
35+
## Enforcement
36+
37+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project maintainers at {COC_EMAIL}. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38+
39+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40+
41+
## Attribution
42+
43+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44+
45+
[homepage]: http://contributor-covenant.org
46+
[version]: http://contributor-covenant.org/version/1/4/
47+
48+
# Social Rules
49+
50+
In addition to having a code of conduct as an anti-harassment policy, we have a small set of [social rules](https://www.recurse.com/manual#sub-sec-social-rules) we follow. We (the project maintainers) lifted these rules from the [Recurse Center](https://www.recurse.com). We've seen these rules in effect in other environments. We'd like the Pony community to share a similar positive environment. These rules are intended to be lightweight, and to make more explicit certain social norms that are normally implicit. Most of our social rules really boil down to “don't be a jerk” or “don't be annoying.” Of course, almost nobody sets out to be a jerk or annoying, so telling people not to be jerks isn't a very productive strategy.
51+
52+
Unlike the anti-harassment policy, violation of the social rules will not result in expulsion from the Pony community or a strong warning from project maintainers. Rather, they are designed to provide some lightweight social structure for community members to use when interacting with each other.
53+
54+
## No feigning surprise.
55+
56+
The first rule means you shouldn't act surprised when people say they don't know something. This applies to both technical things ("What?! I can't believe you don't know what the stack is!") and non-technical things ("You don't know who RMS is?!"). Feigning surprise has absolutely no social or educational benefit: When people feign surprise, it's usually to make them feel better about themselves and others feel worse. And even when that's not the intention, it's almost always the effect.
57+
58+
## No well-actually's
59+
60+
A well-actually happens when someone says something that's almost - but not entirely - correct, and you say, "well, actually…" and then give a minor correction. This is especially annoying when the correction has no bearing on the actual conversation. This doesn't mean we aren't about truth-seeking or that we don't care about being precise. Almost all well-actually's in our experience are about grandstanding, not truth-seeking.
61+
62+
## No subtle -isms
63+
64+
Our last social rule bans subtle racism, sexism, homophobia, transphobia, and other kinds of bias. This one is different from the rest, because it covers a class of behaviors instead of one very specific pattern.
65+
66+
Subtle -isms are small things that make others feel uncomfortable, things that we all sometimes do by mistake. For example, saying "It's so easy my grandmother could do it" is a subtle -ism. Like the other three social rules, this one is often accidentally broken. Like the other three, it's not a big deal to mess up – you just apologize and move on.
67+
68+
If you see a subtle -ism in the Pony community, you can point it out to the relevant person, either publicly or privately, or you can ask one of the project maintainers to say something. After this, we ask that all further discussion move off of public channels. If you are a third party, and you don't see what could be biased about the comment that was made, feel free to talk to the project maintainers. Please don't say, "Comment X wasn't homophobic!" Similarly, please don't pile on to someone who made a mistake. The "subtle" in "subtle -isms" means that it's probably not obvious to everyone right away what was wrong with the comment.
69+
70+
If you have any questions about any part of the code of conduct or social rules, please feel free to reach out to any of the project maintainers.

CONTRIBUTING.md

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Contributing
2+
3+
You want to contribute to ponyfmt? Awesome.
4+
5+
There are a number of ways to contribute. As this document is a little long, feel free to jump to the section that applies to you currently:
6+
7+
* [Bug report](#bug-report)
8+
* [How to contribute](#how-to-contribute)
9+
* [Pull request](#pull-request)
10+
11+
Additional notes regarding formatting:
12+
13+
* [Documentation formatting](#documentation-formatting)
14+
* [Code formatting](#code-formatting)
15+
* [File Naming](#standard-library-file-naming)
16+
17+
## Bug report
18+
19+
First of all please [search existing issues](https://github.com/mfelsche/ponyfmt/issues) to make sure your issue hasn't already been reported. If you cannot find a suitable issue — [create a new one](https://github.com/mfelsche/ponyfmt/issues/new).
20+
21+
Provide the following details:
22+
23+
- short summary of what you were trying to achieve,
24+
- a code snippet causing the bug,
25+
- expected result,
26+
- actual results and
27+
- environment details: at least operating system version
28+
29+
If possible, try to isolate the problem and provide just enough code to demonstrate it. Add any related information which might help to fix the issue.
30+
31+
## How to Contribute
32+
33+
This project uses a fairly standard GitHub pull request workflow. If you have already contributed to a project via GitHub pull request, you can skip this section and proceed to the [specific details of what we ask for in a pull request](#pull-request). If this is your first time contributing to a project via GitHub, read on.
34+
35+
Here is the basic GitHub workflow:
36+
37+
1. Fork this repo. you can do this via the GitHub website. This will result in you having your own copy of the repo under your GitHub account.
38+
2. Clone your forked repo to your local machine
39+
3. Make a branch for your change
40+
4. Make your change on that branch
41+
5. Push your change to your repo
42+
6. Use the github ui to open a PR
43+
44+
Some things to note that aren't immediately obvious to folks just starting out:
45+
46+
1. Your fork doesn't automatically stay up to date with changes in the main repo.
47+
2. Any changes you make on your branch that you used for one PR will automatically appear in another PR so if you have more than 1 PR, be sure to always create different branches for them.
48+
3. Weird things happen with commit history if you don't create your PR branches off of `master` so always make sure you have the `master` branch checked out before creating a branch for a PR
49+
50+
If you feel overwhelmed at any point, don't worry, it can be a lot to learn when you get started. You can usually find me on the [Pony IRC](https://webchat.freenode.net/?channels=%ponylang) if you need help.
51+
52+
You can get help using GitHub via [the official documentation](https://help.github.com/). Some hightlights include:
53+
54+
- [Fork A Repo](https://help.github.com/articles/fork-a-repo/)
55+
- [Creating a pull request](https://help.github.com/articles/creating-a-pull-request/)
56+
- [Syncing a fork](https://help.github.com/articles/syncing-a-fork/)
57+
58+
## Pull request
59+
60+
Before issuing a pull request we ask that you squash all your commits into a single logical commit. While your PR is in review, we may ask for additional changes, please do not squash those commits while the review is underway. Once everything is good, I'll then ask you to further squash those commits before merging. We ask that you not squash while a review is underway as it can make it hard to follow what is going on. Additionally, we ask that you:
61+
62+
* [Write a good commit message](http://chris.beams.io/posts/git-commit/)
63+
* Issue 1 Pull Request per feature. Don't lump unrelated changes together.
64+
65+
If you aren't sure how to squash multiple commits into one, Steve Klabnik wrote [a handy guide](http://blog.steveklabnik.com/posts/2012-11-08-how-to-squash-commits-in-a-github-pull-request) that you can refer to.
66+
67+
Once those conditions are met, the PR can be merged.
68+
69+
Please note, if your changes are purely to things like README, CHANGELOG etc, you can add [skip ci] as the last line of your commit message and your PR won't be run through our continuous integration systems. We ask that you use [skip ci] where appropriate as it helps to get changes through CI faster and doesn't waste resources that TravisCI is kindly donating to the Open Source community.
70+
71+
## Documentation formatting
72+
73+
When contributing to documentation, try to keep the following style guidelines in mind:
74+
75+
As much as possible all documentation should be textual and in Markdown format. Diagrams are often needed to clarify a point. For any images, an original high-resolution source should be provided as well so updates can be made.
76+
77+
Documentation is not "source code." As such, it should not be wrapped at 80 columns. Documentation should be allowed to flow naturally until the end of a paragraph. It is expected that the reader will turn on soft wrapping as needed.
78+
79+
All code examples in documentation should be formatted in a fashion appropriate to the language in question.
80+
81+
All command line examples in documentation should be presented in a copy and paste friendly fashion. Assume the user is using the `bash` shell. GitHub formatting on long command lines can be unfriendly to copy-and-paste. Long command lines should be broken up using `\` so that each line is no more than 80 columns. Wrapping at 80 columns should result in a good display experience in GitHub. Additionally, continuation lines should be indented two spaces.
82+
83+
OK:
84+
85+
```bash
86+
my_command --some-option foo --path-to-file ../../wallaroo/long/line/foo \
87+
--some-other-option bar
88+
```
89+
90+
Not OK:
91+
92+
```bash
93+
my_command --some-option foo --path-to-file ../../wallaroo/long/line/foo --some-other-option bar
94+
```
95+
96+
Wherever possible when writing documentation, favor full command options rather than short versions. Full flags are usually much easier to modify because the meaning is clearer.
97+
98+
OK:
99+
100+
```bash
101+
my_command --messages 100
102+
```
103+
104+
Not OK:
105+
106+
```bash
107+
my_command -m 100
108+
```
109+
110+
## Code formatting
111+
112+
The basics:
113+
114+
* Indentation
115+
116+
Indent using spaces, not tabs. Indentation is language specific.
117+
118+
* Watch your whitespace!
119+
120+
Use an editor plugin to remove unused trailing whitespace including both at the end of a line and at the end of a file. By the same token, remember to leave a single newline only line at the end of each file. It makes output files to the console much more pleasant.
121+
122+
* Line Length
123+
124+
We all have different sized monitors. What might look good on yours might look like awful on another. Be kind and wrap all lines at 80 columns unless you have a good reason not to.
125+
126+
* Reformatting code to meet standards
127+
128+
Try to avoid doing it. A commit that changes the formatting for large chunks of a file makes for an ugly commit history when looking for changes. Don't commit code that doesn't conform to coding standards in the first place. If you do reformat code, make sure it is either standalone reformatting with no logic changes or confined solely to code whose logic you touched. For example, updating the indentation in a file? Do not make logic changes along with it. Editing a line that has extra whitespace at the end? Feel free to remove it.
129+
130+
The details:
131+
132+
All Pony sources should follow the [Pony standard library style guide](https://github.com/ponylang/ponyc/blob/master/STYLE_GUIDE.md).
133+
134+
## File naming
135+
136+
Pony code follows the [Pony standard library file naming guidelines](https://github.com/ponylang/ponyc/blob/master/STYLE_GUIDE.md#naming).

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
build/ponyfmt: build ponyfmt/*.pony
3+
stable env ponyc ponyfmt -o build --debug
4+
5+
build:
6+
mkdir build
7+
8+
test: build/ponyfmt
9+
build/ponyfmt
10+
11+
clean:
12+
rm -rf build
13+
14+
.PHONY: clean test

README.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
# ponyfmt
2-
autoformatting for pony code
32

4-
## Current Status
3+
Source Code Formatter for the ponylang programming language
54

6-
This repository is pure vaporware.
5+
## Status
76

8-
Its sole purpose is a future repository for the actual ponyfmt code
9-
and, most importantly a place for discussion about the idea, approach and implementation
10-
of a ponylang autoformatter.
7+
[![Build Status](https://travis-ci.org/mfelsche/ponyfmt.svg?branch=master)](https://travis-ci.org/mfelsche/ponyfmt)
8+
9+
This project is still in pre-alpha state and might damage your sources.
10+
11+
## Installation
12+
13+
* Install [pony-stable](https://github.com/ponylang/pony-stable)
14+
* Update your `bundle.json`
15+
16+
```json
17+
{
18+
"type": "github",
19+
"repo": "mfelsche/ponyfmt"
20+
}
21+
```
22+
23+
* `stable fetch` to fetch your dependencies
24+
* `use "ponyfmt"` to include this package
25+
* `stable env ponyc` to compile your application

STYLE_GUIDE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Style Guide
2+
3+
ponyfmt follows the [Pony standard library Style Guide](https://github.com/ponylang/ponyc/blob/master/STYLE_GUIDE.md).

bundle.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"deps": [
3+
{
4+
"type": "github",
5+
"repo": "jemc/ponycc"
6+
}
7+
]
8+
}

ponyfmt/formatter.pony

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
class val FormatterConfig
3+
4+
actor Formatter
5+
let config: FormatterConfig
6+
7+
new create(config': FormatterConfig) =>
8+
config = config'

ponyfmt/main.pony

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
use "ponycc/ast"
2+
use "cli"
3+
use "files"
4+
use "ponycc/ast/print"
5+
6+
actor Main
7+
let env: Env
8+
9+
new create(env': Env) =>
10+
env = env'
11+
let commandSpec =
12+
try
13+
CommandSpec.leaf(
14+
"ponyfmt",
15+
"A Pony Code Formatter",
16+
[
17+
OptionSpec.string("output", "Output directory", 'o', ".")],
18+
[
19+
ArgSpec.string_seq("modules", "The pony modules to format")
20+
])? .> add_help()?
21+
else
22+
env'.err.print("Invalid CommandSpec")
23+
env'.exitcode(1)
24+
return
25+
end
26+
let cmd =
27+
match CommandParser(commandSpec).parse(env.args, env.vars())
28+
| let c: Command => c
29+
| let ch: CommandHelp =>
30+
ch.print_help(env.out)
31+
env'.exitcode(0)
32+
return
33+
| let se: SyntaxError =>
34+
env'.err.print(se.string())
35+
env'.exitcode(1)
36+
return
37+
end
38+
39+
let modules = cmd.arg("modules").string_seq()
40+
for modulePath in modules.values() do
41+
formatModule(modulePath)
42+
end
43+
44+
fun box reportErrors(errs: Array[(String, SourcePosAny)]) =>
45+
"""
46+
"""
47+
48+
fun formatModule(modulePath: String) =>
49+
let moduleSource: Source =
50+
try
51+
loadModule(modulePath)?
52+
else
53+
env.err.print("unable to load module @ " + modulePath)
54+
return
55+
end
56+
ModuleParser.parseModule(
57+
moduleSource,
58+
{(errs: Array[(String, SourcePosAny)] box) =>
59+
env.err.print(modulePath)
60+
for err in errs.values() do
61+
(let line, let arrow) = err._2.show_in_line()
62+
env.err
63+
.>print(" ERROR:")
64+
.>print(" " + err._1)
65+
.>print(" " + line)
66+
.>print(" " + arrow)
67+
.>print("")
68+
end
69+
} val,
70+
{(module: Module) =>
71+
// TODO: use Formatter
72+
env.out
73+
.>print(modulePath)
74+
.>print(Print(module))
75+
} val)
76+
77+
78+
79+
fun loadModule(path: String): Source ? =>
80+
let filePath = FilePath(env.root as AmbientAuth, path)?
81+
match OpenFile(filePath)
82+
| let file: File =>
83+
Source(file.read_string(file.size()), path)
84+
else
85+
error
86+
end

0 commit comments

Comments
 (0)