Home My Page Projects Code Snippets Project Openings 3D graphics for Standard ML
Summary Activity SCM

SCM Repository

[sml3d] View of /trunk/sml3d/gen/spec-parser/spec-db/xml-spec.grm
ViewVC logotype

View of /trunk/sml3d/gen/spec-parser/spec-db/xml-spec.grm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1223 - (download) (annotate)
Wed Aug 3 18:28:46 2011 UTC (6 years, 10 months ago) by jhr
File size: 4414 byte(s)
  Working on spec parser/database
(* xml-spec.grm
 *
 * COPYRIGHT (c) 2011 The SML3d Project (http://sml3d.cs.uchicago.edu)
 * All rights reserved.
 *
 * This is a parser for the XML file that is used to specify information
 * about the OpenGL interfaces and extensions.
 *)

%name XMLSpec;

%tokens : TAG_const_group	("const-group")
        | TAG_constant		("constant")
        | TAG_constants		("constants")
        | TAG_const_prefix	("const-prefix")
        | TAG_enums		("enums")
        | TAG_function		("function")
        | TAG_functions		("functions")
        | TAG_funct_prefix	("funct-prefix")
        | TAG_functs		("functs")
        | TAG_param		("param")
        | TAG_return		("return")
        | TAG_spec_db		("spec-db")
        | TAG_type		("type")
        | TAG_typemap		("typemap")
        | TAG_types		("types")
        | ATR_alias		("alias")
        | ATR_category		("category")
        | ATR_ctype		("ctype")
        | ATR_deprecated	("deprecated")
        | ATR_def               ("def")
        | ATR_kind		("kind")
        | ATR_mltype		("mltype")
        | ATR_name		("name")
        | ATR_path		("path")
        | ATR_prefix		("prefix")
        | ATR_value		("value")
        | ATR_version		("version")
	| LOPEN			("<")
	| ROPEN			(">")
	| LCLOSE		("</")
	| RCLOSE		("/>")
	| EQ			("=")
	| STR of string
	;

%defs (
  structure X = XMLRep

  fun isCType s = Option.isSome(CType.fromString s)

  fun ctype s = (case CType.fromString s
         of NONE => raise Fail(concat["bogus C type \"", s, "\""])
          | SOME ty => ty
        (* end case *))
);

File
	: "<" "spec-db" ">" Header Constants Types Functions* "</" "spec-db" ">"
		=> (let
                    val (tm, en, fs, cp, fp) = Header
                    in
                      X.DB{
                          typemap = tm, enums = en, functs = fs,
                          constprefix = cp, functprefix = fp,
                          constants = Constants,
                          types = Types,
                          functions = Functions
                        }
                    end)
	;

Header
        : TypeMap Enums Functs ConstPrefix FunctPrefix
                => (TypeMap, Enums, Functs, ConstPrefix, FunctPrefix)
        ;

TypeMap
        : "<" "typemap" "path" "=" STR "/>"
                => (STR)
        ;

Enums
        : "<" "enums" "path" "=" STR "/>"
                => (STR)
        ;

Functs
        : "<" "functs" "path" "=" STR "/>"
                => (STR)
        ;

ConstPrefix
        : "<" "const-prefix" "prefix" "=" STR "/>"
                => (STR)
        ;

FunctPrefix
        : "<" "funct-prefix" "prefix" "=" STR "/>"
                => (STR)
        ;

Constants
	: "<" "constants" ">" ConstGroup+ "</" "constants" ">"
		=> (ConstGroup)
	| "<" "constants" "/>"
		=> ([])
	;

ConstGroup
        : "<" "const-group" "name" "=" Atom "kind" "=" Atom
          ( ">" Constant+ "</" "const-group" ">" => (Constant) | "/>" => ([]))
                => (X.ConstGrp{name=Atom1, kind=Atom2, consts=SR})
        ;

Constant
	: "<" "constant" "name" "=" Atom "value" "=" STR "/>"
		=> ({name = Atom, value = STR})
	;

Types
	: "<" "types" ">" Type* "</" "type" ">"
		=> (Type)
	| "<" "types" "/>"
		=> ([])
	;

Type
	: "<" "type" "name" "=" Atom "def" "=" CType "/>"
		=> ({name = Atom, def = CType})
	;

Functions
	: "<" "functions" "category" "=" Atom ">" Function+ "</" "functions" ">"
		=> (X.Category{name = Atom, functs = Function})
	;

Function
	: "<" "function" "name" "=" Atom Alias? Version? Deprecated? ">"
          ReturnType Param*
          "</" "function" ">"
                => (X.Fun{
                      name = Atom, alias = Alias, version = Version, deprecated = Deprecated,
                      retTy = ReturnType, params = Param
                    })
	;

Alias
        : "alias" "=" Atom              => (Atom)
        ;

Version
        : "version" "=" STR             => (STR)
        ;

Deprecated
        : "deprecated" "=" STR          => (STR)
        ;

ReturnType
        : "<" "return" "ctype" "=" CType ("mltype" "=" STR)? "/>"
                => ({cty = CType, mlty = SR})
        ;

Param
        : "<" "param" "name" "=" STR "ctype" "=" CType ("mltype" "=" STR)? "/>"
                => (X.Param{name = STR, cty = CType, mlty = SR})
        ;

CType
        : STR %where (isCType STR)
                => (ctype STR)
        ;

Atom    : STR           => (Atom.atom STR)
        ;

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0