Class ParserUtils

java.lang.Object
software.amazon.smithy.model.loader.ParserUtils

public final class ParserUtils extends Object
Utility methods that act on a SimpleParser and parse Smithy grammar productions.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    consumeIdentifier(software.amazon.smithy.utils.SimpleParser parser)
    Expects and skips over a Smithy identifier production.
    static void
    consumeNamespace(software.amazon.smithy.utils.SimpleParser parser)
    Expects and consumes a valid Smithy shape ID namespace.
    static boolean
    isAlphabetic(char c)
    Returns true if the given character is an alphabetic character A-Z, a-z.
    static boolean
    isAlphabetic(int c)
    Returns true if the given character is an alphabetic character A-Z, a-z.
    static boolean
    isDigit(char c)
    Returns true if the given value is a digit 0-9.
    static boolean
    isDigit(int c)
    Returns true if the given value is a digit 0-9.
    static boolean
    Returns true if the given character is allowed to start an identifier.
    static boolean
    Returns true if the given character is allowed to start an identifier.
    static boolean
    Returns true if the given character is allowed in an identifier.
    static boolean
    Returns true if the given character is allowed in an identifier.
    static String
    parseIdentifier(software.amazon.smithy.utils.SimpleParser parser)
    Expects and returns a parsed Smithy identifier production.
    static String
    parseNumber(software.amazon.smithy.utils.SimpleParser parser)
    Parses a Smithy number production into a string.
    static String
    parseRootShapeId(software.amazon.smithy.utils.SimpleParser parser)
    Expects and returns a parsed absolute Smithy Shape ID that does not include a member.
    static String
    parseShapeId(software.amazon.smithy.utils.SimpleParser parser)
    Expects and returns a parsed relative or absolute Smithy Shape ID.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • parseNumber

      public static String parseNumber(software.amazon.smithy.utils.SimpleParser parser)
      Parses a Smithy number production into a string.
      -?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?
      Parameters:
      parser - Parser to consume tokens from.
      Returns:
      Returns the parsed number lexeme.
    • parseIdentifier

      public static String parseIdentifier(software.amazon.smithy.utils.SimpleParser parser)
      Expects and returns a parsed Smithy identifier production.
      Parameters:
      parser - Parser to consume tokens from.
      Returns:
      Returns the parsed identifier.
    • parseRootShapeId

      public static String parseRootShapeId(software.amazon.smithy.utils.SimpleParser parser)
      Expects and returns a parsed absolute Smithy Shape ID that does not include a member.
      Parameters:
      parser - Parser to consume tokens from.
      Returns:
      Returns the parsed Shape ID as a string.
    • parseShapeId

      public static String parseShapeId(software.amazon.smithy.utils.SimpleParser parser)
      Expects and returns a parsed relative or absolute Smithy Shape ID.
      Parameters:
      parser - Parser to consume tokens from.
      Returns:
      Returns the parsed Shape ID as a string.
    • consumeNamespace

      public static void consumeNamespace(software.amazon.smithy.utils.SimpleParser parser)
      Expects and consumes a valid Smithy shape ID namespace.
      Parameters:
      parser - Parser to consume tokens from.
    • consumeIdentifier

      public static void consumeIdentifier(software.amazon.smithy.utils.SimpleParser parser)
      Expects and skips over a Smithy identifier production.
           identifier       = identifier_start *identifier_chars
           identifier_start = *"_" ALPHA
           identifier_chars = ALPHA / DIGIT / "_"
       
      Parameters:
      parser - Parser to consume tokens from.
    • isValidIdentifierCharacter

      public static boolean isValidIdentifierCharacter(char c)
      Returns true if the given character is allowed in an identifier.
      Parameters:
      c - Character to check.
      Returns:
      Returns true if the character is allowed in an identifier.
    • isValidIdentifierCharacter

      public static boolean isValidIdentifierCharacter(int c)
      Returns true if the given character is allowed in an identifier.
      Parameters:
      c - Character to check.
      Returns:
      Returns true if the character is allowed in an identifier.
    • isIdentifierStart

      public static boolean isIdentifierStart(char c)
      Returns true if the given character is allowed to start an identifier.
      Parameters:
      c - Character to check.
      Returns:
      Returns true if the character can start an identifier.
    • isIdentifierStart

      public static boolean isIdentifierStart(int c)
      Returns true if the given character is allowed to start an identifier.
      Parameters:
      c - Character to check.
      Returns:
      Returns true if the character can start an identifier.
    • isDigit

      public static boolean isDigit(char c)
      Returns true if the given value is a digit 0-9.
      Parameters:
      c - Character to check.
      Returns:
      Returns true if the character is a digit.
    • isDigit

      public static boolean isDigit(int c)
      Returns true if the given value is a digit 0-9.
      Parameters:
      c - Character to check.
      Returns:
      Returns true if the character is a digit.
    • isAlphabetic

      public static boolean isAlphabetic(char c)
      Returns true if the given character is an alphabetic character A-Z, a-z. This is a stricter version of Character.isAlphabetic(int).
      Parameters:
      c - Character to check.
      Returns:
      Returns true if the character is an alphabetic character.
    • isAlphabetic

      public static boolean isAlphabetic(int c)
      Returns true if the given character is an alphabetic character A-Z, a-z. This is a stricter version of Character.isAlphabetic(int).
      Parameters:
      c - Character to check.
      Returns:
      Returns true if the character is an alphabetic character.