lexer function

Parser<FhirPathParser> lexer()

Primary lexing function for this library

Implementation

Parser<FhirPathParser> lexer() {
  final lexerFunctions = undefined();
  final lexerParentheses = undefined();

  /// The order of lexing is important, and if/when updated, needs
  /// to be taken into account in order for petiteparser to find
  /// patterns in the correct order
  final tokenizer = simpleLexer |
      lexerFunctions |
      lexerParentheses |
      wordOperationLexer |
      wsLexer |
      symbolOperationLexer |
      specialLexer |
      literalLexer;

  /// Calls the operatorValues function to check if any arguments need
  /// to be passed to the current Parser
  lexerFunctions.set((functionLexer & tokenizer.star() & char(')'))
      .map((val) => val[0]..value = operatorValues(val[1] as List)));

  /// Calls the operatorValues function to check if any arguments need
  /// to be passed to the current ParenthesesParser
  lexerParentheses.set((char('(') & tokenizer.star() & char(')'))
      .map((value) => ParenthesesParser(operatorValues(value[1] as List))));

  /// Complete the lexing and again, passes to operatorValues
  return tokenizer.plus().end().map((value) => operatorValues(value));
}