Permalink
Browse files

Moved `Parser` class to separate file, outside of the `RuleBasedParse…

…r`. Moved `cruise.umple.parser` code to `UmpleParser/` directory. Updated build-scripts. Added readme.
  • Loading branch information...
bitwizeshift committed Apr 4, 2016
1 parent d64c24d commit 41526d65fcb90c51519fd110a29969d188e273d5
Showing with 1,344 additions and 1,215 deletions.
  1. +2 −2 .travis.yml
  2. +33 −0 UmpleParser/README.md
  3. 0 {cruise.umple → UmpleParser}/src/GrammarParsing.ump
  4. 0 {cruise.umple → UmpleParser}/src/GrammarParsing_Code.ump
  5. +12 −0 UmpleParser/src/Master.ump
  6. +126 −0 UmpleParser/src/ParseUtilities.ump
  7. +606 −0 UmpleParser/src/ParseUtilities_Code.ump
  8. 0 {cruise.umple → UmpleParser}/src/ParsingRules.ump
  9. 0 {cruise.umple → UmpleParser}/src/ParsingRules_Code.ump
  10. 0 {cruise.umple → UmpleParser}/src/TextParser.ump
  11. 0 {cruise.umple → UmpleParser}/src/TextParser_Code.ump
  12. +16 −0 build/build.umple.xml
  13. +4 −1 cruise.umple/src/Documenter.ump
  14. +1 −1 cruise.umple/src/Generator.ump
  15. +4 −1 cruise.umple/src/Json.ump
  16. +0 −3 cruise.umple/src/Master.ump
  17. +18 −113 cruise.umple/src/Parser.ump
  18. +0 −607 cruise.umple/src/Parser_Code.ump
  19. +2 −0 cruise.umple/src/Structure.ump
  20. +11 −0 cruise.umple/src/Umple.ump
  21. +2 −0 cruise.umple/src/UmpleAnalysis.ump
  22. +4 −0 cruise.umple/src/UmpleInternalParser.ump
  23. +4 −0 cruise.umple/src/UmpleInternalParser_CodeParserHandlers.ump
  24. +1 −1 cruise.umple/src/UmpleInternalParser_CodeTemplate.ump
  25. +4 −1 cruise.umple/src/Vml.ump
  26. +1 −1 cruise.umple/test/cruise/umple/{parser → compiler}/CoupleTest.java
  27. +8 −1 cruise.umple/test/cruise/umple/{parser → compiler}/ParserTest.java
  28. +482 −482 cruise.umple/test/cruise/umple/{parser → compiler}/RuleInstanceTest.java
  29. +3 −1 cruise.umple/test/cruise/umple/{parser → compiler}/RulePartTest.java
View
@@ -36,12 +36,12 @@ script:
- ant deps-resolve-all
# Do a modified version of `first-build`
- $ANT_FIRST clean init codegen rtcpp template.setVersion resetUmpleSelf
- $ANT_FIRST clean init codegen umpleParser rtcpp template.setVersion resetUmpleSelf
- $ANT_FIRST compile compileValidator compileUmplificator
- $ANT_FIRST package template.resetVersion
# Do a modified version of `build`
- $ANT_BUILD clean init codegen rtcpp template.setVersion resetUmpleSelf
- $ANT_BUILD clean init codegen umpleParser rtcpp template.setVersion resetUmpleSelf
- $ANT_BUILD compile compileValidator compileUmplificator
- $ANT_BUILD package
- $ANT_BUILD template.test template.resetVersion
View
@@ -0,0 +1,33 @@
UmpleParser
===========
Description
-----------
The `RuleBasedParser` is a fast and sophisticated parser that is at the core of Umple.
It reads in grammar files written in a modified/extended [EBNF](https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_Form) syntax and produces rules that can be used to parse files written in the corresponding language.
Compilation
-----------
Currently, this can only be compiled as part of the main Umple build. This will be changed in the future to be an entirely independently compilable project with a separate ant build target.
The umple source is available in `src/`, and -- once compiled -- the java source is available in `src-gen-umple/`
How To Use
----------
Using the RuleBasedParser is simple:
1. Import the package for the RuleBasedParser
In Umple this is `depend cruise.umple.parser.analysis.RuleBasedParser`. In Java, just `import cruise.umple.parser.analysis.RuleBasedParser`
2. Construct a parser with `RuleBasedParser rbp = new RuleBasedParser()`
3. Read in any necessary grammar files for the parser with `rbp.addGrammarFile("<filepath>");`
The grammar file filepath is relative to the root java package.
4. *[Optional]* Assign a handler for linking files. To do this, call `rbp.setLikedFileHandler(...)` and pass a class that implements `LinkedFileHandler`
5. *[Optional]* Assign a handler for generating analyzers. To do this, call `rbp.setAnalyzerGenerator(...)` and pass a class that implements `AnalyzerGeneratorHandler`
6. *[Optional]* Create parser actions for specific tokens with `rbp.addParserAction(...)`, passing it the string action name and a class that implements `ParserAction`
7. Create a `File` object of the file to parse (e.g. `File file = new File("somefile");`
8. Parse the file with `rbp.parse( file )`. To retrieve the tokens from the parse, use `rbp.getRootToken()`
View
@@ -0,0 +1,12 @@
generate Java "../src-gen-umple";
strictness allow 1006;
strictness allow 1007;
strictness allow 1008;
strictness allow 46;
strictness allow 36;
use ParseUtilities.ump;
use ParsingRules.ump;
use TextParser.ump;
use GrammarParsing.ump;
@@ -0,0 +1,126 @@
/*
Copyright: All contributers to the Umple Project
This file is made available subject to the open source license found at:
http://umple.org/license
Parser for the grammar that can be used to define any grammar
UmpleParser.ump is the key example
*/
namespace cruise.umple.parser;
/*
* Represents the results of parsing, such as if it was successful,
* whether it had warnings, etc.
*/
class ParseResult
{
// Specifies whether or not the parsing was successful.
Boolean wasSuccess;
// Specifies whether or not the parsing has warnings.
Boolean hasWarnings = false;
internal Boolean _acceptsErrors = true;
// Position is left for now, as not to break things
* -> 0..1 Position;
// The error messages related to parsing.
* -> * ErrorMessage;
}
/*
* Represents an error message, typically used with parsing.
*/
class ErrorMessage
{
// Indicates the type of error.
* -> 1 ErrorType;
* -> 1 Position;
String[] parameters;
depend java.io.File;
}
/*
* Represents an error type, which contains an error code, the severity of the error, etc.
* Error data is read from the en.error file
*/
class ErrorType
{
// The error code.
Integer errorCode;
// The severity of the error.
Integer severity;
String errorFormat;
String errorUrl;
key {errorCode}
}
/*
* Lists all the errors in the system
*/
class ErrorTypeSingleton
{
singleton;
1 -> * ErrorType;
depend java.io.*;
depend java.lang.IllegalStateException;
}
/*
* Fundamental to all parsing, used in conjunction with rules and their definitions.
* As parsing is taking place these will indicate what is currently being looked for
* (such as a class definition or attribute) and helps to keep
* track of the positions that the input parser parsed things at.
*/
class Token
{
// The name of the token.
name;
// The value of the token.
value;
0..1 parentToken -- * Token subTokens;
* -> 0..1 Position;
* -> 0..1 Position endPosition;
before getName { if (name == null) { return ""; } }
before getValue { if (value == null) { return ""; } }
before setPosition {String tFilename = position == null ? aNewPosition.getFilename() : position.getFilename();}
after setPosition {position.setFilename(tFilename);}
}
/*
* Used to indicate the coordinates of a position when parsing. This is done by keeping track of the
* filename, the line number and the corresponding offset on that line number.
*/
class Position
{
// The filename of the position.
String filename;
// The line number of the position.
Integer lineNumber;
// The character offset of the position.
Integer characterOffset;
// The offset of the position.
Integer offset;
key { filename, lineNumber, characterOffset, offset }
}
use ParseUtilities_Code.ump;
Oops, something went wrong.

0 comments on commit 41526d6

Please sign in to comment.