Skip to content

Commit 487fe9b

Browse files
committed
Add docs for File_Options and Strict_Mode.
Support file options docgen syntax highlighter. Also, added support for using class based styling, instead of style based styling. In the future, I will create a css class to do the styling, but for now, it remains hardcoded.
1 parent 5307cf3 commit 487fe9b

File tree

7 files changed

+457
-152
lines changed

7 files changed

+457
-152
lines changed

src/main/java/com/laytonsmith/core/compiler/FileOptions.java

Lines changed: 66 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -10,81 +10,85 @@
1010
*/
1111
public class FileOptions {
1212

13-
private boolean strict;
14-
private List<String> supressWarnings;
15-
private String name;
16-
private String author;
17-
private String created;
18-
private String description;
19-
//TODO: Make this non-public once this is all finished.
20-
public FileOptions(Map<String, String> parsedOptions) {
21-
strict = parseBoolean(getDefault(parsedOptions, "strict", "false"));
22-
supressWarnings = parseList(getDefault(parsedOptions, "supresswarnings", ""));
23-
name = getDefault(parsedOptions, "name", "");
24-
author = getDefault(parsedOptions, "author", "");
25-
created = getDefault(parsedOptions, "created", "");
26-
description = getDefault(parsedOptions, "description", null);
27-
}
13+
/*
14+
These values are used in the syntax highlighter, and should remain the name they are in code.
15+
*/
16+
private final boolean strict;
17+
private final List<String> suppressWarnings;
18+
private final String name;
19+
private final String author;
20+
private final String created;
21+
private final String description;
22+
//TODO: Make this non-public once this is all finished.
2823

29-
private String getDefault(Map<String, String> map, String key, String defaultIfNone){
30-
if(map.containsKey(key)){
31-
return map.get(key);
32-
} else {
33-
return defaultIfNone;
34-
}
35-
}
24+
public FileOptions(Map<String, String> parsedOptions) {
25+
strict = parseBoolean(getDefault(parsedOptions, "strict", "false"));
26+
suppressWarnings = parseList(getDefault(parsedOptions, "suppresswarnings", ""));
27+
name = getDefault(parsedOptions, "name", "");
28+
author = getDefault(parsedOptions, "author", "");
29+
created = getDefault(parsedOptions, "created", "");
30+
description = getDefault(parsedOptions, "description", null);
31+
}
3632

37-
private boolean parseBoolean(String bool){
38-
if(bool.equalsIgnoreCase("false") || bool.equalsIgnoreCase("off")){
39-
return false;
40-
} else {
41-
return true;
42-
}
33+
private String getDefault(Map<String, String> map, String key, String defaultIfNone) {
34+
if (map.containsKey(key)) {
35+
return map.get(key);
36+
} else {
37+
return defaultIfNone;
4338
}
39+
}
4440

45-
private List<String> parseList(String list){
46-
List<String> l = new ArrayList<String>();
47-
for(String part : list.split(",")){
48-
if(!part.trim().isEmpty()){
49-
l.add(part.trim().toLowerCase());
50-
}
51-
}
52-
return l;
41+
private boolean parseBoolean(String bool) {
42+
if (bool.equalsIgnoreCase("false") || bool.equalsIgnoreCase("off")) {
43+
return false;
44+
} else {
45+
return true;
5346
}
47+
}
5448

55-
public boolean isStrict(){
56-
return strict;
49+
private List<String> parseList(String list) {
50+
List<String> l = new ArrayList<String>();
51+
for (String part : list.split(",")) {
52+
if (!part.trim().isEmpty()) {
53+
l.add(part.trim().toLowerCase());
54+
}
5755
}
56+
return l;
57+
}
5858

59-
public boolean isWarningSupressed(String warning){
60-
return warning.trim().contains(warning.toLowerCase());
61-
}
59+
public boolean isStrict() {
60+
return strict;
61+
}
6262

63-
public String getName() {
64-
return name;
65-
}
63+
public boolean isWarningSuppressed(String warning) {
64+
return warning.trim().contains(warning.toLowerCase());
65+
}
6666

67-
public String getAuthor() {
68-
return author;
69-
}
67+
public String getName() {
68+
return name;
69+
}
7070

71-
public String getCreated() {
72-
return created;
73-
}
71+
public String getAuthor() {
72+
return author;
73+
}
7474

75-
public String getDescription(){
76-
return description;
77-
}
75+
public String getCreated() {
76+
return created;
77+
}
7878

79-
@Override
80-
public String toString() {
81-
return (strict ? "Strict Mode on" : "") + "\n" +
82-
(supressWarnings.isEmpty() ? "" : "Suppressed Warnings: " + supressWarnings.toString() + "\n") +
83-
(name.isEmpty() ? "" : "File name: " + name + "\n") +
84-
(author.isEmpty() ? "" : "Author: " + author + "\n") +
85-
(created.isEmpty() ? "" : "Creation Date: " + created + "\n") +
86-
(description == null ? "" : "File description: " + description + "\n");
79+
public String getDescription() {
80+
return description;
81+
}
8782

88-
}
83+
@Override
84+
public String toString() {
85+
return (strict ? "Strict Mode on" : "") + "\n"
86+
+ (suppressWarnings.isEmpty() ? "" : "Suppressed Warnings: " + suppressWarnings.toString() + "\n")
87+
+ (name.isEmpty() ? "" : "File name: " + name + "\n")
88+
+ (author.isEmpty() ? "" : "Author: " + author + "\n")
89+
+ (created.isEmpty() ? "" : "Creation Date: " + created + "\n")
90+
+ (description == null ? "" : "File description: " + description + "\n");
91+
92+
}
8993

9094
}
Lines changed: 85 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
package com.laytonsmith.core.compiler;
32

43
import com.laytonsmith.core.constructs.Token;
@@ -9,89 +8,101 @@
98

109
/**
1110
*
12-
*
11+
*
1312
*/
1413
public class TokenStream extends LinkedList<Token> {
15-
private FileOptions fileOptions;
1614

17-
public TokenStream() {
18-
super();
19-
this.fileOptions = null;
20-
}
15+
private FileOptions fileOptions;
16+
private String rawFileOptions;
2117

22-
public TokenStream(List<Token> list, FileOptions options) {
23-
super(list);
24-
this.fileOptions = options;
25-
}
18+
public TokenStream() {
19+
super();
20+
this.fileOptions = null;
21+
}
2622

27-
public TokenStream(List<Token> list, String fileOptions) {
28-
super(list);
29-
this.fileOptions = parseFileOptions(fileOptions);
30-
}
23+
public TokenStream(List<Token> list, FileOptions options) {
24+
super(list);
25+
this.fileOptions = options;
26+
}
3127

32-
public void setFileOptions(String fileOptions) {
33-
this.fileOptions = parseFileOptions(fileOptions);
34-
}
28+
public TokenStream(List<Token> list, String fileOptions) {
29+
super(list);
30+
this.fileOptions = parseFileOptions(fileOptions);
31+
}
3532

36-
public void setFileOptions(FileOptions fileOptions) {
37-
this.fileOptions = fileOptions;
38-
}
33+
public void setFileOptions(String fileOptions) {
34+
this.rawFileOptions = fileOptions;
35+
this.fileOptions = parseFileOptions(fileOptions);
36+
}
3937

40-
public FileOptions getFileOptions() {
41-
return this.fileOptions;
42-
}
38+
public void setFileOptions(FileOptions fileOptions) {
39+
this.fileOptions = fileOptions;
40+
}
41+
42+
public FileOptions getFileOptions() {
43+
return this.fileOptions;
44+
}
45+
46+
/**
47+
* Returns the file options as they were originally passed in. This should only be used in special cases (syntax
48+
* highlighters, etc)
49+
* @return
50+
*/
51+
public String getRawFileOptions() {
52+
return rawFileOptions;
53+
}
4354

44-
private static FileOptions parseFileOptions(String options) {
45-
//Only ; needs escaping. Everything else is just trimmed, and added to the map.
46-
Map<String, String> map = new HashMap<String, String>();
47-
boolean inKey = true;
48-
StringBuilder buffer = new StringBuilder();
49-
String keyName = "";
50-
for (int i = 0; i < options.length(); i++) {
51-
Character c = options.charAt(i);
52-
Character c2 = null;
53-
if (i < options.length() - 1) {
54-
c2 = options.charAt(i + 1);
55-
}
56-
if (inKey) {
57-
if (c == ':') {
58-
keyName = buffer.toString();
59-
buffer = new StringBuilder();
60-
inKey = false;
61-
} else if (c == ';') {
62-
//Self closed
63-
map.put(buffer.toString().trim().toLowerCase(), "true");
64-
buffer = new StringBuilder();
65-
keyName = "";
66-
//We don't reset the inKey parameter
67-
} else {
68-
buffer.append(c);
69-
}
70-
} else {
71-
if (c == '\\' && c2 == ';') {
72-
buffer.append(';');
73-
i++;
74-
} else if (c == ';') {
75-
//We're done
76-
inKey = true;
77-
map.put(keyName.trim().toLowerCase(), buffer.toString());
78-
buffer = new StringBuilder();
79-
} else {
80-
buffer.append(c);
81-
}
82-
}
55+
private static FileOptions parseFileOptions(String options) {
56+
//Only ; needs escaping. Everything else is just trimmed, and added to the map.
57+
Map<String, String> map = new HashMap<String, String>();
58+
boolean inKey = true;
59+
StringBuilder buffer = new StringBuilder();
60+
String keyName = "";
61+
for (int i = 0; i < options.length(); i++) {
62+
Character c = options.charAt(i);
63+
Character c2 = null;
64+
if (i < options.length() - 1) {
65+
c2 = options.charAt(i + 1);
66+
}
67+
if (inKey) {
68+
if (c == ':') {
69+
keyName = buffer.toString();
70+
buffer = new StringBuilder();
71+
inKey = false;
72+
} else if (c == ';') {
73+
//Self closed
74+
map.put(buffer.toString().trim().toLowerCase(), "true");
75+
buffer = new StringBuilder();
76+
keyName = "";
77+
//We don't reset the inKey parameter
78+
} else {
79+
buffer.append(c);
8380
}
84-
if (buffer.length() > 0) {
85-
if (!inKey) {
86-
map.put(keyName.trim().toLowerCase(), buffer.toString());
87-
} else {
88-
if (!buffer.toString().trim().isEmpty()) {
89-
map.put(buffer.toString().trim().toLowerCase(), "true");
90-
}
91-
}
81+
} else {
82+
if (c == '\\' && c2 == ';') {
83+
buffer.append(';');
84+
i++;
85+
} else if (c == ';') {
86+
//We're done
87+
inKey = true;
88+
map.put(keyName.trim().toLowerCase(), buffer.toString());
89+
buffer = new StringBuilder();
90+
} else {
91+
buffer.append(c);
9292
}
93-
FileOptions fo = new FileOptions(map);
94-
return fo;
93+
}
9594
}
96-
95+
if (buffer.length() > 0) {
96+
if (!inKey) {
97+
map.put(keyName.trim().toLowerCase(), buffer.toString());
98+
} else {
99+
if (!buffer.toString().trim().isEmpty()) {
100+
map.put(buffer.toString().trim().toLowerCase(), "true");
101+
}
102+
}
103+
}
104+
FileOptions fo = new FileOptions(map);
105+
return fo;
106+
}
107+
97108
}

0 commit comments

Comments
 (0)