Class Source

java.lang.Object
nz.org.riskscape.dsl.Source

public class Source extends Object

Represents a bit of source code - something that we will parse using RiskScape's DSL API.

For now, this is effectively a wrapper around a string that remembers the location, but having a minimal matching API would allow:

  • to parse the file without having to read the whole thing up front first.
  • to not keep the whole thing in RAM once it's parsed.

But debatable whether it's worth the effort - but might improve start up times for larger projects?

  • Constructor Details

    • Source

      public Source(@NonNull @NonNull String wrapping, @NonNull @NonNull URI location)
  • Method Details

    • create

      public static Source create(String string, URI location)

      Create a Source object from a string and a URI

    • from

      public static Source from(Resource source)

      Create a Source object from a Resource

    • fromPath

      public static Source fromPath(String filepath) throws RiskscapeIOException

      Create a Source object from a file path

      Throws:
      RiskscapeIOException
    • anon

      public static Source anon(String string)

      Create a Source object that doesn't retain its location - avoid using this where possible.

    • toString

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

      public boolean isAnonymous()
    • readFully

      public String readFully()
    • length

      public int length()
    • charAt

      public char charAt(int index)
    • subSequence

      public CharSequence subSequence(int start, int end)
    • substring

      public String substring(int begin, int end)
    • substring

      public String substring(int begin)
    • isSingleLine

      public boolean isSingleLine()
    • regionMatches

      public boolean regionMatches(int position, String string, int i, int length)
    • regionMatches

      public boolean regionMatches(boolean b, int position, String string, int i, int length)
    • getLocation

      @NonNull public @NonNull URI getLocation()