Skip to content

Commit 1bf9beb

Browse files
committed
First commit
0 parents  commit 1bf9beb

File tree

85 files changed

+8986
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+8986
-0
lines changed

.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
target/
2+
lib_managed/
3+
src_managed/
4+
project/boot/
5+
bin/
6+
.scala_dependencies
7+
core/target/
8+
core/lib_managed/
9+
core/src_managed/
10+
gui/target/
11+
gui/lib_managed/
12+
gui/src_managed/
13+
corpusscan/target/
14+
corpusscan/lib_managed/
15+
corpusscan/src_managed/
16+
eclipse/scalariform.eclipse/bin
17+
eclipse/scalariform.update/artifacts.jar
18+
eclipse/scalariform.update/content.jar
19+
eclipse/scalariform.update/features
20+
eclipse/scalariform.update/plugins
21+
eclipse/scalariform.update/logs.zip
22+
eclipse/scalariform.eclipse/lib/scalariform_2.8.0-SNAPSHOT-0.1.jar
23+
docs/build

LICENCE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License
2+
3+
Copyright (c) 2010 Matthew D. Russell
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and
10+
to permit persons to whom the Software is furnished to do so,
11+
subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
20+
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.rst

Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
Scalariform
2+
===========
3+
4+
Scalariform is a code formatter for Scala 2.8. It is a stand-alone
5+
library and an Eclipse plug-in. Currently, Scalariform supports only a
6+
limited set of options, although it is intended to be compatible with
7+
the recommendations of the `Scala Style Guide`_ (see below). Please
8+
let me know what other features people would like.
9+
10+
Scalariform is licenced under `The MIT Licence`_.
11+
12+
.. _Scala Style Guide: http://davetron5000.github.com/scala-style/
13+
.. _The MIT Licence: http://www.opensource.org/licenses/mit-license.php
14+
15+
Installation
16+
------------
17+
18+
In Eclipse Ganymede (3.5), install the latest nightly Scala Eclipse
19+
plugin using the Eclipse update site mechanism:
20+
21+
http://www.scala-lang.org/scala-eclipse-plugin-nightly
22+
23+
(See http://www.scala-lang.org/node/94 for more detailed instructions.)
24+
25+
Then install Scalariform from this update site:
26+
27+
http://scalariform.googlecode.com/svn/trunk/update-site/
28+
29+
To format:
30+
31+
- Right click in the editor -> Format Scala Source Code, or
32+
- Press Ctrl-Shift-D
33+
34+
To configure preferences, go to Window -> Preferences -> Scala -> Scala Formatter Preferences
35+
36+
Preferences
37+
-----------
38+
39+
alignParameters
40+
~~~~~~~~~~~~~~~
41+
42+
Default: ``false``
43+
44+
Align class/function parameters in the same column. For example, if ``false``, then::
45+
46+
class Person(name: String,
47+
age: Int,
48+
birthdate: Date,
49+
astrologicalSign: String,
50+
shoeSize: Int,
51+
favoriteColor: java.awt.Color)
52+
53+
If ``true``, then::
54+
55+
class Person(name: String,
56+
age: Int,
57+
birthdate: Date,
58+
astrologicalSign: String,
59+
shoeSize: Int,
60+
favoriteColor: java.awt.Color)
61+
62+
compactStringConcatenation
63+
~~~~~~~~~~~~~~~~~~~~~~~~~~
64+
65+
Default: ``false``
66+
67+
Omit spaces when formatting a '+' operator on String literals". For example, If ``false``, then::
68+
69+
"Hello " + name + "!"
70+
71+
If ``true``, then::
72+
73+
"Hello "+name+"!"
74+
75+
The Scala Style Guide recommends_ that operators, "should `always` be
76+
invoked using infix notation with spaces separated the target".
77+
78+
.. _recommends: http://davetron5000.github.com/scala-style/method_invocation/operators.html
79+
80+
doubleIndentClassDeclaration
81+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
82+
83+
Default: ``false``
84+
85+
With this set to ``true``, class (and trait / object) declarations
86+
will be formatted as recommended by the `Scala Style Guide`_. That is,
87+
if the declaration section spans multiple lines, it will be formatted
88+
so that either the parameter section or the inheritance section is
89+
doubly indented. This provides a visual distinction from the members
90+
of the class. For example::
91+
92+
class Person(
93+
name: String,
94+
age: Int,
95+
birthdate: Date,
96+
astrologicalSign: String,
97+
shoeSize: Int,
98+
favoriteColor: java.awt.Color)
99+
extends Entity
100+
with Logging
101+
with Identifiable
102+
with Serializable {
103+
def firstMethod = ...
104+
}
105+
106+
Or::
107+
108+
class Person(
109+
name: String,
110+
age: Int,
111+
birthdate: Date,
112+
astrologicalSign: String,
113+
shoeSize: Int,
114+
favoriteColor: java.awt.Color) {
115+
def firstMethod = ...
116+
}
117+
118+
indentSpaces
119+
~~~~~~~~~~~~
120+
121+
Default: ``2``
122+
123+
The number of spaces to use for each level of indentation.
124+
125+
preserveSpaceBeforeArguments
126+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
127+
128+
Default: ``false``
129+
130+
If ``true``, the formatter will keep an existing space before a parenthesis argument. For example::
131+
132+
stack.pop() should equal (2)
133+
134+
Otherwise, if ``false``, spaces before arguments will always be removed.
135+
136+
rewriteArrowSymbols
137+
~~~~~~~~~~~~~~~~~~~
138+
139+
Default: ``false``
140+
141+
Replace arrow tokens with their unicode equivalents: ``=>`` with ````, and ``<-`` with ````. For example::
142+
143+
for (n <- 1 to 10) n % 2 match {
144+
case 0 => println("even")
145+
case 1 => println("odd")
146+
}
147+
148+
is formatted as::
149+
150+
for (n ← 1 to 10) n % 2 match {
151+
case 0 ⇒ println("even")
152+
case 1 ⇒ println("odd")
153+
}
154+
155+
spaceBeforeColon
156+
~~~~~~~~~~~~~~~~
157+
158+
Default: ``false``
159+
160+
Whether to ensure a space before colon. For example, If ``false``, then::
161+
162+
def add(a: Int, b: Int): Int = a + b
163+
164+
If ``true``, then::
165+
166+
def add(a : Int, b : Int) : Int = a + b
167+
168+
Scala Style Guide
169+
~~~~~~~~~~~~~~~~~
170+
171+
Scalariform is "compatible" with the `Scala Style Guide`_ v1.1.0 in the
172+
sense that, given the right preference settings, source code that is
173+
initially compiliant with the Style Guide will not become uncompliant
174+
after formatting. In a number of cases, running the formatter will
175+
make uncompliant source more compliant.
176+
177+
============================ ========= =========
178+
Preference Value Default?
179+
============================ ========= =========
180+
alignParameters ``false``
181+
compactStringConcatenation ``false``
182+
doubleIndentClassDeclaration ``true`` No
183+
indentSpaces ``2``
184+
preserveSpaceBeforeArguments ``false``
185+
rewriteArrowSymbols ``false``
186+
spaceBeforeColon ``false``
187+
============================ ========= =========
188+
189+
Source directives
190+
-----------------
191+
192+
As well as global preferences, formatting can be tweaked at the source level through comments.
193+
194+
format: [ON|OFF]
195+
~~~~~~~~~~~~~~~~
196+
197+
Disables the formatter for selective portions of a source file::
198+
199+
// format: OFF <-- this directive disables formatting from this point
200+
class AsciiDSL {
201+
n ¦- "1" -+ { n: Node =>
202+
n ¦- "i"
203+
n ¦- "ii"
204+
n ¦- "iii"
205+
n ¦- "iv"
206+
n ¦- "v"
207+
}
208+
n ¦- "2"
209+
n ¦- "3" -+ { n: Node =>
210+
n ¦- "i"
211+
n ¦- "ii" -+ { n: Node =>
212+
n ¦- "a"
213+
n ¦- "b"
214+
n ¦- "c"
215+
}
216+
n ¦- "iii"
217+
n ¦- "iv"
218+
n ¦- "v"
219+
}
220+
// format: ON <-- formatter resumes from this point
221+
...
222+
}
223+
// (see: http://dev.day.com/microsling/content/blogs/main/scalajcr2.html)
224+
225+
format: [+|-]<preferenceName>
226+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
227+
228+
Sets a preference for the entire of the source file, overriding the global formatting settings::
229+
230+
// format: +preserveSpaceBeforeArguments
231+
class StackSpec extends FlatSpec with ShouldMatchers {
232+
// ...
233+
stack.pop() should equal (2)
234+
}

core/.classpath

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry including="**/*.scala" kind="src" path="src/main/scala"/>
4+
<classpathentry including="**/*.scala" kind="src" path="src/test/scala"/>
5+
<classpathentry kind="con" path="ch.epfl.lamp.sdt.launching.SCALA_CONTAINER"/>
6+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
7+
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
8+
<classpathentry kind="lib" path="lib_managed/scala_2.8.0.Beta1/compile/scalatest-1.0.1-for-scala-2.8.0.Beta1-with-test-interfaces-0.3-SNAPSHOT.jar"/>
9+
<classpathentry kind="output" path="bin"/>
10+
</classpath>

core/.project

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>scalariform</name>
4+
<comment>scalariform 0.1</comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>ch.epfl.lamp.sdt.core.scalabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.pde.ManifestBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.pde.SchemaBuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
</buildSpec>
24+
<natures>
25+
<nature>ch.epfl.lamp.sdt.core.scalanature</nature>
26+
<nature>org.eclipse.jdt.core.javanature</nature>
27+
<nature>org.eclipse.pde.PluginNature</nature>
28+
</natures>
29+
</projectDescription>

core/META-INF/MANIFEST.MF

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Manifest-Version: 1.0
2+
Bundle-ManifestVersion: 2
3+
Bundle-Name: Scalariform
4+
Bundle-SymbolicName: scalariform
5+
Bundle-Version: 0.0.1
6+
Require-Bundle:
7+
scala.library
8+
Bundle-ClassPath: .
9+
Export-Package: scalariform.formatter,
10+
scalariform.formatter.preferences,
11+
scalariform.lexer,
12+
scalariform.parser,
13+
scalariform.utils

core/build.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
bin.includes = META-INF/,\
2+
.
3+
source.. = src/main/scala/
4+
jars.compile.order = .
5+
output.. = bin/
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package scalariform.formatter
2+
3+
import scalariform.parser._
4+
import scalariform.utils._
5+
import scalariform.lexer._
6+
import scalariform.formatter.preferences._
7+
trait AnnotationFormatter {
8+
self: HasFormattingPreferences with TypeFormatter with ExprFormatter
9+
10+
def format(annotation: Annotation)(implicit formatterState: FormatterState): FormatResult = {
11+
val Annotation(atToken: Token, annotationType: Type, argumentExprss: List[ArgumentExprs], newlineOption: Option[Token]) = annotation
12+
var formatResult: FormatResult = NoFormatResult
13+
14+
formatResult ++= format(annotationType)
15+
for (argumentExprs argumentExprss)
16+
formatResult ++= format(argumentExprs)
17+
for (newline newlineOption)
18+
formatResult = formatResult.formatNewline(newline, Compact) // TODO: rethink
19+
formatResult
20+
}
21+
}
22+

0 commit comments

Comments
 (0)