Skip to content
This repository
Browse code

Switched to JavaCC parser for HLint output and finish it.

  • Loading branch information...
commit 43b0869512c2f6c01a97f5aa808b9e815c9a6457 1 parent 882b21e
Alejandro Serrano authored June 27, 2011
3  net.sf.eclipsefp.haskell.core/META-INF/MANIFEST.MF
@@ -11,7 +11,8 @@ Require-Bundle: org.eclipse.core.expressions;bundle-version="[3.2.0,4.0.0)",
11 11
  org.eclipse.ui;bundle-version="3.5.0",
12 12
  net.sf.eclipsefp.haskell.scion.client,
13 13
  org.eclipse.text;bundle-version="3.5.0",
14  
- net.sf.eclipsefp.haskell.util;bundle-version="1.0.0"
  14
+ net.sf.eclipsefp.haskell.util;bundle-version="1.0.0",
  15
+ net.sf.eclipsefp.haskell.hlint;bundle-version="0.0.1"
15 16
 Bundle-ActivationPolicy: lazy
16 17
 Bundle-ManifestVersion: 2
17 18
 Bundle-RequiredExecutionEnvironment: J2SE-1.5
1  net.sf.eclipsefp.haskell.core/src/net/sf/eclipsefp/haskell/core/hlint/HLintBuilder.java
@@ -17,6 +17,7 @@ public HLintBuilder() {
17 17
 	@Override
18 18
 	protected IProject[] build(final int kind, final Map<String, String> args, final IProgressMonitor monitor)
19 19
 			throws CoreException {
  20
+	  // Complete code here
20 21
 		return null;
21 22
 	}
22 23
 
1  net.sf.eclipsefp.haskell.hlint/.classpath
... ...
@@ -1,6 +1,5 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 2
 <classpath>
3  
-	<classpathentry exported="true" kind="lib" path="lib/jparsec-2.0.jar"/>
4 3
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
5 4
 	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
6 5
 	<classpathentry kind="src" path="src"/>
8  net.sf.eclipsefp.haskell.hlint/.project
... ...
@@ -1,11 +1,16 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 2
 <projectDescription>
3 3
 	<name>net.sf.eclipsefp.haskell.hlint</name>
4  
-	<comment></comment>
  4
+	<comment>JavaCC Nature</comment>
5 5
 	<projects>
6 6
 	</projects>
7 7
 	<buildSpec>
8 8
 		<buildCommand>
  9
+			<name>sf.eclipse.javacc.javaccbuilder</name>
  10
+			<arguments>
  11
+			</arguments>
  12
+		</buildCommand>
  13
+		<buildCommand>
9 14
 			<name>org.eclipse.jdt.core.javabuilder</name>
10 15
 			<arguments>
11 16
 			</arguments>
@@ -24,5 +29,6 @@
24 29
 	<natures>
25 30
 		<nature>org.eclipse.pde.PluginNature</nature>
26 31
 		<nature>org.eclipse.jdt.core.javanature</nature>
  32
+		<nature>sf.eclipse.javacc.javaccnature</nature>
27 33
 	</natures>
28 34
 </projectDescription>
8  net.sf.eclipsefp.haskell.hlint/META-INF/MANIFEST.MF
@@ -5,10 +5,10 @@ Bundle-SymbolicName: net.sf.eclipsefp.haskell.hlint;singleton:=true
5 5
 Bundle-Version: 0.0.1
6 6
 Bundle-Activator: net.sf.eclipsefp.haskell.hlint.HLintPlugin
7 7
 Require-Bundle: org.eclipse.ui;bundle-version="[3.2.0,4.0.0)",
8  
- org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
9  
- net.sf.eclipsefp.haskell.core;bundle-version="2.0.5"
  8
+ org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)"
10 9
 Eclipse-LazyStart: true
11 10
 Bundle-RequiredExecutionEnvironment: J2SE-1.5
12 11
 Bundle-Vendor: %bundleVendor
13  
-Bundle-ClassPath: lib/jparsec-2.0.jar,
14  
- .
  12
+Bundle-ClassPath: .
  13
+Export-Package: net.sf.eclipsefp.haskell.hlint,
  14
+ net.sf.eclipsefp.haskell.hlint.parser
3  net.sf.eclipsefp.haskell.hlint/build.properties
... ...
@@ -1,6 +1,5 @@
1 1
 source.. = src/
2 2
 output.. = bin/
3 3
 bin.includes = META-INF/,\
4  
-               .,\
5  
-               lib/jparsec-2.0.jar
  4
+               .
6 5
 
BIN  net.sf.eclipsefp.haskell.hlint/lib/jparsec-2.0.jar
Binary file not shown
46  net.sf.eclipsefp.haskell.hlint/src/net/sf/eclipsefp/haskell/hlint/OutputParser.java
... ...
@@ -1,46 +0,0 @@
1  
-package net.sf.eclipsefp.haskell.hlint;
2  
-
3  
-import java.util.List;
4  
-
5  
-import org.codehaus.jparsec.Parser;
6  
-import org.codehaus.jparsec.Parsers;
7  
-import org.codehaus.jparsec.Scanners;
8  
-import org.codehaus.jparsec.Terminals;
9  
-import org.codehaus.jparsec.functors.Map;
10  
-
11  
-public class OutputParser {
12  
-
13  
-	static final Parser<Integer> NUMBER = Terminals.IntegerLiteral.PARSER
14  
-			.map(new Map<String, Integer>() {
15  
-				public Integer map(String s) {
16  
-					return Integer.valueOf(s);
17  
-				}
18  
-			});
19  
-
20  
-	static final Parser<?> COLON = Scanners.isChar(':');
21  
-	static final Parser<Character> NOT_COLON = notChar(':');
22  
-	
23  
-	static final Parser<?> EOL = Scanners.isChar('\n');
24  
-	static final Parser<Character> NOT_EOL = notChar('\n');
25  
-
26  
-	public static Parser<Character> notChar(char c) {
27  
-		return Terminals.CharLiteral.PARSER.next(new Map<Character, Parser<Character>>() {
28  
-			public Parser<Character> map(Character c) {
29  
-				return c == ':' ? Parsers.<Character> unexpected(":") : Parsers.constant(c);
30  
-			}
31  
-		});
32  
-	}
33  
-	
34  
-	public static Parser<String> upTo(char c) {
35  
-		return notChar(c).many().map(new Map<List<Character>, String>() {
36  
-			public String map(List<Character> chars) {
37  
-				StringBuilder builder = new StringBuilder();
38  
-				for (char c : chars)
39  
-					builder.append(c);
40  
-				return builder.toString();
41  
-			}
42  
-		});
43  
-	}
44  
-	
45  
-	
46  
-}
18  net.sf.eclipsefp.haskell.hlint/src/net/sf/eclipsefp/haskell/hlint/Suggestion.java
@@ -4,7 +4,7 @@
4 4
 	private SourceLocation location;
5 5
 	private Severity severity;
6 6
 	private String message;
7  
-	private CodeModification prev;
  7
+	private CodeModification pre;
8 8
 	private CodeModification post;
9 9
 	
10 10
 	public SourceLocation getLocation() {
@@ -19,31 +19,31 @@ public String getMessage() {
19 19
 		return message;
20 20
 	}
21 21
 	
22  
-	public CodeModification getPrev() {
23  
-		return prev;
  22
+	public CodeModification getPre() {
  23
+		return pre;
24 24
 	}
25 25
 	
26 26
 	public CodeModification getPost() {
27 27
 		return post;
28 28
 	}
29 29
 
30  
-	void setLocation(SourceLocation location) {
  30
+	public void setLocation(SourceLocation location) {
31 31
 		this.location = location;
32 32
 	}
33 33
 
34  
-	void setSeverity(Severity severity) {
  34
+	public void setSeverity(Severity severity) {
35 35
 		this.severity = severity;
36 36
 	}
37 37
 
38  
-	void setMessage(String message) {
  38
+	public void setMessage(String message) {
39 39
 		this.message = message;
40 40
 	}
41 41
 
42  
-	void setPrev(CodeModification prev) {
43  
-		this.prev = prev;
  42
+	public void setPre(CodeModification pre) {
  43
+		this.pre = pre;
44 44
 	}
45 45
 
46  
-	void setPost(CodeModification post) {
  46
+	public void setPost(CodeModification post) {
47 47
 		this.post = post;
48 48
 	}
49 49
 }
181  net.sf.eclipsefp.haskell.hlint/src/net/sf/eclipsefp/haskell/hlint/parser/OutputParser.jj
... ...
@@ -0,0 +1,181 @@
  1
+/**
  2
+ * JavaCC template file created by SF JavaCC plugin 1.5.17+ wizard for JavaCC 1.5.0+
  3
+ */
options
{
  JDK_VERSION = "1.5";
  4
+  LOOKAHEAD = 100;
  5
+  FORCE_LA_CHECK = true;
  static = false;
}

PARSER_BEGIN(OutputParser)
package net.sf.eclipsefp.haskell.hlint.parser;
  6
+
  7
+import java.util.*;
  8
+import net.sf.eclipsefp.haskell.hlint.*;
  9
+
  10
+public class OutputParser
{
  
}

PARSER_END(OutputParser)

  11
+TOKEN :
  12
+{
  < SPACE : " " >
  13
+| < EOL : "\n" | "\r" | "\r\n" >
  14
+| < COLON : ":" >
  15
+| < OTHER_CHAR : ~[ "\n", "\r", ":" ] >
  16
+}
  17
+
  18
+List<Suggestion> suggestions() :
  19
+{
  20
+  ArrayList<Suggestion > sugs;
  21
+  Suggestion sug;
}
  22
+{
  string_until_eol()
  23
+  < EOF >
  24
+  {
    return new ArrayList<Suggestion>();
  25
+  }
  26
+| sug = suggestion()
  27
+  {
    sugs = new ArrayList<Suggestion>();
  28
+    sugs.add(sug);
  29
+  }
  30
+  (
    sug = suggestion()
  31
+    {
      sugs.add(sug);
  32
+    }
  33
+  )*
  34
+  string_until_eol()
  35
+  < EOF >
  36
+  {
    return sugs;
  37
+  }
  38
+}

Suggestion suggestion() :
{
  39
+  StringBuilder filename;
  40
+  Integer line;
  41
+  Integer column;
  42
+  Severity sev;
  43
+  StringBuilder message;
  44
+  CodeModification pre;
  45
+  CodeModification post;
  46
+}
{
  filename = string_until_colon()
  47
+  line = number()
  48
+  column = number()
  49
+  < SPACE >
  50
+  sev = severity()
  51
+  < SPACE >
  52
+  message = string_until_eol()
  53
+  pre = code_mod()
  54
+  post = code_mod()
  55
+  < EOL >
  {
    Suggestion s = new Suggestion();
  56
+    s.setLocation(new SourceLocation(filename.toString(), line, column));
  57
+    s.setSeverity(sev);
  58
+    s.setMessage(message.toString());
  59
+    s.setPre(pre);
  60
+    s.setPost(post);
  61
+    return s;
  }
}
  62
+
  63
+StringBuilder string_until_colon() :
  64
+{
  Token c;
  65
+  StringBuilder s;
  66
+}
  67
+{
  68
+  c = < OTHER_CHAR >
  s = string_until_colon()
  69
+  {
    s.insert(0, c.image);
  70
+    return s;
  71
+  }
  72
+| c = < SPACE >
  73
+  s = string_until_colon()
  74
+  {
  75
+    s.insert(0, c.image);
  76
+    return s;
  77
+  }
  78
+| < COLON >
  79
+  {
    return new StringBuilder();
  80
+  }
  81
+}
  82
+
  83
+StringBuilder string_until_eol() :
  84
+{
  85
+  Token c;
  86
+  StringBuilder s;
  87
+}
  88
+{
  89
+  c = < OTHER_CHAR >
  90
+  s = string_until_eol()
  91
+  {
  92
+    s.insert(0, c.image);
  93
+    return s;
  94
+  }
  95
+| c = < SPACE >
  96
+  s = string_until_eol()
  97
+  {
  98
+    s.insert(0, c.image);
  99
+    return s;
  100
+  }
  101
+| c = < COLON >
  102
+  s = string_until_eol()
  103
+  {
  104
+    s.insert(0, c.image);
  105
+    return s;
  106
+  }
  107
+| < EOL >
  108
+  {
  109
+    return new StringBuilder();
  110
+  }
  111
+}
  112
+
  113
+Integer number() :
  114
+{
  115
+  StringBuilder sb;
  116
+}
  117
+{
  118
+  sb = string_until_colon()
  119
+  {
  120
+    return Integer.valueOf(sb.toString());
  121
+  }
  122
+}
  123
+
  124
+Severity severity() :
  125
+{
  126
+  StringBuilder sb;
  127
+}
{
  128
+  sb = string_until_colon()
  129
+  {
  130
+    String s = sb.toString();
    if (s.equals("Ignore"))
  131
+      return Severity.IGNORE;
  132
+    else if (s.equals("Warning"))
  133
+      return Severity.WARNING;
  134
+    else if (s.equals("Error"))
  135
+      return Severity.ERROR;
  136
+    else
  137
+      return null;
  138
+  }
  139
+}
  140
+
  141
+CodeModification code_mod() :
  142
+{
  143
+  StringBuilder s;
}
  144
+{
  145
+  string_until_eol() // Get the message
  146
+  {
  147
+    s = null;
  148
+  }
  149
+  (
     s = source_code()
  150
+  )?
  151
+  {
  152
+    if (s != null)
  153
+      return new CodeModificationText(s.toString());
  154
+    else
  155
+      return new CodeModificationRemove();
  156
+  }
  157
+}
  158
+
  159
+StringBuilder source_code_line() :
  160
+{
  161
+  StringBuilder line;
}
  162
+{
  < SPACE >
  163
+  < SPACE >
  164
+  line = string_until_eol()
  165
+  {
    return line;
  166
+  }
  167
+}
  168
+
  169
+StringBuilder source_code() :
  170
+{
  StringBuilder line;
  171
+  StringBuilder all;
  172
+}
  173
+{
  all = source_code_line()
  174
+  (
    line = source_code_line()
  175
+    {
  176
+      all.append('\n');
      all.append(line.toString());
  177
+    }
  178
+  )*
  179
+  {
    return all;
  180
+  } 
  181
+}

0 notes on commit 43b0869

Please sign in to comment.
Something went wrong with that request. Please try again.