mirror of
				https://github.com/Baidicoot/rpncalc-v4
				synced 2025-10-30 23:23:04 +00:00 
			
		
		
		
	added parsing for push operator
This commit is contained in:
		
							
								
								
									
										15
									
								
								parse.js
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								parse.js
									
									
									
									
									
								
							| @@ -170,6 +170,19 @@ const parseName = (stream) => { | |||||||
|     return {parsed:id.parsed.val, stream:syn.stream}; |     return {parsed:id.parsed.val, stream:syn.stream}; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | /* takes in stream, outputs parsed item or null - FAILABLE */ | ||||||
|  | const parsePush = (stream) => { | ||||||
|  |     let syn = attempt(parseSyntax("'")); | ||||||
|  |     if (syn.parsed === null) { | ||||||
|  |         return {parsed:null, stream:syn.stream}; | ||||||
|  |     } | ||||||
|  |     let id = parseIdent(syn.stream); | ||||||
|  |     if (id.parsed === null) { | ||||||
|  |         return {parsed:null, stream:id.stream}; | ||||||
|  |     } | ||||||
|  |     return {parsed:{type:"push", elem:id.parsed}, stream:id.stream}; | ||||||
|  | } | ||||||
|  |  | ||||||
| /* takes in stream, outputs parsed item or null - FAILABLE */ | /* takes in stream, outputs parsed item or null - FAILABLE */ | ||||||
| const parseLambda = (stream) => { | const parseLambda = (stream) => { | ||||||
|     let name = attempt(parseName)(stream); |     let name = attempt(parseName)(stream); | ||||||
| @@ -189,7 +202,7 @@ const parseLambda = (stream) => { | |||||||
| } | } | ||||||
|  |  | ||||||
| /* takes in stream, outputs parsed item or null */ | /* takes in stream, outputs parsed item or null */ | ||||||
| const parseExpr = or(parseBuiltin, or(parseIdent, or(parseInteger, attempt(parens(parseLambda))))); | const parseExpr = or(parseBuiltin, or(parseIdent, or(parseInteger, or(parsePush, attempt(parens(parseLambda)))))); | ||||||
|  |  | ||||||
| /* takes in stream, outputs parsed items */ | /* takes in stream, outputs parsed items */ | ||||||
| export const parseExprs = many(parseExpr); | export const parseExprs = many(parseExpr); | ||||||
		Reference in New Issue
	
	Block a user
	 Aidan K. Ewart
					Aidan K. Ewart