Esempio n. 1
0
static
parse_err_t parse_list(parse_state_t *state, node_t **result)
{
	parse_err_t status = PARSE_OK;
	node_t *child = NULL, *next = NULL;

	switch(token_type(state->ts)) {
	case TOK_END:
		status = PARSE_TOKEN_UNDERFLOW;
		*result = NULL;
		break;

	case TOK_RPAREN:
		/* ... ) */
		/* check but don't consume this RPAREN because the parse_sexpr
		   that calls this function will check for it when this function
		   returns */
		*result = NULL;
		break;

	case TOK_DOT:
		token_chomp(state->ts);
		switch(token_type(state->ts)) {
		case TOK_END:
			status = PARSE_TOKEN_UNDERFLOW;
			break;
		case TOK_RPAREN:
			status = PARSE_UNEXPECTED_RPAREN;
			break;
		case TOK_DOT:
			status = PARSE_UNEXPECTED_DOT;
			break;
		default:
			status = parse_sexpr(state, result);
			break;
		}
		break;
	default:
		status = parse_sexpr(state, &child);
		if(status == PARSE_OK) {
			status = parse_list(state, &next);
			if(status == PARSE_OK) {
				*result = node_cons_new(state->ms, child, next);
			} else {
				node_droproot(next);
			}
		}

	}

	return status;
}
Esempio n. 2
0
int main(int argc, char **argv)
{
	struct atom a;
	FILE *f;
	int retval;

	if (argc != 2) return 1;

	f = fopen(argv[1], "r");

	retval = parse_sexpr(f, &a, '\0', SBOF);
	//while (s) {
	//	printf("(");
	//}

//	/*
	#if 0
	printf("atom a at location          %p\n", &a);
	printf("a.atom_t at location        %p\n", &a.atom_t);
	printf("a.contents at location      %p\n", &a.contents);
	printf("a.contents.sexp at location %p\n", &a.contents.sexp);
	printf("a.contents.sexp points to   %p\n", a.contents.sexp);
	if (!a.contents.sexp) return retval;
	printf("a.contents.sexp.first " "   %p\n", a.contents.sexp->first);
	printf("a.contents.sexp.rest  " "   %p\n", a.contents.sexp->rest);
	#endif
//	*/

	atom_pprint(&a);
	printf("\n");

	return retval;
}
Esempio n. 3
0
parse_err_t parse(memory_state_t *ms, tok_state_t *ts, node_t *out_hdl)
{
	parse_err_t status = PARSE_OK;
	node_t *result = NULL;
	parse_state_t state = { .ms = ms, .ts = ts };

	if(token_type(state.ts) == TOK_INIT) {
		token_chomp(state.ts);
	}
	status = parse_sexpr(&state, &result);
	node_handle_update(out_hdl, result);

	return status;
}
Esempio n. 4
0
parse_part parse_listitem(parser_state state) {
    parse_part result;
    lexid current = getCurrent(state);
    if (lexid_eq(FLOAT_LEXID, current) || lexid_eq(INT_LEXID, current)
        || lexid_eq(STRING_LEXID, current)) {

        result.tree = lexid_tree_init(current);
        result.state = state;
        result.state.index += 1;
    }
    else if (lexid_eq(LPAREN_LEXID, current)) {
        result = parse_sexpr(state);
    }
    else if ( isID(current) ) {
        result = parse_dotapp(state);
    }
    else {
        printf("%s", "ERROR!");
    }
    return result; 
}
Esempio n. 5
0
void TextBuffer::colorize (int from, int to, bool force)
{
  // JUCE LACAUNEA: (1) recoloring should only happen in the visible
  // region of buffer but i dont see anyway to get this information
  // from the viewpoint. (2) In order to recolor I have to delete and
  // add the text back into the buffer

  // this is needed because coloring changes the text buffer and we
  // dont want the editor's change callback to call the colorizer for
  // these changes.
  //  setFlag(EditFlags::Coloring); 

  String text = getTextSubstring(from, to);
  int len = text.length();
  int here = point(), pos = 0, start, end;
  String expr;
  scanresult typ;
  HiliteID hilite;
  Colour color, normal=syntax->hilites[HiliteIDs::None];
  static KeyPress dkey = KeyPress(KeyPress::deleteKey);
  
  // offset is the starting position of text string in buffer.
  setCaretVisible(false);
  setScrollToShowCursor(false);
  //printf("hiliting %d to %d...\n", from, to);
  while (pos < len)
    {
      typ=parse_sexpr(syntax->syntab, text, -1, len, 1,
		      SCAN_COLOR, &pos, &start, &end);
      hilite=HiliteIDs::None;
      if (typ>0)
	{
	  if (typ==SCAN_TOKEN)
	    {
	      hilite=syntax->getHilite(text, start, end);
	    }
	  else if (typ==SCAN_COMMENT) 
	    {
	      hilite=HiliteIDs::Comment;
	    }
	  else if (typ==SCAN_STRING)
	    {
	      hilite=HiliteIDs::String;
	    }
	  if ((hilite>HiliteIDs::None) || force)
	    {
	      // this is REALLY GROSS!
	      expr=text.substring(start,end);
	      color=syntax->hilites[hilite];
	      setPoint(from+start);
	      setHighlightedRegion(from+start, end-start);
	      TextEditor::keyPressed(dkey);
	      setColour(TextEditor::textColourId, color);
	      insertTextAtCursor(expr);
	      setColour(TextEditor::textColourId, normal);
	      /**
	      color=syntax->hilites[hilite];
	      setColour(TextEditor::textColourId, color);
	      TextEditor::repaintText(from+start, end-start);
	      setColour(TextEditor::textColourId, normal); 
	      **/
	    }
	}
    }
  setPoint(here);
  setCaretVisible(true);
  setScrollToShowCursor(true);
  //  clearFlag(EditFlags::Coloring); 
}