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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1377 - (download) (annotate)
Fri Apr 4 20:45:22 2014 UTC (5 years, 1 month ago) by jhr
File size: 4562 byte(s)
  Working on FI generation tools
(* xml-spec.grm
 *
 * COPYRIGHT (c) 2014 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 SpecDB;

%tokens : TAG_command		("command")
	| TAG_commands		("commands")
	| TAG_enum		("enum")
	| TAG_enums		("enums")
	| TAG_feature		("feature")
	| TAG_features		("features")
	| TAG_group		("group")
	| TAG_groups		("groups")
	| TAG_id		("id")
	| TAG_param		("param")
	| TAG_proto		("proto")
	| TAG_return_type	("return-type")
	| TAG_spec_db		("spec-db")
	| TAG_type		("type")
	| TAG_types		("types")
	| ATR_api		("api")
	| ATR_bitmask		("bitmask")
	| ATR_ctype		("ctype")
	| ATR_def		("def")
	| ATR_extensions	("extensions")
	| ATR_mltype		("mltype")
	| ATR_name		("name")
	| ATR_profile		("profile")
	| ATR_registry		("registry")
	| ATR_value		("value")
	| ATR_version		("version")
	| LOPEN			("<")
	| ROPEN			(">")
	| LCLOSE		("</")
	| RCLOSE		("/>")
	| EQ			("=")
	| STR of string
	;

%defs (
  structure X = DBXMLRep

  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"
	    "registry" "=" STR "api" "=" STR "profile" "=" STR "extensions" "=" STR
	  ">" Types Enums Commands Groups Features "</" "spec-db" ">"
		=> (X.DB{
		      registry = STR1,
		      api = STR2,
		      profile = STR3,
		      extensions = STR4,
		      types = Types,
		      enums = Enums,
		      commands = Commands,
		      groups = Groups,
		      features = Features
		    })
	;

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

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

Enums
	: "<" "enums" ">" Enum* "</" "enums" ">"
		=> (Enum)
	| "<" "enums" "/>"
		=> ([])
	;

Enum
	: "<" "enum" NameAttr ( "ctype" "=" CType )? "value" "=" Number "/>"
		=> ({name = NameAttr, ty = SR, value = Number})
	;

Commands
	: "<" "commands" ">" Command* "</" "commands" ">"
		=> (Command)
	| "<" "commands" "/>"
		=> ([])
	;

Command
	: "<" "command" NameAttr ">" Proto+ "</" "command" ">"
		=> (X.Cmd{name = NameAttr, protos = Proto})
	;

Proto
	: "<" "proto" NameAttr ">" ReturnType Param* "</" "proto" ">"
                => (X.Proto{
                      name = NameAttr, retTy = ReturnType, params = Param
                    })
	;

ReturnType
        : "<" "return-type" "ctype" "=" CType MLTypeAttr? "/>"
                => ({cty = CType, mlty = MLTypeAttr})
        ;

MLTypeAttr
	: "mltype" "=" STR
		=> (STR)
	;

Param
        : "<" "param" NameAttr GroupAttr? "ctype" "=" CType MLTypeAttr? "/>"
                => (X.Param{name = NameAttr, group = GroupAttr, cty = CType, mlty = MLTypeAttr})
        ;

GroupAttr
	: "group" "=" STR
		=> (Atom.atom STR)
	;

Groups
	: "<" "groups" ">" Group* "</" "groups" ">"
		=> (Group)
	| "<" "groups" "/>"
		=> ([])
	;

Group
	: "<" "group" NameAttr ("bitmask" "=" Bool)? ">" Id+ "</" "group" ">"
		=> (X.EnumGrp{
			name = NameAttr,
			bitmask = (case SR of SOME b => b | NONE => false),
			consts = Id
		      })
	;

Features
	: "<" "features" ">" Feature* "</" "features" ">"
		=> (Feature)
	| "<" "features" "/>"
		=> ([])
	;

Feature
	: "<" "feature" NameAttr VersionAttr TypeIds EnumIds CommandIds "</" "feature" ">"
		=> (X.Feature{
			name = NameAttr, version = VersionAttr,
			types = TypeIds,
			enums = EnumIds,
			commands = CommandIds
		      })
	;

VersionAttr
	: "version" "=" STR
		=> (List.map (valOf o Int.fromString) (String.tokens (fn #"." => true | _ => false) STR))
	;

TypeIds
	: "<" "types" ">" Id+ "</" "types" ">"
		=> (Id)
	| "<" "types" "/>"
		=> ([])
	;

EnumIds
	: "<" "enums" ">" Id+ "</" "enums" ">"
		=> (Id)
	| "<" "enums" "/>"
		=> ([])
	;

CommandIds
	: "<" "commands" ">" Id+ "</" "commands" ">"
		=> (Id)
	| "<" "commands" "/>"
		=> ([])
	;

Id
	: "<" "id" NameAttr "/>"
		=> (NameAttr)
	;

NameAttr
	: "name" "=" STR
		=> (Atom.atom STR)
	;

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

Bool
	: STR
		=> (case STR
		     of "true" => true
		      | "false" => false
		      | _ => raise Fail(concat["expected boolean, but found \"", STR, "\""])
		    (* end case *))
	;

Number
	: STR
		=> (case IntInf.fromString STR
		     of SOME n => n
		      | _ => raise Fail(concat["expected integer, but found \"", STR, "\""])
		    (* end case *))
	;

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