-
-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d32faa9
commit 5186fc4
Showing
15 changed files
with
229 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
structurizr-dsl/src/main/java/com/structurizr/dsl/Constant.java
This file was deleted.
Oops, something went wrong.
33 changes: 0 additions & 33 deletions
33
structurizr-dsl/src/main/java/com/structurizr/dsl/ConstantParser.java
This file was deleted.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
structurizr-dsl/src/main/java/com/structurizr/dsl/NameValuePair.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.structurizr.dsl; | ||
|
||
class NameValuePair { | ||
|
||
private NameValueType type; | ||
private final String name; | ||
private final String value; | ||
|
||
NameValuePair(String name, String value) { | ||
this.name = name; | ||
this.value = value; | ||
} | ||
|
||
NameValueType getType() { | ||
return type; | ||
} | ||
|
||
void setType(NameValueType type) { | ||
this.type = type; | ||
} | ||
|
||
String getName() { | ||
return name; | ||
} | ||
|
||
String getValue() { | ||
return value; | ||
} | ||
|
||
} | ||
|
||
enum NameValueType { | ||
|
||
Constant, | ||
Variable | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
structurizr-dsl/src/main/java/com/structurizr/dsl/NameValueParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.structurizr.dsl; | ||
|
||
final class NameValueParser extends AbstractParser { | ||
|
||
private static final String GRAMMAR = "%s <name> <value>"; | ||
|
||
private static final int KEYWORD_INDEX = 0; | ||
private static final int NAME_INDEX = 1; | ||
private static final int VALUE_INDEX = 2; | ||
|
||
private static final String NAME_REGEX = "[a-zA-Z0-9-_.]+"; | ||
|
||
NameValuePair parseConstant(Tokens tokens) { | ||
NameValuePair nvp = parse(tokens); | ||
nvp.setType(NameValueType.Constant); | ||
|
||
return nvp; | ||
} | ||
|
||
NameValuePair parseVariable(Tokens tokens) { | ||
NameValuePair nvp = parse(tokens); | ||
nvp.setType(NameValueType.Variable); | ||
|
||
return nvp; | ||
} | ||
|
||
private NameValuePair parse(Tokens tokens) { | ||
// !const name value | ||
// !var name value | ||
|
||
if (tokens.hasMoreThan(VALUE_INDEX)) { | ||
throw new RuntimeException("Too many tokens, expected: " + String.format(GRAMMAR, tokens.get(KEYWORD_INDEX))); | ||
} | ||
|
||
if (!tokens.includes(VALUE_INDEX)) { | ||
throw new RuntimeException("Expected: " + String.format(GRAMMAR, tokens.get(KEYWORD_INDEX))); | ||
} | ||
|
||
String name = tokens.get(NAME_INDEX); | ||
String value = tokens.get(VALUE_INDEX); | ||
|
||
if (!name.matches(NAME_REGEX)) { | ||
throw new RuntimeException("Constant/variable names must only contain the following characters: a-zA-Z0-9-_."); | ||
} | ||
|
||
return new NameValuePair(name, value); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 0 additions & 59 deletions
59
structurizr-dsl/src/test/java/com/structurizr/dsl/ConstantParserTests.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.