Next: , Previous: , Up: Compiler   [Contents][Index]


4.5.1 Parser

The parser is available under the (rpc compiler parser) module. The main procedure, rpc-language->sexp, reads XDR/RPC language descriptions and returns the abstract syntax tree (AST) in the form of an S-expression. The AST can be shown using the --intermediate option of the grpc-compile command-line tool (see Invoking grpc-compile). Below is an illustration of the mapping between the XDR/RPC language and the S-exp representation.

const SIZE = 10;
struct foo
{
  int x;
  enum { NO = 0, YES = 1 } y;
  float z[SIZE];
};

... yields:

(define-constant "SIZE" 10)
(define-type
  "foo"
  (struct
    ("x" "int")
    ("y" (enum ("NO" 0) ("YES" 1)))
    ("z" (fixed-length-array "float" "SIZE"))))
Scheme Procedure: rpc-language->sexp port

Read a specification written in the XDR Language from port and return the corresponding sexp-based representation. This procedure can raise a &compiler-error exception (see below).

The behavior of the parser can be controlled using the *parser-options* parameter object:

Scheme Variable: *parser-options*

This SRFI-39 parameter object must be a list of symbols or the empty list. Each symbol describes an option. For instance, allow-unsigned instructs the parser to recognize unsigned as if it were unsigned int (see Sun XDR/RPC language extensions).

Source location information is attached to the S-expressions returned by rpc-language->sexp. It can be queried using the procedures below. Note that not-only top-level S-expressions (such as define-type or define-constant expressions) can be queried, but also sub-expressions, e.g., the enum S-expression above.

Scheme Procedure: sexp-location sexp

Return the source location associated with sexp or #f if no source location information is available.

Scheme Procedure: location-line loc
Scheme Procedure: location-column loc
Scheme Procedure: location-file loc

Return the line number, column number or file name from location loc, an object returned by sexp-location.

In case of parse errors or other compiler errors, a &compiler-error error condition (or an instance of a sub-type thereof) may be raise.

Scheme Variable: &compiler-error

The “compiler error” error condition type.

Scheme Procedure: compiler-error? c

Return #t if c is a compiler error.

Scheme Procedure: compiler-error:location c

Return the source location information associated with c, or #f if that information is not available.


Next: , Previous: , Up: Compiler   [Contents][Index]