Class Parser

java.lang.Object
org.jfuncmachine.sexprlang.parser.Parser

public class Parser extends Object
A simple S-expression parser
  • Method Details

    • parseFile

      public static SexprItem parseFile(String filename) throws IOException
      Parses a file and returns the first S-expression
      Parameters:
      filename - The file to parse
      Returns:
      The first S-expression in the file
      Throws:
      IOException - If there is an error reading or parsing the file
    • parseFile

      public static SexprItem parseFile(String filename, boolean parseMultipleSexprs) throws IOException
      Parses a file and returns either the first or all S-expressions in it
      Parameters:
      filename - The file to parse
      parseMultipleSexprs - True if the parser should return all S-expressions instead of just the first
      Returns:
      Either the first or all the S-expressions in the file
      Throws:
      IOException - If there is an error reading or parsing the file
    • parseString

      public static SexprItem parseString(String str) throws IOException
      Parses an S-expression from a String
      Parameters:
      str - The string to parse
      Returns:
      The first S-expression in the string
      Throws:
      IOException - If there is an error parsing the string
    • parseString

      public static SexprItem parseString(String str, boolean parseMultipleSexprs) throws IOException
      Parses an S-expression from a String
      Parameters:
      str - The string to parse
      parseMultipleSexprs - If true, all S-expressions in the file are parsed, not just the first
      Returns:
      The first S-expression in the string
      Throws:
      IOException - If there is an error parsing the string
    • parseString

      public static SexprItem parseString(String str, String filename) throws IOException
      Parses an S-expression from a String
      Parameters:
      str - The string to parse
      filename - The filename to use as the filename in the generated S-expressions
      Returns:
      The first S-expression in the string
      Throws:
      IOException - If there is an error parsing the string
    • parseString

      public static SexprItem parseString(String str, boolean parseMultipleSexprs, String filename) throws IOException
      Parses an S-expression from a String
      Parameters:
      str - The string to parse
      parseMultipleSexprs - If true, all S-expressions in the file are parsed, not just the first
      filename - The filename to use as the filename in the generated S-expressions
      Returns:
      The first S-expression in the string
      Throws:
      IOException - If there is an error parsing the string
    • parseFile

      public static SexprItem parseFile(String filename, SymbolMatcher symbolMatcher) throws IOException
      Parses an S-expression from a file using the specified matcher to identify symbols
      Parameters:
      filename - The file to parse
      symbolMatcher - The matcher that determines if a character is part of a symbol
      Returns:
      The first S-expression matched
      Throws:
      IOException - If there is an error reading or parsing the file
    • parseFile

      public static SexprItem parseFile(String filename, boolean parseMultipleSexprs, SymbolMatcher symbolMatcher) throws IOException
      Parses S-expressions from a file using the specified matcher to identify symbols
      Parameters:
      filename - The file to parse
      parseMultipleSexprs - If true, all S-expressions in the file are parsed, not just the first
      symbolMatcher - The matcher that determines if a character is part of a symbol
      Returns:
      The first S-expression matched
      Throws:
      IOException - If there is an error reading or parsing the file
    • parseString

      public static SexprItem parseString(String str, String filename, SymbolMatcher symbolMatcher) throws IOException
      Parses an S-expression from a string using the specified matcher to identify symbols
      Parameters:
      str - The string to parse
      filename - The filename to use as the filename in the generated S-expression items
      symbolMatcher - The matcher that determines if a character is part of a symbol
      Returns:
      The first S-expression matched
      Throws:
      IOException - If there is an error parsing the string
    • parseString

      public static SexprItem parseString(String str, String filename, boolean parseMultipleSexprs, SymbolMatcher symbolMatcher) throws IOException
      Parses an S-expression from a string using the specified matcher to identify symbols
      Parameters:
      str - The string to parse
      filename - The filename to use as the filename in the generated S-expression items
      parseMultipleSexprs - If true, all S-expressions in the file are parsed, not just the first
      symbolMatcher - The matcher that determines if a character is part of a symbol
      Returns:
      The first S-expression matched
      Throws:
      IOException - If there is an error parsing the string