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-parser/xml-spec.grm
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1323 - (download) (annotate)
Fri Nov 15 15:07:59 2013 UTC (4 years, 7 months ago) by jhr
File size: 5094 byte(s)
  working on parser for OpenGL XML spec format
(* xml-spec.grm
 *
 * COPYRIGHT (c) 2013 The SML3d Project (http://sml3d.cs.uchicago.edu)
 * All rights reserved.
 *
 * An ML-Antrl parser for the OpenGL XML specification files.  See registry.rnc for
 * the specification.
 *)

%name GLSpec;

%tokens
  : OPEN_alias		("<alias")
  | ELEM_apientry	("<apientry/>")
  | OPEN_command	("<command")
  | CLOSE_command	("</command>")
  | OPEN_commands	("<commands")
  | CLOSE_commands	("</commands>")
  | OPEN_comment	("<comment>")
  | CLOSE_comment	("</comment>")
  | OPEN_enum		("<enum")
  | OPEN_enums		("<enums")
  | CLOSE_enums		("</enums>")
  | OPEN_extension	("<extension")
  | CLOSE_extension	("</extension>")
  | OPEN_extensions	("<extensions>")
  | CLOSE_extensions	("</extensions>")
  | OPEN_feature	("<feature")
  | CLOSE_feature	("</feature>")
  | OPEN_glx		("<glx")
  | OPEN_group		("<group")
  | CLOSE_group		("</group>")
  | OPEN_groups		("<groups>")
  | CLOSE_groups	("</groups>")
  | OPEN_name		("<name>")
  | CLOSE_name		("</name>")
  | OPEN_param		("<param")
  | CLOSE_param		("</param>")
  | OPEN_proto		("<proto")
  | CLOSE_proto		("</proto>")
  | OPEN_ptype		("<ptype>")
  | CLOSE_ptype		("</ptype>")
  | OPEN_registry	("<registry>")
  | CLOSE_registry	("</registry>")
  | OPEN_require	("<require")
  | CLOSE_require	("</require>")
  | OPEN_remove		("<remove")
  | CLOSE_remove	("</remove>")
  | OPEN_type		("<type")
  | CLOSE_type		("</type>")
  | OPEN_types		("<types>")
  | CLOSE_types		("</types>")
  | OPEN_unused		("<unused")
  | OPEN_vecequiv	("<vecequiv")
  | XML_OPEN		("<?xml")
  | XML_CLOSE		("?>")
  | SYM_GT		(">")
  | SYM_SLASHGT		("/>")
  | SYM_EQ		("=")
  | CDATA of string	(* raw text inside <![CDATA[ ... ]]> element *)
  | TEXT of string	(* text, not including pure whitespace *)
  | ID of Atom.atom
  | LIT of string       (* numbers, version tags, etc. *)
  ;

%defs (
  structure S = SpecRep
);

%start Registry;

Registry
	: "<?xml" Attribute* "?>" "<registry>" RegistryItem* "</registry>"
		=> (S.mkRegistry RegistryItem)
	;

RegistryItem
	: Comment
	| Types
	| Groups
	| Enums
	| Commands
	| Feature
	| Extensions
	;

Comment
	: "<comment>" Text "</comment>"
		=> (S.mkComment Text)
	;

Types
	: "<types>" Type* "</types>"
		=> (S.mkTypes Type)
	;

Type
	: "<type" Attribute* ">" Text? ("<apientry/>" Text)? (Name Text)? "</type>"
		=> (let
		    val (name, txt) = (case SR2
			   of NONE => (NONE, [])
			    | SOME(name, txt) => (SOME name, [" ", name, " ", txt])
			  (* end case *))
		    val txt = (case SR1 of NONE => txt | SOME t => t::txt)
		    val txt = (case Text of NONE => txt | SOME t => t::txt)
		    in
		      S.mkType(Attribute, name, concat txt)
		    end)
	;

Name
	: "<name>" Text "</name>"
		=> (Text)
	;

Groups
	: "<groups>" Group* "</groups>"
		=> (S.mkGroups Group)
	;

Group
	: "<group" Attribute+ ">" Enum* "</group>"
		=> (S.mkGroup(Attribute, Enum))
	;

Enums
	: "<enums" Attribute* ">" (Enum => (S.L Enum)| Unused => (S.R Unused))* "</enums>"
		=> (S.mkEnums(Attribute, SR))
	;

Enum
	: "<enum" Attribute+ "/>"
		=> (S.mkEnum Attribute)
	;

Unused
	: "<unused" Attribute+ "/>"
		=> (S.mkUnused Attribute)
	;

Commands
	: "<commands" Attribute* ">" Command* "</commands>"
		=> (S.mkCommands(Attribute, Command))
	;

Command
	: "<command" Attribute* ">" Proto Param* CmdExtra* "</command>"
		=> (S.mkCommand(Attribute, Proto, Param, CmdExtra))
	;

Proto
	: "<proto" Attribute* ">" ParamOrProtoContent "</proto>"
		=> (let
		    val (ptype, name, txt) = ParamOrProtoContent
		    in
		      S.mkProto(Attribute, ptype, name, txt)
		    end)
	;

ParamOrProtoContent
	: Text (PType Text)? Name Text
		=> (let
		    val txt = [Name, Text2]
		    val (ptype, txt') = (case SR
			   of NONE => (NONE, txt)
			    | SOME(ptype, txt') => (SOME ptype, ptype :: txt' :: txt)
			  (* end case *))
		    in
		      (ptype, Name, String.concat(Text1::txt))
		    end)
	;

PType
	: "<ptype>" Text "</ptype>"
		=> (Text)
	;

Param
	: "<param" Attribute* ">" ParamOrProtoContent "</param>"
		=> (let
		    val (ptype, name, txt) = ParamOrProtoContent
		    in
		      S.mkParam(Attribute, ptype, name, txt)
		    end)
	;

CmdExtra
	: "<alias" Attribute "/>"
		=> (S.mkAlias Attribute)
	| "<vecequiv" Attribute "/>"
		=> (S.mkVecEquiv Attribute)
	| "<glx" Attribute+ "/>"
		=> (S.mkGLX Attribute)
	;

Feature
	: "<feature" Attribute+ ">" RequireOrRemove* "</feature>"
		=> (S.mkFeature(Attribute, RequireOrRemove))
	;

RequireOrRemove
	: "<require" Attribute* ">" InterfaceElement* "</require>"
		=> (S.mkRequire(Attribute, InterfaceElement))
	| "<remove" Attribute* ">" InterfaceElement* "</remove>"
		=> (S.mkRemove(Attribute, InterfaceElement))
	;

InterfaceElement
	: Type
		=> (S.mkTypeElem Type)
	| Enum
		=> (S.mkEnumElem Enum)
	| Command
		=> (S.mkCommandElem Command)
	;

Extensions
	: "<extensions>" Extension* "</extensions>"
		=> (S.mkExtensions Extension)
	;

Extension
	: "<extension" Attribute+ ">" RequireOrRemove* "</extension>"
		=> (S.mkExtension(Attribute, RequireOrRemove))
	;

Attribute
	: ID "=" LIT
		=> (ID, LIT)
	;

Text
	: (TEXT | CDATA)+
		=> (String.concat SR)
	;

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