mirror of
				https://github.com/sharkdp/bat.git
				synced 2025-10-31 07:04:04 +00:00 
			
		
		
		
	Add syntax mapping from NSE to Lua (#2214)
This commit is contained in:
		
							
								
								
									
										34
									
								
								tests/syntax-tests/highlighted/NSE/test.nse
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								tests/syntax-tests/highlighted/NSE/test.nse
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,34 @@ | ||||
| [38;2;117;113;94m--[0m[38;2;117;113;94m- Finds factorial of a number.[0m | ||||
| [38;2;117;113;94m--[0m[38;2;117;113;94m @param value Number to find factorial.[0m | ||||
| [38;2;117;113;94m--[0m[38;2;117;113;94m @return Factorial of number.[0m | ||||
| [38;2;249;38;114mlocal[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mfunction[0m[38;2;248;248;242m [0m[38;2;166;226;46mfactorial[0m[38;2;248;248;242m([0m[3;38;2;253;151;31mvalue[0m[38;2;248;248;242m)[0m | ||||
| [38;2;248;248;242m    [0m[38;2;249;38;114mif[0m[38;2;248;248;242m [0m[38;2;255;255;255mvalue[0m[38;2;248;248;242m [0m[38;2;249;38;114m<=[0m[38;2;248;248;242m [0m[38;2;190;132;255m1[0m[38;2;248;248;242m [0m[38;2;249;38;114mthen[0m | ||||
| [38;2;248;248;242m        [0m[38;2;249;38;114mreturn[0m[38;2;248;248;242m [0m[38;2;190;132;255m1[0m | ||||
| [38;2;248;248;242m    [0m[38;2;249;38;114melse[0m | ||||
| [38;2;248;248;242m        [0m[38;2;249;38;114mreturn[0m[38;2;248;248;242m [0m[38;2;255;255;255mvalue[0m[38;2;248;248;242m [0m[38;2;249;38;114m*[0m[38;2;248;248;242m [0m[38;2;248;248;242mfactorial[0m[38;2;248;248;242m([0m[38;2;255;255;255mvalue[0m[38;2;248;248;242m [0m[38;2;249;38;114m-[0m[38;2;248;248;242m [0m[38;2;190;132;255m1[0m[38;2;248;248;242m)[0m | ||||
| [38;2;248;248;242m    [0m[38;2;249;38;114mend[0m | ||||
| [38;2;249;38;114mend[0m | ||||
|  | ||||
| [38;2;117;113;94m--[0m[38;2;117;113;94m- Joins a table of strings into a new string.[0m | ||||
| [38;2;117;113;94m--[0m[38;2;117;113;94m @param table Table of strings.[0m | ||||
| [38;2;117;113;94m--[0m[38;2;117;113;94m @param separator Separator character.[0m | ||||
| [38;2;117;113;94m--[0m[38;2;117;113;94m @return Joined string.[0m | ||||
| [38;2;249;38;114mlocal[0m[38;2;248;248;242m [0m[3;38;2;102;217;239mfunction[0m[38;2;248;248;242m [0m[38;2;166;226;46mjoin[0m[38;2;248;248;242m([0m[3;38;2;253;151;31mtable[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[3;38;2;253;151;31mseparator[0m[38;2;248;248;242m)[0m | ||||
| [38;2;248;248;242m    [0m[38;2;249;38;114mlocal[0m[38;2;248;248;242m [0m[38;2;255;255;255mdata[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;230;219;116m"[0m[38;2;230;219;116m"[0m | ||||
| [38;2;248;248;242m    [0m | ||||
| [38;2;248;248;242m    [0m[38;2;249;38;114mfor[0m[38;2;248;248;242m [0m[38;2;255;255;255mindex[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;255;255;255mvalue[0m[38;2;248;248;242m [0m[38;2;249;38;114min[0m[38;2;248;248;242m [0m[38;2;102;217;239mipairs[0m[38;2;248;248;242m([0m[38;2;102;217;239mtable[0m[38;2;248;248;242m)[0m[38;2;248;248;242m [0m[38;2;249;38;114mdo[0m | ||||
| [38;2;248;248;242m        [0m[38;2;255;255;255mdata[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;255;255;255mdata[0m[38;2;248;248;242m [0m[38;2;249;38;114m..[0m[38;2;248;248;242m [0m[38;2;255;255;255mvalue[0m[38;2;248;248;242m [0m[38;2;249;38;114m..[0m[38;2;248;248;242m [0m[38;2;255;255;255mseparator[0m | ||||
| [38;2;248;248;242m    [0m[38;2;249;38;114mend[0m | ||||
| [38;2;248;248;242m    [0m | ||||
| [38;2;248;248;242m    [0m[38;2;255;255;255mdata[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;255;255;255mdata[0m[38;2;248;248;242m:[0m[38;2;248;248;242msub[0m[38;2;248;248;242m([0m[38;2;190;132;255m1[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;255;255;255mdata[0m[38;2;248;248;242m:[0m[38;2;248;248;242mlen[0m[38;2;248;248;242m([0m[38;2;248;248;242m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m-[0m[38;2;248;248;242m [0m[38;2;190;132;255m1[0m[38;2;248;248;242m)[0m | ||||
| [38;2;248;248;242m    [0m | ||||
| [38;2;248;248;242m    [0m[38;2;249;38;114mreturn[0m[38;2;248;248;242m [0m[38;2;255;255;255mdata[0m | ||||
| [38;2;249;38;114mend[0m | ||||
|  | ||||
| [38;2;249;38;114mlocal[0m[38;2;248;248;242m [0m[38;2;255;255;255ma[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;248;248;242mfactorial[0m[38;2;248;248;242m([0m[38;2;190;132;255m5[0m[38;2;248;248;242m)[0m | ||||
|  | ||||
| [38;2;102;217;239mprint[0m[38;2;248;248;242m([0m[38;2;255;255;255ma[0m[38;2;248;248;242m)[0m | ||||
|  | ||||
| [38;2;249;38;114mlocal[0m[38;2;248;248;242m [0m[38;2;255;255;255mb[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;248;248;242mjoin[0m[38;2;248;248;242m([0m[38;2;248;248;242m{[0m[38;2;248;248;242m [0m[38;2;230;219;116m"[0m[38;2;230;219;116ml[0m[38;2;230;219;116m"[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;230;219;116m"[0m[38;2;230;219;116mu[0m[38;2;230;219;116m"[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;230;219;116m"[0m[38;2;230;219;116ma[0m[38;2;230;219;116m"[0m[38;2;248;248;242m [0m[38;2;248;248;242m}[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;230;219;116m"[0m[38;2;230;219;116m,[0m[38;2;230;219;116m"[0m[38;2;248;248;242m)[0m | ||||
|  | ||||
| [38;2;102;217;239mprint[0m[38;2;248;248;242m([0m[38;2;255;255;255mb[0m[38;2;248;248;242m)[0m | ||||
							
								
								
									
										34
									
								
								tests/syntax-tests/source/NSE/test.nse
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								tests/syntax-tests/source/NSE/test.nse
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,34 @@ | ||||
| --- Finds factorial of a number. | ||||
| -- @param value Number to find factorial. | ||||
| -- @return Factorial of number. | ||||
| local function factorial(value) | ||||
|     if value <= 1 then | ||||
|         return 1 | ||||
|     else | ||||
|         return value * factorial(value - 1) | ||||
|     end | ||||
| end | ||||
|  | ||||
| --- Joins a table of strings into a new string. | ||||
| -- @param table Table of strings. | ||||
| -- @param separator Separator character. | ||||
| -- @return Joined string. | ||||
| local function join(table, separator) | ||||
|     local data = "" | ||||
|      | ||||
|     for index, value in ipairs(table) do | ||||
|         data = data .. value .. separator | ||||
|     end | ||||
|      | ||||
|     data = data:sub(1, data:len() - 1) | ||||
|      | ||||
|     return data | ||||
| end | ||||
|  | ||||
| local a = factorial(5) | ||||
|  | ||||
| print(a) | ||||
|  | ||||
| local b = join({ "l", "u", "a" }, ",") | ||||
|  | ||||
| print(b) | ||||
		Reference in New Issue
	
	Block a user