Class Parser

java.lang.Object
cruise.umple.compiler.Parser
Direct Known Subclasses:
ContentParser, JsonParser, UmpleInternalParser

public class Parser extends Object
Parses an Umple file (.ump) based on grammar rules. As parsing is going on "tokens" will be created and linked together in a hierarchy fashion based on what was parsed.
  • Constructor Details

    • Parser

      public Parser(String aName)
    • Parser

      public Parser(String aFilename, String aName)
      Constructor.
      Parameters:
      aFilename - The Umple file (.ump) that the parser will parse.
      aName - The name of the parser, typically "UmpleInternalParser" or "innerParser".
  • Method Details

    • setFilename

      public boolean setFilename(String aFilename)
    • setName

      public boolean setName(String aName)
    • addGrammarRule

      public boolean addGrammarRule(String aGrammarRule)
    • removeGrammarRule

      public boolean removeGrammarRule(String aGrammarRule)
    • setParseResult

      public boolean setParseResult(ParseResult aParseResult)
    • setRootToken

      public boolean setRootToken(Token aRootToken)
    • getFilename

      public String getFilename()
      The Umple file (.ump) that will be parsed.
    • getName

      public String getName()
      default 'program'
    • getGrammarRule

      public String getGrammarRule(int index)
    • getGrammarRules

      public String[] getGrammarRules()
    • numberOfGrammarRules

      public int numberOfGrammarRules()
    • hasGrammarRules

      public boolean hasGrammarRules()
    • indexOfGrammarRule

      public int indexOfGrammarRule(String aGrammarRule)
    • getParseResult

      public ParseResult getParseResult()
      The results of the parsing, and any errors/warning messages will be stored here.
    • getRootToken

      public Token getRootToken()
      Every parser makes use of "tokens" that are built up based on what is parsed. In the end it looks almost like a "tree". This is the starting token for which everything will be built off of (sub-tokens).
    • getRule

      public Rule getRule(int index)
    • getRules

      public List<Rule> getRules()
      A parser can have many "rules", likewise each rule can be part of many "parsers"; hence many-to-many.
    • numberOfRules

      public int numberOfRules()
    • hasRules

      public boolean hasRules()
    • indexOfRule

      public int indexOfRule(Rule aRule)
    • getCouple

      public Couple getCouple(int index)
    • getCouples

      public List<Couple> getCouples()
    • numberOfCouples

      public int numberOfCouples()
    • hasCouples

      public boolean hasCouples()
    • indexOfCouple

      public int indexOfCouple(Couple aCouple)
    • minimumNumberOfRules

      public static int minimumNumberOfRules()
    • addRule

      public boolean addRule(Rule aRule)
    • removeRule

      public boolean removeRule(Rule aRule)
    • addRuleAt

      public boolean addRuleAt(Rule aRule, int index)
    • addOrMoveRuleAt

      public boolean addOrMoveRuleAt(Rule aRule, int index)
    • minimumNumberOfCouples

      public static int minimumNumberOfCouples()
    • addCouple

      public boolean addCouple(Couple aCouple)
    • removeCouple

      public boolean removeCouple(Couple aCouple)
    • addCoupleAt

      public boolean addCoupleAt(Couple aCouple, int index)
    • addOrMoveCoupleAt

      public boolean addOrMoveCoupleAt(Couple aCouple, int index)
    • delete

      public void delete()
    • reset

      public Token reset()
    • getRule

      public Rule getRule(String ruleName)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toGrammarNoStyle

      public String toGrammarNoStyle()
    • toGrammar

      public String toGrammar()
      Default grammar generation to html
    • toGrammarHtml

      public String toGrammarHtml()
      Used to generate a nice html representation for the user manual
    • toGrammarLezer

      public String toGrammarLezer()
      Used to generate a lezer grammar. See https://lezer.codemirror.net/docs/guide/#writing-a-grammar
    • toGrammarParts

      public String toGrammarParts(String rulesToOutput)
      Default grammar output to html format
    • toGrammarParts

      public String toGrammarParts(String rulesToOutput, String grammarFormat)
      Converts specific Umple rules to an alternative format If rulesToOutput is empty then all rules are output
    • genRuleHtml

      public void genRuleHtml(String ruleName, StringBuilder answer, String cleanedUpRule, int hasMinus, int hasHash)
    • genRuleLezer

      public void genRuleLezer(String ruleName, StringBuilder answer, String cleanedUpRule, int hasMinus, int hasHash)
    • toString

      public StringBuffer toString(StringBuffer stringSoFar, Token currentToken)
      Output the parse tree. The code originally here has been refactored to Token class
    • addRulesInFile

      public int addRulesInFile(String filenameOrResourcePath)
    • addRule

      public void addRule(String input)
    • parse

      public ParseResult parse(String ruleName, String input)
      Parses input based on a rule.
      Parameters:
      ruleName - The rule to parse based on.
      input - The textual input to parse (such as that from the Umple file).
      Returns:
      The result of the parsing.
    • getToken

      public Token getToken(int index)
    • getTokens

      public List<Token> getTokens()
    • numberOfTokens

      public int numberOfTokens()
    • hasTokens

      public boolean hasTokens()
    • indexOf

      public int indexOf(Token aToken)