From 60f16afd4241164451c99a53166637a93c198a7f Mon Sep 17 00:00:00 2001 From: Justin Tennant Date: Tue, 14 May 2019 11:16:51 -0700 Subject: [PATCH] Restructure project directories --- .../usdidea/{ => lang/lexer}/USDLexer.java | 3 +- .../usdidea/{ => lang/parser}/USDParser.java | 2 +- .../highlighting/USDColorSettingsPage.java | 123 +++++++++ .../highlighting/USDHighlighterColors.java | 10 + .../highlighting/USDSyntaxHighlighter.java | 93 +++++++ .../USDSyntaxHighlighterFactory.java | 16 ++ .../com/justint/usdidea/file/USDFileType.java | 41 +++ .../usdidea/file/USDFileTypeFactory.java | 12 + .../java/com/justint/usdidea/lang/USD.bnf | 244 ++++++++++++++++++ .../com/justint/usdidea/lang/USDLanguage.java | 12 + .../justint/usdidea/lang/lexer/USDLexer.flex | 194 ++++++++++++++ .../usdidea/lang/lexer/USDLexerAdapter.java | 12 + .../justint/usdidea/lang/lexer/_USDLexer.flex | 163 ++++++++++++ .../lang/parser/USDParserDefinition.java | 133 ++++++++++ .../usdidea/lang/psi/USDElementType.java | 12 + .../com/justint/usdidea/lang/psi/USDFile.java | 32 +++ .../usdidea/lang/psi/USDTokenType.java | 17 ++ .../com/justint/usdidea/util/USDIcons.java | 9 + src/main/resources/META-INF/plugin.xml | 8 +- 19 files changed, 1130 insertions(+), 6 deletions(-) rename src/main/gen/com/justint/usdidea/{ => lang/lexer}/USDLexer.java (99%) rename src/main/gen/com/justint/usdidea/{ => lang/parser}/USDParser.java (99%) create mode 100644 src/main/java/com/justint/usdidea/codeinsight/highlighting/USDColorSettingsPage.java create mode 100644 src/main/java/com/justint/usdidea/codeinsight/highlighting/USDHighlighterColors.java create mode 100644 src/main/java/com/justint/usdidea/codeinsight/highlighting/USDSyntaxHighlighter.java create mode 100644 src/main/java/com/justint/usdidea/codeinsight/highlighting/USDSyntaxHighlighterFactory.java create mode 100644 src/main/java/com/justint/usdidea/file/USDFileType.java create mode 100644 src/main/java/com/justint/usdidea/file/USDFileTypeFactory.java create mode 100644 src/main/java/com/justint/usdidea/lang/USD.bnf create mode 100644 src/main/java/com/justint/usdidea/lang/USDLanguage.java create mode 100644 src/main/java/com/justint/usdidea/lang/lexer/USDLexer.flex create mode 100644 src/main/java/com/justint/usdidea/lang/lexer/USDLexerAdapter.java create mode 100644 src/main/java/com/justint/usdidea/lang/lexer/_USDLexer.flex create mode 100644 src/main/java/com/justint/usdidea/lang/parser/USDParserDefinition.java create mode 100644 src/main/java/com/justint/usdidea/lang/psi/USDElementType.java create mode 100644 src/main/java/com/justint/usdidea/lang/psi/USDFile.java create mode 100644 src/main/java/com/justint/usdidea/lang/psi/USDTokenType.java create mode 100644 src/main/java/com/justint/usdidea/util/USDIcons.java diff --git a/src/main/gen/com/justint/usdidea/USDLexer.java b/src/main/gen/com/justint/usdidea/lang/lexer/USDLexer.java similarity index 99% rename from src/main/gen/com/justint/usdidea/USDLexer.java rename to src/main/gen/com/justint/usdidea/lang/lexer/USDLexer.java index 91d6866..8edff51 100644 --- a/src/main/gen/com/justint/usdidea/USDLexer.java +++ b/src/main/gen/com/justint/usdidea/lang/lexer/USDLexer.java @@ -1,7 +1,8 @@ /* The following code was generated by JFlex 1.7.0 tweaked for IntelliJ platform */ -package com.justint.usdidea; +package com.justint.usdidea.lang.lexer; +import com.intellij.lexer.FlexLexer; import com.intellij.psi.tree.IElementType; import static com.intellij.psi.TokenType.BAD_CHARACTER; diff --git a/src/main/gen/com/justint/usdidea/USDParser.java b/src/main/gen/com/justint/usdidea/lang/parser/USDParser.java similarity index 99% rename from src/main/gen/com/justint/usdidea/USDParser.java rename to src/main/gen/com/justint/usdidea/lang/parser/USDParser.java index 7dff56a..ae297a4 100644 --- a/src/main/gen/com/justint/usdidea/USDParser.java +++ b/src/main/gen/com/justint/usdidea/lang/parser/USDParser.java @@ -1,5 +1,5 @@ // This is a generated file. Not intended for manual editing. -package com.justint.usdidea; +package com.justint.usdidea.lang.parser; import com.intellij.lang.PsiBuilder; import com.intellij.lang.PsiBuilder.Marker; diff --git a/src/main/java/com/justint/usdidea/codeinsight/highlighting/USDColorSettingsPage.java b/src/main/java/com/justint/usdidea/codeinsight/highlighting/USDColorSettingsPage.java new file mode 100644 index 0000000..aa076ec --- /dev/null +++ b/src/main/java/com/justint/usdidea/codeinsight/highlighting/USDColorSettingsPage.java @@ -0,0 +1,123 @@ +package com.justint.usdidea.codeinsight.highlighting; + +import com.intellij.openapi.editor.colors.TextAttributesKey; +import com.intellij.openapi.fileTypes.SyntaxHighlighter; +import com.intellij.openapi.options.colors.AttributesDescriptor; +import com.intellij.openapi.options.colors.ColorDescriptor; +import com.intellij.openapi.options.colors.ColorSettingsPage; +import com.justint.usdidea.util.USDIcons; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import java.util.Map; + +public class USDColorSettingsPage implements ColorSettingsPage { + private static final AttributesDescriptor[] DESCRIPTORS = new AttributesDescriptor[] { + new AttributesDescriptor("Number", USDSyntaxHighlighter.NUMBER), + new AttributesDescriptor("String", USDSyntaxHighlighter.STRING), + new AttributesDescriptor("Comment", USDSyntaxHighlighter.COMMENT), + new AttributesDescriptor("USD Declaration", USDSyntaxHighlighter.USDDECLARATION) + }; + + @Nullable + @Override + public Icon getIcon() { + return USDIcons.FILE; + } + + @NotNull + @Override + public SyntaxHighlighter getHighlighter() { + return new USDSyntaxHighlighter(); + } + + @NotNull + @Override + public String getDemoText() { + // TODO: replace with custom demo text + return "#usda 1.0\n" + + "\n" + + "(\n" + + " upAxis = \"Y\"\n" + + " doc = \"\"\"This layer represents the various geometric forms that curves\n" + + " may be used to represent.\"\"\"\n" + + ")\n" + + "\n" + + "\n" + + "def Xform \"Linear\" {\n" + + " uniform token[] xformOpOrder = [\"xformOp:translate\"]\n" + + " float3 xformOp:translate = (0, 9, 0)\n" + + " def Scope \"Tubes\"{\n" + + " def BasisCurves \"ConstantWidth\" (){\n" + + " uniform token[] xformOpOrder = [\"xformOp:translate\"]\n" + + " float3 xformOp:translate = (3, 0, 0)\n" + + "\n" + + " uniform token type = \"linear\"\n" + + " int[] curveVertexCounts = [7]\n" + + " point3f[] points = [(0, 0, 0), (1, 1, 0), (1, 2, 0), (0, 3, 0), (-1, 4, 0), (-1, 5, 0), (0, 6, 0)]\n" + + " float[] widths = [.5] (interpolation = \"constant\")\n" + + " color3f[] primvars:displayColor = [(1, 0, 0)]\n" + + " }\n" + + " def BasisCurves \"VaryingWidth\" (){\n" + + " uniform token[] xformOpOrder = [\"xformOp:translate\"]\n" + + " float3 xformOp:translate = (6, 0, 0)\n" + + "\n" + + " uniform token type = \"linear\"\n" + + " int[] curveVertexCounts = [7]\n" + + " point3f[] points = [(0, 0, 0), (1, 1, 0), (1, 2, 0), (0, 3, 0), (-1, 4, 0), (-1, 5, 0), (0, 6, 0)]\n" + + " float[] widths = [0, .5, .5, .8, .5, .5, 0] (interpolation = \"varying\")\n" + + " color3f[] primvars:displayColor = [(0, 0, 1)]\n" + + " }\n" + + " }\n" + + " def Scope \"Ribbons\"{\n" + + " def BasisCurves \"VaryingWidth\" (){\n" + + " uniform token[] xformOpOrder = [\"xformOp:translate\"]\n" + + " float3 xformOp:translate = (12, 0, 0)\n" + + "\n" + + " uniform token type = \"linear\"\n" + + " int[] curveVertexCounts = [7]\n" + + " point3f[] points = [(0, 0, 0), (1, 1, 0), (1, 2, 0), (0, 3, 0), (-1, 4, 0), (-1, 5, 0), (0, 6, 0)]\n" + + " float[] widths = [0, .5, .5, .8, .5, .5, 0] (interpolation = \"varying\")\n" + + " normal3f[] normals = [(1, 0, 0), (.98, 0, .44), (.98, 0, .44), (.707, 0, .707), (.98, 0, .44), (.98, 0, .44), (1, 0, 0)] (interpolation = \"varying\")\n" + + " color3f[] primvars:displayColor = [(0, 1, 0)]\n" + + " }\n" + + " def BasisCurves \"ConstantWidth\" (){\n" + + " uniform token[] xformOpOrder = [\"xformOp:translate\"]\n" + + " float3 xformOp:translate = (15, 0, 0)\n" + + "\n" + + " uniform token type = \"linear\"\n" + + " int[] curveVertexCounts = [7]\n" + + " point3f[] points = [(0, 0, 0), (1, 1, 0), (1, 2, 0), (0, 3, 0), (-1, 4, 0), (-1, 5, 0), (0, 6, 0)]\n" + + " float[] widths = [.5] (interpolation = \"constant\")\n" + + " normal3f[] normals = [(1, 0, 0), (.98, 0, .44), (.98, 0, .44), (.707, 0, .707), (.98, 0, .44), (.98, 0, .44), (1, 0, 0)] (interpolation = \"varying\")\n" + + " color3f[] primvars:displayColor = [(1, 1, 1)]\n" + + " }\n" + + " }\n" + + "}"; + } + + @Nullable + @Override + public Map getAdditionalHighlightingTagToDescriptorMap() { + return null; + } + + @NotNull + @Override + public AttributesDescriptor[] getAttributeDescriptors() { + return DESCRIPTORS; + } + + @NotNull + @Override + public ColorDescriptor[] getColorDescriptors() { + return ColorDescriptor.EMPTY_ARRAY; + } + + @NotNull + @Override + public String getDisplayName() { + return "USD"; + } +} diff --git a/src/main/java/com/justint/usdidea/codeinsight/highlighting/USDHighlighterColors.java b/src/main/java/com/justint/usdidea/codeinsight/highlighting/USDHighlighterColors.java new file mode 100644 index 0000000..9a3037c --- /dev/null +++ b/src/main/java/com/justint/usdidea/codeinsight/highlighting/USDHighlighterColors.java @@ -0,0 +1,10 @@ +package com.justint.usdidea.codeinsight.highlighting; + +import com.intellij.openapi.editor.colors.TextAttributesKey; + +import static com.intellij.openapi.editor.colors.CodeInsightColors.HYPERLINK_ATTRIBUTES; + +public class USDHighlighterColors { + public static final TextAttributesKey ASSETREFERENCE_KEY = TextAttributesKey.createTextAttributesKey("ASSETREFERENCE", HYPERLINK_ATTRIBUTES); + public static final TextAttributesKey PATHREFERENCE_KEY = TextAttributesKey.createTextAttributesKey("PATHREFERENCE", HYPERLINK_ATTRIBUTES); +} diff --git a/src/main/java/com/justint/usdidea/codeinsight/highlighting/USDSyntaxHighlighter.java b/src/main/java/com/justint/usdidea/codeinsight/highlighting/USDSyntaxHighlighter.java new file mode 100644 index 0000000..5469f74 --- /dev/null +++ b/src/main/java/com/justint/usdidea/codeinsight/highlighting/USDSyntaxHighlighter.java @@ -0,0 +1,93 @@ +package com.justint.usdidea.codeinsight.highlighting; + +import com.intellij.lexer.Lexer; +import com.intellij.openapi.editor.*; +import com.intellij.openapi.editor.colors.TextAttributesKey; +import com.intellij.openapi.fileTypes.SyntaxHighlighterBase; +import com.intellij.psi.tree.IElementType; +import com.intellij.util.containers.ContainerUtil; +import com.justint.usdidea.lang.lexer.USDLexerAdapter; +import com.justint.usdidea.lang.parser.USDParserDefinition; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; + +import static com.intellij.openapi.editor.colors.TextAttributesKey.createTextAttributesKey; + + +public class USDSyntaxHighlighter extends SyntaxHighlighterBase { + + // TextAttributesKey instances + public static final TextAttributesKey USDDECLARATION = + createTextAttributesKey("USDDECLARATION", DefaultLanguageHighlighterColors.CONSTANT); + public static final TextAttributesKey STRING = + createTextAttributesKey("STRING", DefaultLanguageHighlighterColors.STRING); + public static final TextAttributesKey NUMBER = + createTextAttributesKey("NUMBER", DefaultLanguageHighlighterColors.NUMBER); + public static final TextAttributesKey COMMENT = + createTextAttributesKey("COMMENT", DefaultLanguageHighlighterColors.LINE_COMMENT); + +// +// // TextAttributesKey arrays +// private static final TextAttributesKey[] CONSTANTS = new TextAttributesKey[] {USD_DECLARATION}; +// private static final TextAttributesKey[] IDENTIFIERS = new TextAttributesKey[]{ +// createTextAttributesKey("ALPHA", DefaultLanguageHighlighterColors.IDENTIFIER) +// }; +// private static final TextAttributesKey[] INSTANCE_FIELDS = new TextAttributesKey[]{ +// createTextAttributesKey("ATTRIBUTE_NAME", DefaultLanguageHighlighterColors.INSTANCE_FIELD), +// createTextAttributesKey("PRIM_NAME", DefaultLanguageHighlighterColors.INSTANCE_FIELD) +// }; +// private static final TextAttributesKey[] KEYWORDS = new TextAttributesKey[]{ +// createTextAttributesKey("ADD", DefaultLanguageHighlighterColors.KEYWORD), +// createTextAttributesKey("ALPHA", DefaultLanguageHighlighterColors.KEYWORD), +// createTextAttributesKey("APPEND", DefaultLanguageHighlighterColors.KEYWORD), +// createTextAttributesKey("CLASS", DefaultLanguageHighlighterColors.KEYWORD), +// createTextAttributesKey("DEF", DefaultLanguageHighlighterColors.KEYWORD), +// createTextAttributesKey("DELETE", DefaultLanguageHighlighterColors.KEYWORD), +// createTextAttributesKey("OVER", DefaultLanguageHighlighterColors.KEYWORD), +// createTextAttributesKey("PREPEND", DefaultLanguageHighlighterColors.KEYWORD), +// +// }; +// private static final TextAttributesKey[] BAD_CHAR_KEYS = new TextAttributesKey[]{BAD_CHARACTER}; +// private static final TextAttributesKey[] COMMENT_KEYS = new TextAttributesKey[]{COMMENT}; +// private static final TextAttributesKey[] EMPTY_KEYS = new TextAttributesKey[0]; +// +// private static final IElementType[] USD_KEYWORDS = { +// USDTypes.ADD, +// USDTypes.ALPHA, +// USDTypes.APPEND, +// USDTypes.CLASS, +// USDTypes.DEF, +// USDTypes.DELETE, +// USDTypes.OVER, +// USDTypes.PREPEND +// }; + + private static final Map ATTRIBUTES = ContainerUtil.newHashMap(); + + static { + SyntaxHighlighterBase.fillMap(ATTRIBUTES, USDParserDefinition.USDDECLARATION, DefaultLanguageHighlighterColors.CONSTANT); + SyntaxHighlighterBase.fillMap(ATTRIBUTES, USDParserDefinition.BRACKETS, DefaultLanguageHighlighterColors.BRACKETS); + SyntaxHighlighterBase.fillMap(ATTRIBUTES, USDParserDefinition.KEYWORDS, DefaultLanguageHighlighterColors.KEYWORD); + SyntaxHighlighterBase.fillMap(ATTRIBUTES, USDParserDefinition.STRINGS, DefaultLanguageHighlighterColors.STRING); + SyntaxHighlighterBase.fillMap(ATTRIBUTES, USDParserDefinition.NUMBERS, DefaultLanguageHighlighterColors.NUMBER); + SyntaxHighlighterBase.fillMap(ATTRIBUTES, USDParserDefinition.LINE_COMMENTS, DefaultLanguageHighlighterColors.LINE_COMMENT); + SyntaxHighlighterBase.fillMap(ATTRIBUTES, USDParserDefinition.BLOCK_COMMENTS, DefaultLanguageHighlighterColors.BLOCK_COMMENT); + SyntaxHighlighterBase.fillMap(ATTRIBUTES, USDParserDefinition.IDENTIFIERS, DefaultLanguageHighlighterColors.IDENTIFIER); + SyntaxHighlighterBase.fillMap(ATTRIBUTES, USDParserDefinition.ASSETREFERENCES, USDHighlighterColors.ASSETREFERENCE_KEY); + SyntaxHighlighterBase.fillMap(ATTRIBUTES, USDParserDefinition.PATHREFERENCES, USDHighlighterColors.PATHREFERENCE_KEY); + } + + @NotNull + @Override + public Lexer getHighlightingLexer() { + return new USDLexerAdapter(); + } + + @NotNull + @Override + public TextAttributesKey[] getTokenHighlights(IElementType tokenType) { + return pack(ATTRIBUTES.get(tokenType)); + } + +} diff --git a/src/main/java/com/justint/usdidea/codeinsight/highlighting/USDSyntaxHighlighterFactory.java b/src/main/java/com/justint/usdidea/codeinsight/highlighting/USDSyntaxHighlighterFactory.java new file mode 100644 index 0000000..2bfc219 --- /dev/null +++ b/src/main/java/com/justint/usdidea/codeinsight/highlighting/USDSyntaxHighlighterFactory.java @@ -0,0 +1,16 @@ +package com.justint.usdidea.codeinsight.highlighting; + +import com.intellij.openapi.fileTypes.SyntaxHighlighter; +import com.intellij.openapi.fileTypes.SyntaxHighlighterFactory; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; + +public class USDSyntaxHighlighterFactory extends SyntaxHighlighterFactory { + + @NotNull + @Override + public SyntaxHighlighter getSyntaxHighlighter(Project project, VirtualFile virtualFile) { + return new USDSyntaxHighlighter(); + } +} diff --git a/src/main/java/com/justint/usdidea/file/USDFileType.java b/src/main/java/com/justint/usdidea/file/USDFileType.java new file mode 100644 index 0000000..d5bf363 --- /dev/null +++ b/src/main/java/com/justint/usdidea/file/USDFileType.java @@ -0,0 +1,41 @@ +package com.justint.usdidea.file; + +import com.intellij.openapi.fileTypes.LanguageFileType; +import com.justint.usdidea.util.USDIcons; +import com.justint.usdidea.lang.USDLanguage; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; + +public class USDFileType extends LanguageFileType { + public static final USDFileType INSTANCE = new USDFileType(); + + private USDFileType() { + super(USDLanguage.INSTANCE); + } + + @NotNull + @Override + public String getName() { + return "USD"; + } + + @NotNull + @Override + public String getDescription() { + return "Universal Scene Description File"; + } + + @NotNull + @Override + public String getDefaultExtension() { + return "usda"; + } + + @Nullable + @Override + public Icon getIcon() { + return USDIcons.FILE; + } +} diff --git a/src/main/java/com/justint/usdidea/file/USDFileTypeFactory.java b/src/main/java/com/justint/usdidea/file/USDFileTypeFactory.java new file mode 100644 index 0000000..2d536d1 --- /dev/null +++ b/src/main/java/com/justint/usdidea/file/USDFileTypeFactory.java @@ -0,0 +1,12 @@ +package com.justint.usdidea.file; + +import com.intellij.openapi.fileTypes.FileTypeConsumer; +import com.intellij.openapi.fileTypes.FileTypeFactory; +import org.jetbrains.annotations.NotNull; + +public class USDFileTypeFactory extends FileTypeFactory { + @Override + public void createFileTypes(@NotNull FileTypeConsumer fileTypeConsumer) { + fileTypeConsumer.consume(USDFileType.INSTANCE, "usd;usda"); + } +} diff --git a/src/main/java/com/justint/usdidea/lang/USD.bnf b/src/main/java/com/justint/usdidea/lang/USD.bnf new file mode 100644 index 0000000..816b8b3 --- /dev/null +++ b/src/main/java/com/justint/usdidea/lang/USD.bnf @@ -0,0 +1,244 @@ +{ + parserClass="com.justint.usdidea.lang.parser.USDParser" + + extends="com.intellij.extapi.psi.ASTWrapperPsiElement" + + psiClassPrefix="usd" + psiImplClassSuffix="Impl" + psiPackage="com.justint.usdidea.lang.psi" + psiImplPackage="com.justint.usdidea.lang.psi.impl" + + elementTypeHolderClass="com.justint.usdidea.lang.psi.USDTypes" + elementTypeClass="com.justint.usdidea.lang.psi.USDElementType" + tokenTypeClass="com.justint.usdidea.lang.psi.USDTokenType" + + tokens = [ + // + // + usdDeclaration = "regexp:#[^\r\n]*" + + // + // keywords + add = "add" + append = "append" + attributes = "attributes" + class = "class" + config = "config" + connect = "connect" + custom = "custom" + customData = "customData" + default = "default" + def = "def" + delete = "delete" + dictionary = "dictionary" + displayUnit = "displayUnit" + doc = "doc" + inherits = "inherits" + kind = "kind" + mapper = "mapper" + nameChildren = "nameChildren" + None = "None" + offset = "offset" + over = "over" + payload = "payload" + permission = "permission" + prefixSubstitutions = "prefixSubstitutions" + prepend = "prepend" + properties = "properties" + references = "references" + relocates = "relocates" + rel = "rel" + reorder = "reorder" + rootPrims = "rootPrims" + // TODO: re-enable scale as a token whenever the lexer can + // handle non-keyword instances (ie. transform.scale, transform.timeSamples, etc) + //scale = "scale" + subLayers = "subLayers" + suffixSubstitutions = "suffixSubstitutions" + specializes = "specializes" + symmetryArguments = "symmetryArguments" + symmetryFunction = "symmetryFunction" + // TODO: re-enable timeSamples as a token whenever the lexer can + // handle non-keyword instances (ie. transform.scale, transform.timeSamples, etc) + //timeSamples = "timeSamples" + uniform = "uniform" + variantSet = "variantSet" + variantSets = "variantSets" + variants = "variants" + varying = "varying" + + interpolation = "interpolation" + + // Includes the three-quotation docstrings + string = "regexp:\"\"\"[^\"]*\"\"\"|\"[^\"]*\"|'[^']*'" + number = "regexp:(\+|\-)?\p{Digit}+" + floatnumber = "regexp:(\+|\-)?\p{Digit}*\.(\p{Digit}+)?([eE][+\-]\p{Digit}+)?" + alpha = "regexp:\w+" + + // + // basic symbols + period = '.' + comma = ',' + colon = ':' + equals = '=' + leftbracket = '[' + rightbracket = ']' + leftparens = '(' + rightparens = ')' + leftbrace = '{' + rightbrace = '}' + + // + // types + // basic + booltype = 'bool' + uchartype = 'uchar' + inttype = 'int' + uinttype = 'uint' + int64type = 'int64' + uint64type = 'uint64' + halftype = 'half' + floattype = 'float' + doubletype = 'double' + stringtype = 'string' + tokentype = 'token' + assettype = 'asset' + matrix2dtype = 'matrix2d' + matrix3dtype = 'matrix3d' + matrix4dtype = 'matrix4d' + quatdtype = 'quatd' + quatftype = 'quatf' + quathtype = 'quath' + double2type = 'double2' + float2type = 'float2' + half2type = 'half2' + int2type = 'int2' + double3type = 'double3' + float3type = 'float3' + half3type = 'half3' + int3type = 'int3' + double4type = 'double4' + float4type = 'float4' + half4type = 'half4' + int4type = 'int4' + // role + point3dtype = 'point3d' + point3ftype = 'point3f' + point3htype = 'point3h' + normal3dtype = 'normal3d' + normal3ftype = 'normal3f' + normal3htype = 'normal3h' + vector3dtype = 'vector3d' + vector3ftype = 'vector3f' + vector3htype = 'vector3h' + color3dtype = 'color3d' + color3ftype = 'color3f' + color3htype = 'color3h' + color4dtype = 'color4d' + color4ftype = 'color4f' + color4htype = 'color4h' + frame4dtype = 'frame4d' + texCoord2htype = 'texCoord2h' + texCoord2dtype = 'texCoord2d' + texCoord2ftype = 'texCoord2f' + texCoord3htype = 'texCoord3h' + texCoord3dtype = 'texCoord3d' + texCoord3f = 'texCoord3f' + Transformtype = 'Transform' + PointIndextype = 'PointIndex' + EdgeIndextype = 'EdgeIndex' + FaceIndextype = 'FaceIndex' + + comment = "regexp://.*" + blockcomment = "regexp:/\*([^\*]|(\*+[^\*/]))*(\*+/)?" + + + assetReference = "regexp:@([^@]+)?@|@@@(([^@]|@{1,2}[^@]|\\@@@)+)?(@{0,2})@@@" + pathReference = "regexp:\<[^\<\>\r\n]*\>" + ] +} + + +// TODO: implement pin, etc for error recovery + + +usdFile ::= usdDeclaration Metadata? PrimSpec* + + +CompositionArc ::= subLayers | inherits | variantSets | references | payload | specializes + + +Identifier ::= alpha (alpha | number)* + +NamespacedIdentifier ::= Identifier (colon Identifier)+ + + +PrimSpec ::= Specifier Metadata? Body + +Specifier ::= def [Typename] PrimName | over PrimName | class [Typename] PrimName + +Typename ::= Identifier + +PrimName ::= string + +Body ::= leftbrace [!rightbrace (Property | PrimSpec)* ] rightbrace + + +Property ::= AttributeProperty | RelationshipProperty + +AttributeProperty ::= (uniform | custom)? (AttributeType AttributeName | CompositionArc) equals AttributeValue + + +RelationshipProperty ::= variantSet string equals VariantSetBody + +VariantSetBody ::= leftbrace [!rightbrace VariantSetKey VariantSetItemBody (VariantSetKey VariantSetItemBody)*] rightbrace | leftbrace rightbrace + +VariantSetKey ::= string + +VariantSetItemBody ::= Metadata? (leftbrace [!rightbrace PrimSpec (PrimSpec)*] rightbrace | leftbrace rightbrace) + + +AttributeType ::= ArrayAttributeType | SingleAttributeType | rel + +SingleAttributeType ::= BasicDataType | RoleDataType + +ArrayAttributeType ::= SingleAttributeType [leftbracket rightbracket] + +BasicDataType ::= booltype | uchartype | inttype | uinttype | int64type | uint64type | halftype | floattype | doubletype | stringtype | tokentype | assettype | matrix2dtype | matrix3dtype | matrix4dtype | quatdtype | quatftype | quathtype | double2type | float2type | half2type | int2type | double3type | float3type | half3type | int3type | double4type | float4type | half4type | int4type + +RoleDataType ::= point3dtype | point3ftype | point3htype | normal3dtype | normal3ftype | normal3htype | vector3dtype | vector3ftype | vector3htype | color3dtype | color3ftype | color3htype | color4dtype | color4ftype | color4htype | frame4dtype | texCoord2htype | texCoord2dtype | texCoord2ftype | texCoord3htype | texCoord3dtype | texCoord3ftype | Transformtype | PointIndextype | EdgeIndextype | FaceIndextype + +AttributeName ::= (NamespacedIdentifier | Identifier) (period Identifier)* + +AttributeValue ::= Item + + +Metadata ::= leftparens (!rightparens ( MetadataComment | [ListEditAction? MetadataKey equals MetadataValue]) )* rightparens + +ListEditAction ::= add | append | prepend | delete + + +MetadataKey ::= Identifier | CompositionArc | doc | variantSet | kind | variants + +MetadataValue ::= Item + +MetadataComment ::= string + + +Array ::= leftbracket [!rightbracket Item (comma Item)*] rightbracket | leftbracket rightbracket + +InterpolatedArray ::= Array (leftparens interpolation equals string rightparens)? + +Vector ::= leftparens [!rightparens Item? (comma Item)*] rightparens | leftparens rightparens + +Item ::= InterpolatedArray | Array | Vector | string | number | floatnumber | assetReference pathReference | assetReference | pathReference | Dict | TimeSample + +Dict ::= leftbrace [!rightbrace DictKey equals DictValue (DictKey equals DictValue)*] rightbrace | leftbrace rightbrace + +DictKey ::= AttributeType Identifier + +DictValue ::= Item + +TimeSample ::= leftbrace [!rightbrace FrameNumber colon Array (comma FrameNumber colon Array)* comma?] rightbrace | leftbrace rightbrace + +FrameNumber ::= number \ No newline at end of file diff --git a/src/main/java/com/justint/usdidea/lang/USDLanguage.java b/src/main/java/com/justint/usdidea/lang/USDLanguage.java new file mode 100644 index 0000000..8015f78 --- /dev/null +++ b/src/main/java/com/justint/usdidea/lang/USDLanguage.java @@ -0,0 +1,12 @@ +package com.justint.usdidea.lang; + +import com.intellij.lang.Language; + +public class USDLanguage extends Language { + + public static final USDLanguage INSTANCE = new USDLanguage(); + + private USDLanguage() { + super("USD"); + } +} diff --git a/src/main/java/com/justint/usdidea/lang/lexer/USDLexer.flex b/src/main/java/com/justint/usdidea/lang/lexer/USDLexer.flex new file mode 100644 index 0000000..3143f8b --- /dev/null +++ b/src/main/java/com/justint/usdidea/lang/lexer/USDLexer.flex @@ -0,0 +1,194 @@ +package com.justint.usdidea.lang.lexer; + +import com.intellij.lexer.FlexLexer; +import com.intellij.psi.tree.IElementType; + +import static com.intellij.psi.TokenType.BAD_CHARACTER; +import static com.intellij.psi.TokenType.WHITE_SPACE; +import static com.justint.usdidea.lang.psi.USDTypes.*; + +%% + +%{ + public USDLexer() { + this((java.io.Reader)null); + } +%} + +%public +%class USDLexer +%implements FlexLexer +%function advance +%type IElementType +%unicode + +EOL=\r|\n|\r\n +WHITE_SPACE=\s+ + +STRING=\"\"\"[^\"]*\"\"\"|\"[^\"]*\"|'[^']*' +NUMBER=(\+|\-)?[:digit:]+ +FLOATNUMBER=(\+|\-)?[:digit:]*\.([:digit:]+)?([eE][+\-][:digit:]+)? +ALPHA=[a-zA-Z_0-9]+ +COMMENT="//"[^\r\n]* +BLOCKCOMMENT="/"\*([^\*]|(\*+[^\*/]))*(\*+"/")? + +USDDECLARATION=#[^\r\n]* + +IDENTIFIER=[:alpha:][:alnum:]* +NAMESPACED_IDENTIFIER={IDENTIFIER}(\:{IDENTIFIER}*)+ + +ASSETREFERENCE=@([^@]+)?@|@@@(([^@]|@{1,2}[^@]|\\@@@)+)?(@{0,2})@@@ +PATHREFERENCE=\<[^\<\>\r\n]*\> + +//%state SLASHTERIX_COMMENT +%state METADATA + +%% + +// Multi-line comments +// "/*" { +// yybegin(SLASHTERIX_COMMENT); +// return COMMENT; +// } +// [^]|\n|\r { return COMMENT; } +// "*/" { +// yybegin(YYINITIAL); +// return COMMENT; +// } + +// TODO: Implement metadata blocks + + { + {EOL} { return WHITE_SPACE; } + {WHITE_SPACE} { return WHITE_SPACE; } + + "add" { return ADD; } + "append" { return APPEND; } + "attributes" { return ATTRIBUTES; } + "class" { return CLASS; } + "config" { return CONFIG; } + "connect" { return CONNECT; } + "custom" { return CUSTOM; } + "customData" { return CUSTOMDATA; } + "default" { return DEFAULT; } + "def" { return DEF; } + "delete" { return DELETE; } + "dictionary" { return DICTIONARY; } + "displayUnit" { return DISPLAYUNIT; } + "doc" { return DOC; } + "inherits" { return INHERITS; } + "kind" { return KIND; } + "mapper" { return MAPPER; } + "nameChildren" { return NAMECHILDREN; } + "None" { return NONE; } + "offset" { return OFFSET; } + "over" { return OVER; } + "payload" { return PAYLOAD; } + "permission" { return PERMISSION; } + "prefixSubstitutions" { return PREFIXSUBSTITUTIONS; } + "prepend" { return PREPEND; } + "properties" { return PROPERTIES; } + "references" { return REFERENCES; } + "relocates" { return RELOCATES; } + "rel" { return REL; } + "reorder" { return REORDER; } + "rootPrims" { return ROOTPRIMS; } + "subLayers" { return SUBLAYERS; } + "suffixSubstitutions" { return SUFFIXSUBSTITUTIONS; } + "specializes" { return SPECIALIZES; } + "symmetryArguments" { return SYMMETRYARGUMENTS; } + "symmetryFunction" { return SYMMETRYFUNCTION; } + "uniform" { return UNIFORM; } + "variantSet" { return VARIANTSET; } + "variantSets" { return VARIANTSETS; } + "variants" { return VARIANTS; } + "varying" { return VARYING; } + "interpolation" { return INTERPOLATION; } + "." { return PERIOD; } + "," { return COMMA; } + ":" { return COLON; } + "=" { return EQUALS; } + "[" { return LEFTBRACKET; } + "]" { return RIGHTBRACKET; } + "(" { return LEFTPARENS; } + ")" { return RIGHTPARENS; } + "{" { return LEFTBRACE; } + "}" { return RIGHTBRACE; } + "bool" { return BOOLTYPE; } + "uchar" { return UCHARTYPE; } + "int" { return INTTYPE; } + "uint" { return UINTTYPE; } + "int64" { return INT64TYPE; } + "uint64" { return UINT64TYPE; } + "half" { return HALFTYPE; } + "float" { return FLOATTYPE; } + "double" { return DOUBLETYPE; } + "string" { return STRINGTYPE; } + "token" { return TOKENTYPE; } + "asset" { return ASSETTYPE; } + "matrix2d" { return MATRIX2DTYPE; } + "matrix3d" { return MATRIX3DTYPE; } + "matrix4d" { return MATRIX4DTYPE; } + "quatd" { return QUATDTYPE; } + "quatf" { return QUATFTYPE; } + "quath" { return QUATHTYPE; } + "double2" { return DOUBLE2TYPE; } + "float2" { return FLOAT2TYPE; } + "half2" { return HALF2TYPE; } + "int2" { return INT2TYPE; } + "double3" { return DOUBLE3TYPE; } + "float3" { return FLOAT3TYPE; } + "half3" { return HALF3TYPE; } + "int3" { return INT3TYPE; } + "double4" { return DOUBLE4TYPE; } + "float4" { return FLOAT4TYPE; } + "half4" { return HALF4TYPE; } + "int4" { return INT4TYPE; } + "point3d" { return POINT3DTYPE; } + "point3f" { return POINT3FTYPE; } + "point3h" { return POINT3HTYPE; } + "normal3d" { return NORMAL3DTYPE; } + "normal3f" { return NORMAL3FTYPE; } + "normal3h" { return NORMAL3HTYPE; } + "vector3d" { return VECTOR3DTYPE; } + "vector3f" { return VECTOR3FTYPE; } + "vector3h" { return VECTOR3HTYPE; } + "color3d" { return COLOR3DTYPE; } + "color3f" { return COLOR3FTYPE; } + "color3h" { return COLOR3HTYPE; } + "color4d" { return COLOR4DTYPE; } + "color4f" { return COLOR4FTYPE; } + "color4h" { return COLOR4HTYPE; } + "frame4d" { return FRAME4DTYPE; } + "texCoord2h" { return TEXCOORD2HTYPE; } + "texCoord2d" { return TEXCOORD2DTYPE; } + "texCoord2f" { return TEXCOORD2FTYPE; } + "texCoord3h" { return TEXCOORD3HTYPE; } + "texCoord3d" { return TEXCOORD3DTYPE; } + "texCoord3f" { return TEXCOORD3F; } + "Transform" { return TRANSFORMTYPE; } + "PointIndex" { return POINTINDEXTYPE; } + "EdgeIndex" { return EDGEINDEXTYPE; } + "FaceIndex" { return FACEINDEXTYPE; } + "texCoord3ftype" { return TEXCOORD3FTYPE; } + + {USDDECLARATION} { return USDDECLARATION; } + + {IDENTIFIER} { return IDENTIFIER; } + {NAMESPACED_IDENTIFIER} { return NAMESPACED_IDENTIFIER; } + + {STRING} { return STRING; } + + "-inf" { return NUMBER; } + {NUMBER} { return NUMBER; } + {FLOATNUMBER} { return FLOATNUMBER; } + + {ALPHA} { return ALPHA; } + {COMMENT} { return COMMENT; } + {BLOCKCOMMENT} { return BLOCKCOMMENT; } + {ASSETREFERENCE} { return ASSETREFERENCE; } + {PATHREFERENCE} { return PATHREFERENCE; } + +} + +[^] { return BAD_CHARACTER; } diff --git a/src/main/java/com/justint/usdidea/lang/lexer/USDLexerAdapter.java b/src/main/java/com/justint/usdidea/lang/lexer/USDLexerAdapter.java new file mode 100644 index 0000000..bcaf4f3 --- /dev/null +++ b/src/main/java/com/justint/usdidea/lang/lexer/USDLexerAdapter.java @@ -0,0 +1,12 @@ +package com.justint.usdidea.lang.lexer; + +import com.intellij.lexer.FlexAdapter; + +import java.io.Reader; + + +public class USDLexerAdapter extends FlexAdapter { + public USDLexerAdapter() { + super(new USDLexer((Reader) null)); + } +} diff --git a/src/main/java/com/justint/usdidea/lang/lexer/_USDLexer.flex b/src/main/java/com/justint/usdidea/lang/lexer/_USDLexer.flex new file mode 100644 index 0000000..f6ab433 --- /dev/null +++ b/src/main/java/com/justint/usdidea/lang/lexer/_USDLexer.flex @@ -0,0 +1,163 @@ +package com.justint.usdidea; + +import com.intellij.psi.tree.IElementType; + +import static com.intellij.psi.TokenType.BAD_CHARACTER; +import static com.intellij.psi.TokenType.WHITE_SPACE; +import static com.justint.usdidea.lang.psi.USDTypes.*; + +%% + +%{ + public _USDLexer() { + this((java.io.Reader)null); + } +%} + +%public +%class _USDLexer +%implements FlexLexer +%function advance +%type IElementType +%unicode + +EOL=\R +WHITE_SPACE=\s+ + +USDDECLARATION=#[^\r\n]* +STRING=\"\"\"[^\"]*\"\"\"|\"[^\"]*\"|'[^']*' +NUMBER=(\+|\-)?[:digit:]+ +FLOATNUMBER=(\+|\-)?[:digit:]*\.([:digit:]+)?([eE][+\-][:digit:]+)? +ALPHA=[a-zA-Z_0-9]+ +COMMENT="//".* +BLOCKCOMMENT="/"\*([^\*]|(\*+[^\*/]))*(\*+"/")? +ASSETREFERENCE=@([^@]+)?@|@@@(([^@]|@{1,2}[^@]|\\@@@)+)?(@{0,2})@@@ +PATHREFERENCE=\<[^\<\>\r\n]*\> + +%% + { + {WHITE_SPACE} { return WHITE_SPACE; } + + "add" { return ADD; } + "append" { return APPEND; } + "attributes" { return ATTRIBUTES; } + "class" { return CLASS; } + "config" { return CONFIG; } + "connect" { return CONNECT; } + "custom" { return CUSTOM; } + "customData" { return CUSTOMDATA; } + "default" { return DEFAULT; } + "def" { return DEF; } + "delete" { return DELETE; } + "dictionary" { return DICTIONARY; } + "displayUnit" { return DISPLAYUNIT; } + "doc" { return DOC; } + "inherits" { return INHERITS; } + "kind" { return KIND; } + "mapper" { return MAPPER; } + "nameChildren" { return NAMECHILDREN; } + "None" { return NONE; } + "offset" { return OFFSET; } + "over" { return OVER; } + "payload" { return PAYLOAD; } + "permission" { return PERMISSION; } + "prefixSubstitutions" { return PREFIXSUBSTITUTIONS; } + "prepend" { return PREPEND; } + "properties" { return PROPERTIES; } + "references" { return REFERENCES; } + "relocates" { return RELOCATES; } + "rel" { return REL; } + "reorder" { return REORDER; } + "rootPrims" { return ROOTPRIMS; } + "subLayers" { return SUBLAYERS; } + "suffixSubstitutions" { return SUFFIXSUBSTITUTIONS; } + "specializes" { return SPECIALIZES; } + "symmetryArguments" { return SYMMETRYARGUMENTS; } + "symmetryFunction" { return SYMMETRYFUNCTION; } + "uniform" { return UNIFORM; } + "variantSet" { return VARIANTSET; } + "variantSets" { return VARIANTSETS; } + "variants" { return VARIANTS; } + "varying" { return VARYING; } + "interpolation" { return INTERPOLATION; } + "." { return PERIOD; } + "," { return COMMA; } + ":" { return COLON; } + "=" { return EQUALS; } + "[" { return LEFTBRACKET; } + "]" { return RIGHTBRACKET; } + "(" { return LEFTPARENS; } + ")" { return RIGHTPARENS; } + "{" { return LEFTBRACE; } + "}" { return RIGHTBRACE; } + "bool" { return BOOLTYPE; } + "uchar" { return UCHARTYPE; } + "int" { return INTTYPE; } + "uint" { return UINTTYPE; } + "int64" { return INT64TYPE; } + "uint64" { return UINT64TYPE; } + "half" { return HALFTYPE; } + "float" { return FLOATTYPE; } + "double" { return DOUBLETYPE; } + "string" { return STRINGTYPE; } + "token" { return TOKENTYPE; } + "asset" { return ASSETTYPE; } + "matrix2d" { return MATRIX2DTYPE; } + "matrix3d" { return MATRIX3DTYPE; } + "matrix4d" { return MATRIX4DTYPE; } + "quatd" { return QUATDTYPE; } + "quatf" { return QUATFTYPE; } + "quath" { return QUATHTYPE; } + "double2" { return DOUBLE2TYPE; } + "float2" { return FLOAT2TYPE; } + "half2" { return HALF2TYPE; } + "int2" { return INT2TYPE; } + "double3" { return DOUBLE3TYPE; } + "float3" { return FLOAT3TYPE; } + "half3" { return HALF3TYPE; } + "int3" { return INT3TYPE; } + "double4" { return DOUBLE4TYPE; } + "float4" { return FLOAT4TYPE; } + "half4" { return HALF4TYPE; } + "int4" { return INT4TYPE; } + "point3d" { return POINT3DTYPE; } + "point3f" { return POINT3FTYPE; } + "point3h" { return POINT3HTYPE; } + "normal3d" { return NORMAL3DTYPE; } + "normal3f" { return NORMAL3FTYPE; } + "normal3h" { return NORMAL3HTYPE; } + "vector3d" { return VECTOR3DTYPE; } + "vector3f" { return VECTOR3FTYPE; } + "vector3h" { return VECTOR3HTYPE; } + "color3d" { return COLOR3DTYPE; } + "color3f" { return COLOR3FTYPE; } + "color3h" { return COLOR3HTYPE; } + "color4d" { return COLOR4DTYPE; } + "color4f" { return COLOR4FTYPE; } + "color4h" { return COLOR4HTYPE; } + "frame4d" { return FRAME4DTYPE; } + "texCoord2h" { return TEXCOORD2HTYPE; } + "texCoord2d" { return TEXCOORD2DTYPE; } + "texCoord2f" { return TEXCOORD2FTYPE; } + "texCoord3h" { return TEXCOORD3HTYPE; } + "texCoord3d" { return TEXCOORD3DTYPE; } + "texCoord3f" { return TEXCOORD3F; } + "Transform" { return TRANSFORMTYPE; } + "PointIndex" { return POINTINDEXTYPE; } + "EdgeIndex" { return EDGEINDEXTYPE; } + "FaceIndex" { return FACEINDEXTYPE; } + "texCoord3ftype" { return TEXCOORD3FTYPE; } + + {USDDECLARATION} { return USDDECLARATION; } + {STRING} { return STRING; } + {NUMBER} { return NUMBER; } + {FLOATNUMBER} { return FLOATNUMBER; } + {ALPHA} { return ALPHA; } + {COMMENT} { return COMMENT; } + {BLOCKCOMMENT} { return BLOCKCOMMENT; } + {ASSETREFERENCE} { return ASSETREFERENCE; } + {PATHREFERENCE} { return PATHREFERENCE; } + +} + +[^] { return BAD_CHARACTER; } diff --git a/src/main/java/com/justint/usdidea/lang/parser/USDParserDefinition.java b/src/main/java/com/justint/usdidea/lang/parser/USDParserDefinition.java new file mode 100644 index 0000000..a672694 --- /dev/null +++ b/src/main/java/com/justint/usdidea/lang/parser/USDParserDefinition.java @@ -0,0 +1,133 @@ +package com.justint.usdidea.lang.parser; + +import com.intellij.lang.*; +import com.intellij.lexer.Lexer; +import com.intellij.openapi.project.Project; +import com.intellij.psi.*; +import com.intellij.psi.tree.IFileElementType; +import com.intellij.psi.tree.TokenSet; +import com.justint.usdidea.lang.parser.USDParser; +import com.justint.usdidea.lang.USDLanguage; +import com.justint.usdidea.lang.lexer.USDLexerAdapter; +import com.justint.usdidea.lang.psi.*; +import org.jetbrains.annotations.NotNull; + +public class USDParserDefinition implements ParserDefinition { + public static final TokenSet USDDECLARATION = TokenSet.create(USDTypes.USDDECLARATION); + + public static final TokenSet ASSETREFERENCES = TokenSet.create(USDTypes.ASSETREFERENCE); + + public static final TokenSet PATHREFERENCES = TokenSet.create(USDTypes.PATHREFERENCE); + + public static final TokenSet WHITE_SPACES = TokenSet.create(TokenType.WHITE_SPACE); + + public static final TokenSet LINE_COMMENTS = TokenSet.create(USDTypes.COMMENT); + + public static final TokenSet BLOCK_COMMENTS = TokenSet.create(USDTypes.BLOCKCOMMENT); + + public static final TokenSet STRINGS = TokenSet.create(USDTypes.STRING); + + public static final TokenSet NUMBERS = TokenSet.create( + USDTypes.NUMBER, + USDTypes.FLOATNUMBER + ); + + public static final TokenSet BRACKETS = TokenSet.create( + USDTypes.LEFTBRACE, USDTypes.RIGHTBRACE, + USDTypes.LEFTBRACKET, USDTypes.RIGHTBRACKET, + USDTypes.LEFTPARENS, USDTypes.RIGHTPARENS + ); + + public static final TokenSet IDENTIFIERS = TokenSet.create(USDTypes.IDENTIFIER); + + public static final TokenSet KEYWORDS = TokenSet.create( + USDTypes.ADD, + USDTypes.APPEND, + USDTypes.ATTRIBUTES, + USDTypes.CLASS, + USDTypes.CONFIG, + USDTypes.CONNECT, + USDTypes.CUSTOM, + USDTypes.CUSTOMDATA, + USDTypes.DEFAULT, + USDTypes.DEF, + USDTypes.DELETE, + USDTypes.DICTIONARY, + USDTypes.DISPLAYUNIT, + USDTypes.DOC, + USDTypes.INHERITS, + USDTypes.KIND, + USDTypes.MAPPER, + USDTypes.NAMECHILDREN, + USDTypes.NONE, + USDTypes.OFFSET, + USDTypes.OVER, + USDTypes.PAYLOAD, + USDTypes.PERMISSION, + USDTypes.PREFIXSUBSTITUTIONS, + USDTypes.PREPEND, + USDTypes.PROPERTIES, + USDTypes.REFERENCES, + USDTypes.RELOCATES, + USDTypes.REL, + USDTypes.REORDER, + USDTypes.ROOTPRIMS, + USDTypes.SUBLAYERS, + USDTypes.SUFFIXSUBSTITUTIONS, + USDTypes.SPECIALIZES, + USDTypes.SYMMETRYARGUMENTS, + USDTypes.SYMMETRYFUNCTION, + USDTypes.UNIFORM, + USDTypes.VARIANTSET, + USDTypes.VARIANTSETS, + USDTypes.VARIANTS, + USDTypes.VARYING + ); + + public static final IFileElementType FILE = new IFileElementType(USDLanguage.INSTANCE); + + @NotNull + @Override + public Lexer createLexer(Project project) { + return new USDLexerAdapter(); + } + + @NotNull + public TokenSet getWhitespaceTokens() { + return WHITE_SPACES; + } + + @NotNull + public TokenSet getCommentTokens() { + return LINE_COMMENTS; + } + + @NotNull + public TokenSet getStringLiteralElements() { + return TokenSet.EMPTY; + } + + @NotNull + public PsiParser createParser(final Project project) { + return new USDParser(); + } + + @Override + public IFileElementType getFileNodeType() { + return FILE; + } + + public PsiFile createFile(FileViewProvider viewProvider) { + return new USDFile(viewProvider); + } + + public SpaceRequirements spaceExistanceTypeBetweenTokens(ASTNode left, ASTNode right) { + return SpaceRequirements.MAY; + } + + @NotNull + public PsiElement createElement(ASTNode node) { + return USDTypes.Factory.createElement(node); + } + +} diff --git a/src/main/java/com/justint/usdidea/lang/psi/USDElementType.java b/src/main/java/com/justint/usdidea/lang/psi/USDElementType.java new file mode 100644 index 0000000..34a4a64 --- /dev/null +++ b/src/main/java/com/justint/usdidea/lang/psi/USDElementType.java @@ -0,0 +1,12 @@ +package com.justint.usdidea.lang.psi; + +import com.intellij.psi.tree.IElementType; +import com.justint.usdidea.lang.USDLanguage; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; + +public class USDElementType extends IElementType { + public USDElementType(@NotNull @NonNls String debugName) { + super(debugName, USDLanguage.INSTANCE); + } +} diff --git a/src/main/java/com/justint/usdidea/lang/psi/USDFile.java b/src/main/java/com/justint/usdidea/lang/psi/USDFile.java new file mode 100644 index 0000000..7c4287b --- /dev/null +++ b/src/main/java/com/justint/usdidea/lang/psi/USDFile.java @@ -0,0 +1,32 @@ +package com.justint.usdidea.lang.psi; + +import com.intellij.extapi.psi.PsiFileBase; +import com.intellij.openapi.fileTypes.FileType; +import com.intellij.psi.FileViewProvider; +import com.justint.usdidea.file.USDFileType; +import com.justint.usdidea.lang.USDLanguage; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; + +public class USDFile extends PsiFileBase { + public USDFile(@NotNull FileViewProvider viewProvider) { + super(viewProvider, USDLanguage.INSTANCE); + } + + @NotNull + @Override + public FileType getFileType() { + return USDFileType.INSTANCE; + } + + @Override + public String toString() { + return "Universal Scene Description"; + } + + @Override + public Icon getIcon(int flags) { + return super.getIcon(flags); + } +} diff --git a/src/main/java/com/justint/usdidea/lang/psi/USDTokenType.java b/src/main/java/com/justint/usdidea/lang/psi/USDTokenType.java new file mode 100644 index 0000000..22957be --- /dev/null +++ b/src/main/java/com/justint/usdidea/lang/psi/USDTokenType.java @@ -0,0 +1,17 @@ +package com.justint.usdidea.lang.psi; + +import com.intellij.psi.tree.IElementType; +import com.justint.usdidea.lang.USDLanguage; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; + +public class USDTokenType extends IElementType { + public USDTokenType(@NotNull @NonNls String debugName) { + super(debugName, USDLanguage.INSTANCE); + } + + @Override + public String toString() { + return "USDTokenType." + super.toString(); + } +} diff --git a/src/main/java/com/justint/usdidea/util/USDIcons.java b/src/main/java/com/justint/usdidea/util/USDIcons.java new file mode 100644 index 0000000..aa65a0a --- /dev/null +++ b/src/main/java/com/justint/usdidea/util/USDIcons.java @@ -0,0 +1,9 @@ +package com.justint.usdidea.util; + +import com.intellij.openapi.util.IconLoader; + +import javax.swing.*; + +public class USDIcons { + public static final Icon FILE = IconLoader.getIcon("/com/justint/usdidea/icons/usd-file.svg"); +} diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index da8f95a..6e6a630 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -29,11 +29,11 @@ - - - + + + - +