diff options
-rw-r--r-- | pygments/lexers/apdlexer.py | 179 | ||||
-rw-r--r-- | tests/examplefiles/apdl/example1apdl.ans.output | 40 | ||||
-rw-r--r-- | tests/examplefiles/apdl/example2apdl.ans | 18 | ||||
-rw-r--r-- | tests/examplefiles/apdl/example2apdl.ans.output | 52 |
4 files changed, 206 insertions, 83 deletions
diff --git a/pygments/lexers/apdlexer.py b/pygments/lexers/apdlexer.py index 74ef7511..b7aae75c 100644 --- a/pygments/lexers/apdlexer.py +++ b/pygments/lexers/apdlexer.py @@ -10,9 +10,9 @@ import re -from pygments.lexer import RegexLexer, include, words +from pygments.lexer import RegexLexer, include, words, default from pygments.token import Comment, Keyword, Name, Number, Operator, \ - String, Generic, Punctuation, Whitespace + String, Generic, Punctuation, Whitespace, Escape __all__ = ['apdlexer'] @@ -144,7 +144,7 @@ class apdlexer(RegexLexer): "CMDELE", "CMDOMEGA", "CMEDIT", "CMGRP", "CMLIST", "CMMOD", "CMOMEGA", "CMPLOT", "CMROTATE", "CMSEL", "CMSFILE", "CMSOPT", "CMWRITE", "CNCHECK", "CNKMOD", - "CNTR", "CNVTOL", "/COLOR", "/COM", "*COMP", "COMBINE", + "CNTR", "CNVTOL", "/COLOR", "*COMP", "COMBINE", "COMPRESS", "CON4", "CONE", "/CONFIG", "CONJUG", "/CONTOUR", "/COPY", "CORIOLIS", "COUPLE", "COVAL", "CP", "CPCYC", "CPDELE", "CPINTF", "/CPLANE", "CPLGEN", @@ -158,7 +158,7 @@ class apdlexer(RegexLexer): "DADELE", "DALIST", "DAMORPH", "DATA", "DATADEF", "DCGOMG", "DCUM", "DCVSWP", "DDASPEC", "DDELE", "DDOPTION", "DEACT", "DEFINE", "*DEL", "DELETE", - "/DELETE", "DELTIM", "DEMORPH", "DERIV", "DESIZE", + "/DELETE", "DELTIM", "DELTIME", "DEMORPH", "DERIV", "DESIZE", "DESOL", "DETAB", "/DEVDISP", "/DEVICE", "/DFLAB", "DFLX", "DFSWAVE", "DIG", "DIGIT", "*DIM", "/DIRECTORY", "DISPLAY", "/DIST", "DJ", "DJDELE", @@ -350,7 +350,7 @@ class apdlexer(RegexLexer): "SSBT", "/SSCALE", "SSLN", "SSMT", "SSPA", "SSPB", "SSPD", "SSPE", "SSPM", "SSUM", "SSTATE", "STABILIZE", "STAOPT", "STAT", "*STATUS", "/STATUS", "STEF", - "/STITLE", "STORE", "SUBOPT", "SUBSET", "SUCALC", + "STORE", "SUBOPT", "SUBSET", "SUCALC", "SUCR", "SUDEL", "SUEVAL", "SUGET", "SUMAP", "SUMTYPE", "SUPL", "SUPR", "SURESU", "SUSAVE", "SUSEL", "SUVECT", "SV", "SVPLOT", "SVTYP", "SWADD", "SWDEL", "SWGEN", @@ -359,13 +359,13 @@ class apdlexer(RegexLexer): "TBEO", "TBIN", "TBFIELD", "TBFT", "TBLE", "TBLIST", "TBMODIF", "TBPLOT", "TBPT", "TBTEMP", "TCHG", "/TEE", "TERM", "THEXPAND", "THOPT", "TIFF", "TIME", - "TIMERANGE", "TIMINT", "TIMP", "TINTP", "/TITLE", + "TIMERANGE", "TIMINT", "TIMP", "TINTP", "/TLABEL", "TOFFST", "*TOPER", "TORQ2D", "TORQC2D", "TORQSUM", "TORUS", "TRANS", "TRANSFER", "*TREAD", "TREF", "/TRIAD", "/TRLCY", "TRNOPT", "TRPDEL", "TRPLIS", "TRPOIN", "TRTIME", "TSHAP", "/TSPEC", "TSRES", "TUNIF", "TVAR", "/TXTRE", "/TYPE", "TYPE", - "/UCMD", "/UDOC", "/UI", "UIMP", "/UIS", "*ULIB", + "/UCMD", "/UDOC", "/UI", "UIMP", "/UIS", "*ULIB", "/UPF", "UNDELETE", "UNDO", "/UNITS", "UNPAUSE", "UPCOORD", "UPGEOM", "*USE", "/USER", "USRCAL", "USRDOF", "USRELEM", "V", "V2DOPT", "VA", "*VABS", "VADD", @@ -416,23 +416,168 @@ class apdlexer(RegexLexer): "/ANNOT", "ANORM", "ANPRES", "ANSOL", "ANSTOAQWA", "ANSTOASAS", "ANTIME", "ANTYPE") + special = ("/COM", "/TITLE", "STITLE") + + elements = ("SOLID5", + "LINK11", + "PLANE13", + "COMBIN14", + "MASS2", + "PLANE25", + "MATRIX27", + "FLUID29", + "FLUID30", + "LINK31", + "LINK33", + "LINK34", + "PLANE35", + "SOURC36", + "COMBIN37", + "FLUID38", + "COMBIN39", + "COMBIN40", + "INFIN47", + "MATRIX50", + "PLANE55", + "SHELL61", + "LINK68", + "SOLID70", + "MASS71", + "PLANE75", + "PLANE77", + "PLANE78", + "PLANE83", + "SOLID87", + "SOLID90", + "CIRCU94", + "SOLID96", + "SOLID98", + "INFIN110", + "INFIN111", + "FLUID116", + "PLANE121", + "SOLID122", + "SOLID123", + "CIRCU124", + "CIRCU125", + "TRANS126", + "FLUID129", + "FLUID130", + "SHELL131", + "SHELL132", + "FLUID136", + "FLUID138", + "FLUID139", + "SURF151", + "SURF152", + "SURF153", + "SURF154", + "SURF155", + "SURF156", + "SHELL157", + "SURF159", + "TARGE169", + "TARGE170", + "CONTA172", + "CONTA174", + "CONTA175", + "CONTA177", + "CONTA178", + "PRETS179", + "LINK180", + "SHELL181", + "PLANE182", + "PLANE183", + "MPC184", + "SOLID185", + "SOLID186", + "SOLID187", + "BEAM188", + "BEAM189", + "SOLSH190", + "INTER192", + "INTER193", + "INTER194", + "INTER195", + "MESH200", + "FOLLW201", + "INTER202", + "INTER203", + "INTER204", + "INTER205", + "SHELL208", + "SHELL209", + "CPT212", + "CPT213", + "COMBI214", + "CPT215", + "CPT216", + "CPT217", + "FLUID218", + "FLUID220", + "FLUID221", + "PLANE222", + "PLANE223", + "SOLID225", + "SOLID226", + "SOLID227", + "PLANE230", + "SOLID231", + "SOLID232", + "PLANE233", + "SOLID236", + "SOLID237", + "PLANE238", + "SOLID239", + "SOLID240", + "HSFLD241", + "HSFLD242", + "COMBI250", + "SURF251", + "SURF252", + "INFIN257", + "REINF263", + "REINF264", + "REINF265", + "SOLID272", + "SOLID273", + "SOLID278", + "SOLID279", + "CABLE280", + "SHELL281", + "SOLID285", + "PIPE288", + "PIPE289", + "ELBOW290", + "SOLID291", + "PLANE292", + "PLANE293", + "USER300") + tokens = { 'root': [ - (r'!.*\n', Comment), + (r'[^\S\n]+', Whitespace), + (words((elafunb+elafunc+elafund+elafune+elafunh+special), suffix=r'\b'), Keyword, 'non-keyword'), + default('non-keyword'), + ], + 'non-keyword': [ + (r'!.*\n', Comment, '#pop'), + (r'%.*?%', Escape), include('strings'), - include('core'), include('nums'), - (words((elafunb+elafunc+elafund+elafune+elafunh), suffix=r'\b'), Keyword), (words((elafunf+elafung), suffix=r'\b'), Name.Builtin), + (words((elements), suffix=r'\b'), Name.Property), + include('core'), (r'AR[0-9]+', Name.Variable.Instance), - (r'[a-z][a-z0-9_]*', Name.Variable), - (r'[\s]+', Whitespace), + (r'[a-z_][a-z0-9_]*', Name.Variable), + (r'\n+', Whitespace, '#pop'), + (r'[^\S\n]+', Whitespace), ], 'core': [ # Operators - (r'(\*\*|\*|\+|-|\/|<|>|<=|>=|==|\/=|=)', Operator), + (r'(\*\*|\*|\+|-|\/|<|>|<=|>=|==|\/=|=|\(|\))', Operator), (r'/EOF', Generic.Emph), - (r'[(),:&;]', Punctuation), + (r'[\.(),:&;]', Punctuation), ], 'strings': [ (r'(?s)"(\\\\|\\[0-7]+|\\.|[^"\\])*"', String.Double), @@ -440,8 +585,8 @@ class apdlexer(RegexLexer): (r'[$%]', String.Symbol), ], 'nums': [ - (r'\d+(?![.ef])', Number.Integer), - (r'[+-]?\d*\.?\d+([ef][-+]?\d+)?', Number.Float), - (r'[+-]?\d+\.?\d*([ef][-+]?\d+)?', Number.Float), + (r'[+-]?\d*\.\d+([efEF][-+]?\d+)?', Number.Float), # with dot + (r'([+-]?\d+([efEF][-+]?\d+))', Number.Float), # With scientific notation + (r'\b\d+(?![.ef])', Number.Integer), # integer simple ] } diff --git a/tests/examplefiles/apdl/example1apdl.ans.output b/tests/examplefiles/apdl/example1apdl.ans.output index 2a1c3fe9..73d55fa3 100644 --- a/tests/examplefiles/apdl/example1apdl.ans.output +++ b/tests/examplefiles/apdl/example1apdl.ans.output @@ -1,12 +1,10 @@ 'finish' Keyword '\n' Text.Whitespace -'/' Operator -'clear' Name.Variable +'/clear' Keyword '\n\n' Text.Whitespace -'/' Operator -'title' Name.Variable +'/title' Keyword ',' Punctuation ' ' Text.Whitespace 'Thermal' Name.Variable @@ -16,13 +14,11 @@ 'Example' Name.Variable '\n' Text.Whitespace -'/' Operator -'prep7' Name.Variable +'/prep7' Keyword '\t\t\t\t\t' Text.Whitespace '! Enter preprocessor\n' Comment -'*' Operator -'VOPER' Name.Variable +'*VOPER' Keyword ',' Punctuation 'test' Name.Variable '\n\n' Text.Whitespace @@ -60,7 +56,7 @@ ',' Punctuation '1' Literal.Number.Integer ',' Punctuation -'link33' Name.Variable +'link33' Name.Property '\t\t\t\t' Text.Whitespace '! Element type\n' Comment @@ -79,8 +75,7 @@ ',' Punctuation '1' Literal.Number.Integer ',' Punctuation -'6' Literal.Number.Integer -'0.5' Literal.Number.Float +'60.5' Literal.Number.Float '\t\t\t\t' Text.Whitespace '! Thermal conductivity\n' Comment @@ -100,7 +95,7 @@ 'physics' Keyword ',' Punctuation -'write' Keyword +'write' Name.Variable ',' Punctuation 'thermal' Name.Variable '\t\t\t' Text.Whitespace @@ -126,8 +121,7 @@ ',' Punctuation '1' Literal.Number.Integer ',' Punctuation -'20' Literal.Number.Integer -'0e9' Literal.Number.Float +'200e9' Literal.Number.Float '\t\t\t\t' Text.Whitespace "! Young's modulus\n" Comment @@ -147,14 +141,13 @@ ',' Punctuation '1' Literal.Number.Integer ',' Punctuation -'1' Literal.Number.Integer -'2e-6' Literal.Number.Float +'12e-6' Literal.Number.Float '\t\t\t\t' Text.Whitespace '! Expansion coefficient\n' Comment 'physics' Keyword ',' Punctuation -'write' Keyword +'write' Name.Variable ',' Punctuation 'struct' Name.Variable '\t\t\t' Text.Whitespace @@ -168,8 +161,7 @@ 'finish' Keyword '\n\n' Text.Whitespace -'/' Operator -'solu' Keyword +'/solu' Keyword '\t\t\t\t\t' Text.Whitespace '! Enter the solution phase\n' Comment @@ -181,7 +173,7 @@ 'physics' Keyword ',' Punctuation -'read' Keyword +'read' Name.Variable ',' Punctuation 'thermal' Name.Variable '\t\t\t' Text.Whitespace @@ -205,14 +197,13 @@ 'finish' Keyword '\n\n' Text.Whitespace -'/' Operator -'solu' Keyword +'/solu' Keyword '\t\t\t\t\t' Text.Whitespace '! Re-enter the solution phase\n' Comment 'physics' Keyword ',' Punctuation -'read' Keyword +'read' Name.Variable ',' Punctuation 'struct' Name.Variable '\t\t\t' Text.Whitespace @@ -263,8 +254,7 @@ 'finish' Keyword '\n\n' Text.Whitespace -'/' Operator -'post1' Name.Variable +'/post1' Keyword '\t\t\t\t\t' Text.Whitespace '! Enter postprocessor\n' Comment diff --git a/tests/examplefiles/apdl/example2apdl.ans b/tests/examplefiles/apdl/example2apdl.ans index 238b62e7..a49039fe 100644 --- a/tests/examplefiles/apdl/example2apdl.ans +++ b/tests/examplefiles/apdl/example2apdl.ans @@ -1,19 +1,19 @@ ! ANSYS command file to perform 2D Truss Tutorial (Chandrupatla p.123) ! -/title, Bridge Truss Tutorial + /title, Bridge Truss Tutorial /PREP7 ! preprocessor phase ! ! define parameters (mm) height = 3118 width = 3600 ! -! define keypoints +! define keypoints ! K,1, 0, 0 ! keypoint, #, x, y -K,2, width/2,height +K,2, width/2,height K,3, width, 0 K,4, 3*width/2, height -K,5, 2*width, 0 +K,5, 2*width, 0 K,6, 5*width/2, height K,7, 3*width, 0 ! @@ -30,7 +30,7 @@ L,4,6 L,5,6 L,5,7 L,6,7 - + ! ! element definition ! @@ -47,14 +47,14 @@ FINISH ! finish pre-processor ! ! apply some constraints DK,1,ALL,0 ! define a DOF constraint at a keypoint -DK,7,UY,0 +DK,7,UY,0 ! ! apply loads ! FK,1,FY,-280e3 ! define a force load to a keypoint -FK,3,FY,-210e3 -FK,5,FY,-280e3 -FK,7,FY,-360e3 +FK,3,FY,-210e3 +FK,5,FY,-280e3 +FK,7,FY,-360e3 ! SOLVE ! solve the resulting system of equations FINISH ! finish solution diff --git a/tests/examplefiles/apdl/example2apdl.ans.output b/tests/examplefiles/apdl/example2apdl.ans.output index f964f25b..aa07e58c 100644 --- a/tests/examplefiles/apdl/example2apdl.ans.output +++ b/tests/examplefiles/apdl/example2apdl.ans.output @@ -2,8 +2,8 @@ '!\n' Comment -'/' Operator -'title' Name.Variable +' ' Text.Whitespace +'/title' Keyword ',' Punctuation ' ' Text.Whitespace 'Bridge' Name.Variable @@ -13,8 +13,7 @@ 'Tutorial' Name.Variable '\n' Text.Whitespace -'/' Operator -'PREP7' Name.Variable +'/PREP7' Keyword ' ' Text.Whitespace '! preprocessor phase\n' Comment @@ -38,7 +37,7 @@ '!\n' Comment -'! define keypoints \n' Comment +'! define keypoints\n' Comment '!\n' Comment @@ -64,7 +63,7 @@ '2' Literal.Number.Integer ',' Punctuation 'height' Name.Variable -' \n' Text.Whitespace +'\n' Text.Whitespace 'K' Keyword ',' Punctuation @@ -103,7 +102,7 @@ ',' Punctuation ' ' Text.Whitespace '0' Literal.Number.Integer -' \n' Text.Whitespace +'\n' Text.Whitespace 'K' Keyword ',' Punctuation @@ -215,7 +214,7 @@ '6' Literal.Number.Integer ',' Punctuation '7' Literal.Number.Integer -'\n \n' Text.Whitespace +'\n\n' Text.Whitespace '!\n' Comment @@ -227,7 +226,7 @@ ',' Punctuation '1' Literal.Number.Integer ',' Punctuation -'LINK1' Keyword +'LINK1' Name.Variable ' ' Text.Whitespace '! element type #1; spring element\n' Comment @@ -245,8 +244,7 @@ ',' Punctuation '1' Literal.Number.Integer ',' Punctuation -'20' Literal.Number.Integer -'0e3' Literal.Number.Float +'200e3' Literal.Number.Float ' ' Text.Whitespace "! material property #1; Young's modulus: 200 GPa\n" Comment @@ -282,8 +280,7 @@ '!\n' Comment -'/' Operator -'SOLU' Keyword +'/SOLU' Keyword ' ' Text.Whitespace '! enter solution phase\n' Comment @@ -308,7 +305,7 @@ 'UY' Name.Variable ',' Punctuation '0' Literal.Number.Integer -' \n' Text.Whitespace +'\n' Text.Whitespace '!\n' Comment @@ -322,9 +319,7 @@ ',' Punctuation 'FY' Name.Variable ',' Punctuation -'-' Operator -'28' Literal.Number.Integer -'0e3' Literal.Number.Float +'-280e3' Literal.Number.Float ' ' Text.Whitespace '! define a force load to a keypoint\n' Comment @@ -334,10 +329,8 @@ ',' Punctuation 'FY' Name.Variable ',' Punctuation -'-' Operator -'21' Literal.Number.Integer -'0e3' Literal.Number.Float -' \n' Text.Whitespace +'-210e3' Literal.Number.Float +'\n' Text.Whitespace 'FK' Keyword ',' Punctuation @@ -345,10 +338,8 @@ ',' Punctuation 'FY' Name.Variable ',' Punctuation -'-' Operator -'28' Literal.Number.Integer -'0e3' Literal.Number.Float -' \n' Text.Whitespace +'-280e3' Literal.Number.Float +'\n' Text.Whitespace 'FK' Keyword ',' Punctuation @@ -356,10 +347,8 @@ ',' Punctuation 'FY' Name.Variable ',' Punctuation -'-' Operator -'36' Literal.Number.Integer -'0e3' Literal.Number.Float -' \n' Text.Whitespace +'-360e3' Literal.Number.Float +'\n' Text.Whitespace '!\n' Comment @@ -373,13 +362,12 @@ '\n' Text.Whitespace -'/' Operator -'POST1' Name.Variable +'/POST1' Keyword '\n' Text.Whitespace 'PRRSOL' Keyword ',' Punctuation -'F' Keyword +'F' Name.Variable ' ' Text.Whitespace '! List Reaction Forces\n' Comment |