Package io.opsit.explang.parser.alg
Class AlgParser
- java.lang.Object
-
- io.opsit.explang.parser.alg.AlgParser
-
- All Implemented Interfaces:
IAutoSuggester,io.opsit.explang.IParser
public class AlgParser extends Object implements io.opsit.explang.IParser, IAutoSuggester
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classAlgParser.ExprVisitorstatic classAlgParser.SyntaxErrorstatic classAlgParser.SyntaxErrorListener
-
Field Summary
Fields Modifier and Type Field Description protected io.opsit.explang.atom.AtomParser[]atomParsersstatic StringDESCRIPTION_KEYstatic StringDISPLAYNAME_KEYprotected io.opsit.explang.atom.EscStringParserescStringParser
-
Constructor Summary
Constructors Constructor Description AlgParser()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected StringargsJoin(List<String> args)SourceInfoautoSuggest(String inputStr, io.opsit.explang.Compiler.ICtx ctx, int curPos, boolean returnTokenization, boolean returnErrors, boolean returnSuggestions, boolean filterSuggestions)protected voidclearBuf(StringBuffer buf)StringcodeType(io.opsit.explang.ICode code)Return type of callable object.IntegercomputeTokenIndex(org.antlr.v4.runtime.tree.ParseTree tree, org.antlr.v4.runtime.CommonTokenStream ts, int pos)Compute index of current token for given cursor position.StringconvertArgsDescr(String args)Convert argument description for suggestion display.Map<String,String>convertVariableProps(Map<Object,Object> props)Convert Map of variable properties for display.StringdocstringSummary(String str)Format function docstring for display.StringformatArgSpec(io.opsit.explang.ArgSpec spec)List<String>getErrors(io.opsit.explang.parser.alg.AlgParser.ParsingState state, int curPos)List<String>getErrors(String inputStr, int curPos)io.opsit.explang.OperatorDesc[]getOperatorDescs()StringgetTokenKind(int tokType)Return kind of token for the autosuggestion mechanism given ANTLR token type.protected booleanisParen(String str)protected Listlist(Object... objs)List<Suggestion>mkFunctionsSuggestions(io.opsit.explang.Compiler.ICtx ctx)Return suggestions for function calls.List<Suggestion>mkOperatorSuggestions(io.opsit.explang.Compiler.ICtx ctx, Integer tokType)Return list of suggestions for operators.protected static io.opsit.explang.ParseCtxmkPctx(io.opsit.explang.ParseCtx old, AlgParser.SyntaxError se)List<Suggestion>mkSuggestionForToken(Integer tokType, List<Integer> tokens, io.opsit.explang.Compiler.ICtx ctx, boolean filter, Tokenization tz)Build list of suggestions for a token.List<Suggestion>mkSymbolSuggestions(io.opsit.explang.Compiler.ICtx ctx)Return list of suggestions for a symbol literal.List<Suggestion>mkVariablesSuggestions(io.opsit.explang.Compiler.ICtx ctx)Make list of suggestions for a variable.io.opsit.explang.ASTNListparse(io.opsit.explang.ParseCtx pctx, InputStream is, int maxExprs)io.opsit.explang.ASTNListparse(io.opsit.explang.ParseCtx pctx, Reader reader, int maxExprs)io.opsit.explang.ASTNListparse(io.opsit.explang.ParseCtx pctx, String input)io.opsit.explang.ASTNListparse(io.opsit.explang.ParseCtx pctx, String input, int maxExprs)protected static io.opsit.explang.ParserExceptionse2ParserException(io.opsit.explang.ParseCtx oldPctx, AlgParser.SyntaxError se)StringsexpToString(Object obj)Convert S-exp string representaion in informational/error messages.booleansupportREPLStream()org.antlr.v4.runtime.TokentokenHasPos(List<org.antlr.v4.runtime.Token> tl, int pos)Return token that has given cursor position.Tokenizationtokenize(io.opsit.explang.parser.alg.AlgParser.ParsingState state, int curPos)Return tokenization of expression including information on current token (with active cursor).Tokenizationtokenize(String inputStr, int curPos)org.antlr.v4.runtime.TokentokHasPos(org.antlr.v4.runtime.Token tok, int pos, boolean rightInclude)Check if token has given position.Stringunquote(String str)Unquote quoted expression.
-
-
-
Field Detail
-
DESCRIPTION_KEY
public static final String DESCRIPTION_KEY
- See Also:
- Constant Field Values
-
DISPLAYNAME_KEY
public static final String DISPLAYNAME_KEY
- See Also:
- Constant Field Values
-
escStringParser
protected final io.opsit.explang.atom.EscStringParser escStringParser
-
atomParsers
protected io.opsit.explang.atom.AtomParser[] atomParsers
-
-
Method Detail
-
parse
public io.opsit.explang.ASTNList parse(io.opsit.explang.ParseCtx pctx, String input)- Specified by:
parsein interfaceio.opsit.explang.IParser
-
parse
public io.opsit.explang.ASTNList parse(io.opsit.explang.ParseCtx pctx, String input, int maxExprs)- Specified by:
parsein interfaceio.opsit.explang.IParser
-
parse
public io.opsit.explang.ASTNList parse(io.opsit.explang.ParseCtx pctx, InputStream is, int maxExprs)
-
parse
public io.opsit.explang.ASTNList parse(io.opsit.explang.ParseCtx pctx, Reader reader, int maxExprs)- Specified by:
parsein interfaceio.opsit.explang.IParser
-
supportREPLStream
public boolean supportREPLStream()
- Specified by:
supportREPLStreamin interfaceio.opsit.explang.IParser
-
getErrors
public List<String> getErrors(String inputStr, int curPos)
- Specified by:
getErrorsin interfaceIAutoSuggester
-
getErrors
public List<String> getErrors(io.opsit.explang.parser.alg.AlgParser.ParsingState state, int curPos)
-
tokenize
public Tokenization tokenize(String inputStr, int curPos)
- Specified by:
tokenizein interfaceIAutoSuggester
-
tokenize
public Tokenization tokenize(io.opsit.explang.parser.alg.AlgParser.ParsingState state, int curPos)
Return tokenization of expression including information on current token (with active cursor).
-
getOperatorDescs
public io.opsit.explang.OperatorDesc[] getOperatorDescs()
- Specified by:
getOperatorDescsin interfaceio.opsit.explang.IParser
-
autoSuggest
public SourceInfo autoSuggest(String inputStr, io.opsit.explang.Compiler.ICtx ctx, int curPos, boolean returnTokenization, boolean returnErrors, boolean returnSuggestions, boolean filterSuggestions)
- Specified by:
autoSuggestin interfaceIAutoSuggester
-
codeType
public String codeType(io.opsit.explang.ICode code)
Return type of callable object.
-
convertArgsDescr
public String convertArgsDescr(String args)
Convert argument description for suggestion display.
-
mkFunctionsSuggestions
public List<Suggestion> mkFunctionsSuggestions(io.opsit.explang.Compiler.ICtx ctx)
Return suggestions for function calls.
-
convertVariableProps
public Map<String,String> convertVariableProps(Map<Object,Object> props)
Convert Map of variable properties for display.
-
mkVariablesSuggestions
public List<Suggestion> mkVariablesSuggestions(io.opsit.explang.Compiler.ICtx ctx)
Make list of suggestions for a variable.
-
mkSymbolSuggestions
public List<Suggestion> mkSymbolSuggestions(io.opsit.explang.Compiler.ICtx ctx)
Return list of suggestions for a symbol literal.
-
mkOperatorSuggestions
public List<Suggestion> mkOperatorSuggestions(io.opsit.explang.Compiler.ICtx ctx, Integer tokType)
Return list of suggestions for operators.
-
getTokenKind
public String getTokenKind(int tokType)
Return kind of token for the autosuggestion mechanism given ANTLR token type.
-
mkSuggestionForToken
public List<Suggestion> mkSuggestionForToken(Integer tokType, List<Integer> tokens, io.opsit.explang.Compiler.ICtx ctx, boolean filter, Tokenization tz)
Build list of suggestions for a token.
-
tokHasPos
public org.antlr.v4.runtime.Token tokHasPos(org.antlr.v4.runtime.Token tok, int pos, boolean rightInclude)Check if token has given position.- Parameters:
tok- tokenpos- positionrightInclude- include token that start at the cursor position.
-
tokenHasPos
public org.antlr.v4.runtime.Token tokenHasPos(List<org.antlr.v4.runtime.Token> tl, int pos)
Return token that has given cursor position.
-
computeTokenIndex
public Integer computeTokenIndex(org.antlr.v4.runtime.tree.ParseTree tree, org.antlr.v4.runtime.CommonTokenStream ts, int pos)
Compute index of current token for given cursor position.
-
mkPctx
protected static io.opsit.explang.ParseCtx mkPctx(io.opsit.explang.ParseCtx old, AlgParser.SyntaxError se)
-
se2ParserException
protected static io.opsit.explang.ParserException se2ParserException(io.opsit.explang.ParseCtx oldPctx, AlgParser.SyntaxError se)
-
sexpToString
public String sexpToString(Object obj)
Convert S-exp string representaion in informational/error messages.
-
clearBuf
protected void clearBuf(StringBuffer buf)
-
isParen
protected boolean isParen(String str)
-
formatArgSpec
public String formatArgSpec(io.opsit.explang.ArgSpec spec)
- Specified by:
formatArgSpecin interfaceio.opsit.explang.IParser
-
-